mod common;
use common::generic_test;
use std::process::Command;
macro_rules! query_test {
($test_name:ident, $query:literal, $expected:literal) => {
generic_test!(
$test_name,
vec!["query", "--filepath", "tests/files/valid.toml", $query],
$expected
);
};
}
query_test!(
should_print_whole_document,
".",
r#"[table]
key_with_decorator = "value"
key_without_decorator ="value"
number = 2
inline_table = { inline_key = "inline_value", array_in_inline_table = [] }
array = [1, 2, 3, [4, 5, 6, { name = "inline_table_in_array", another_array = [8, 9]}]]
[[table.array_of_tables]]
key = "value"
key2 = "value2"
array = [1, 2, 3]
[[table.array_of_tables]]
key = "value"
key2 = "value2"
array = [1, 2, 3]
"#
);
query_test!(
should_print_value_with_whitespace_prefix,
"table.key_with_decorator",
" \"value\"\n"
);
query_test!(
should_print_value_without_whitespace_prefix,
"table.key_without_decorator",
"\"value\"\n"
);
query_test!(should_print_value_as_number, "table.number", " 2\n");
query_test!(
should_print_inline_table,
"table.inline_table",
" { inline_key = \"inline_value\", array_in_inline_table = [] }\n"
);
query_test!(
should_print_array_of_tables,
"table.array_of_tables",
"[{ key = \"value\", key2 = \"value2\", array = [1, 2, 3] }, { key = \"value\", key2 = \"value2\", array = [1, 2, 3] }]\n"
);
query_test!(
should_print_array,
"table.array",
" [1, 2, 3, [4, 5, 6, { name = \"inline_table_in_array\", another_array = [8, 9]}]]\n"
);
query_test!(should_print_element_in_array, "table.array[1]", " 2\n");
query_test!(
should_print_value_from_table_in_array_of_tables,
"table.array_of_tables[0].key",
" \"value\"\n"
);
query_test!(
should_print_key_not_found,
"I_dont_exist",
"Key not found: I_dont_exist\n"
);
query_test!(
should_print_key_not_found_in_table,
"table.I_dont_exist",
"Key not found: I_dont_exist\n"
);
query_test!(
should_print_key_not_found_in_inline_table,
"table.inline_table.I_dont_exist",
"Key not found: I_dont_exist\n"
);
query_test!(
should_print_index_out_of_bounds,
"table.array[5]",
"Index (\"5\") is out of bounds\n"
);
query_test!(
should_print_index_out_of_bounds_for_array_of_tables,
"table.array_of_tables[5]",
"Index (\"5\") is out of bounds\n"
);