2020-03-30 15:43:15 -04:00
|
|
|
#[macro_use]
|
|
|
|
mod macros;
|
|
|
|
test!(
|
|
|
|
map_get_key_exists,
|
|
|
|
"a {\n color: map-get((a: b), a);\n}\n",
|
|
|
|
"a {\n color: b;\n}\n"
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_get_key_does_not_exist,
|
|
|
|
"a {\n color: map-get((a: b), foo);\n}\n",
|
|
|
|
""
|
|
|
|
);
|
2020-05-18 17:56:25 -04:00
|
|
|
test!(
|
|
|
|
map_get_empty_list,
|
|
|
|
"a {\n color: map-get((), foo);\n}\n",
|
|
|
|
""
|
|
|
|
);
|
2020-03-30 15:43:15 -04:00
|
|
|
error!(
|
|
|
|
map_get_non_map,
|
|
|
|
"a {\n color: map-get(foo, foo);\n}\n", "Error: $map: foo is not a map."
|
|
|
|
);
|
2020-05-18 17:56:25 -04:00
|
|
|
error!(
|
|
|
|
map_get_one_arg,
|
|
|
|
"a {\n color: map-get(1);\n}\n", "Error: Missing argument $key."
|
|
|
|
);
|
2020-03-30 15:43:15 -04:00
|
|
|
test!(
|
|
|
|
map_has_key_true,
|
|
|
|
"a {\n color: map-has-key((a: b), a);\n}\n",
|
|
|
|
"a {\n color: true;\n}\n"
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_has_key_false,
|
|
|
|
"a {\n color: map-has-key((a: b), foo);\n}\n",
|
|
|
|
"a {\n color: false;\n}\n"
|
|
|
|
);
|
2020-05-18 17:56:25 -04:00
|
|
|
test!(
|
|
|
|
map_has_key_empty_list,
|
|
|
|
"a {\n color: map-has-key((), foo);\n}\n",
|
|
|
|
"a {\n color: false;\n}\n"
|
|
|
|
);
|
2020-03-30 15:43:15 -04:00
|
|
|
error!(
|
|
|
|
map_has_key_non_map,
|
|
|
|
"a {\n color: map-has-key(foo, foo);\n}\n", "Error: $map: foo is not a map."
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_keys_one,
|
|
|
|
"a {\n color: map-keys((a: b));\n}\n",
|
|
|
|
"a {\n color: a;\n}\n"
|
|
|
|
);
|
2020-03-30 16:14:42 -04:00
|
|
|
test!(
|
|
|
|
map_keys_are_comma_separated,
|
|
|
|
"a {\n color: map-keys((a: b, c: d));\n}\n",
|
|
|
|
"a {\n color: a, c;\n}\n"
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_keys_empty,
|
|
|
|
"a {\n color: inspect(map-keys(()));\n}\n",
|
|
|
|
"a {\n color: ();\n}\n"
|
|
|
|
);
|
2020-03-30 15:43:15 -04:00
|
|
|
error!(
|
|
|
|
map_keys_non_map,
|
|
|
|
"a {\n color: map-keys(foo);\n}\n", "Error: $map: foo is not a map."
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_values_one,
|
|
|
|
"a {\n color: map-values((a: b));\n}\n",
|
|
|
|
"a {\n color: b;\n}\n"
|
|
|
|
);
|
2020-03-30 16:21:00 -04:00
|
|
|
test!(
|
|
|
|
map_values_empty,
|
|
|
|
"a {\n color: inspect(map-values(()));\n}\n",
|
|
|
|
"a {\n color: ();\n}\n"
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_values_are_comma_separated,
|
|
|
|
"a {\n color: map-values((a: b, c: d));\n}\n",
|
|
|
|
"a {\n color: b, d;\n}\n"
|
|
|
|
);
|
2020-03-30 15:43:15 -04:00
|
|
|
error!(
|
|
|
|
map_values_non_map,
|
|
|
|
"a {\n color: map-values(foo);\n}\n", "Error: $map: foo is not a map."
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_merge_one,
|
|
|
|
"a {\n color: inspect(map-merge((a: b), (c: d)));\n}\n",
|
|
|
|
"a {\n color: (a: b, c: d);\n}\n"
|
|
|
|
);
|
2020-03-30 16:10:02 -04:00
|
|
|
test!(
|
|
|
|
map_merge_both_empty,
|
|
|
|
"a {\n color: inspect(map-merge((), ()));\n}\n",
|
|
|
|
"a {\n color: ();\n}\n"
|
|
|
|
);
|
2020-03-30 16:33:43 -04:00
|
|
|
test!(
|
|
|
|
map_merge_same_keys,
|
|
|
|
"a {\n color: inspect(map-merge((c: d, e: f), (c: 1, e: 2)));\n}\n",
|
|
|
|
"a {\n color: (c: 1, e: 2);\n}\n"
|
|
|
|
);
|
2021-07-03 23:17:31 -04:00
|
|
|
test!(
|
|
|
|
map_merge_nested_empty,
|
|
|
|
"a {b: inspect(map-merge((c: ()), c, ()))}",
|
|
|
|
"a {\n b: (c: ());\n}\n"
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_merge_nested_overlapping_keys,
|
|
|
|
"a {b: inspect(map-merge((c: (d: e, f: g, h: i)), c, (j: 1, f: 2, k: 3)))}",
|
|
|
|
"a {\n b: (c: (d: e, f: 2, h: i, j: 1, k: 3));\n}\n"
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_merge_nested_intermediate_is_not_map,
|
|
|
|
"a {b: inspect(map-merge((c: 1), c, d, (e: f)))}",
|
|
|
|
"a {\n b: (c: (d: (e: f)));\n}\n"
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_merge_nested_leaf_is_not_map,
|
|
|
|
"a {b: inspect(map-merge((c: 1), c, (d: e)))}",
|
|
|
|
"a {\n b: (c: (d: e));\n}\n"
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_merge_nested_multiple_keys,
|
|
|
|
"a {b: inspect(map-merge((c: (d: (e: (f: (g: h))))), c, d, e, f, (g: 1)))}",
|
|
|
|
"a {\n b: (c: (d: (e: (f: (g: 1)))));\n}\n"
|
|
|
|
);
|
2020-03-30 15:43:15 -04:00
|
|
|
error!(
|
|
|
|
map_merge_map1_non_map,
|
|
|
|
"a {\n color: map-merge(foo, (a: b));\n}\n", "Error: $map1: foo is not a map."
|
|
|
|
);
|
|
|
|
error!(
|
|
|
|
map_merge_map2_non_map,
|
|
|
|
"a {\n color: map-merge((a: b), foo);\n}\n", "Error: $map2: foo is not a map."
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_dbl_quoted_key,
|
2020-04-01 15:32:52 -04:00
|
|
|
"a {\n color: map-get((\"a\": b), \"a\");\n}\n",
|
2020-03-30 15:43:15 -04:00
|
|
|
"a {\n color: b;\n}\n"
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_key_quoting_ignored,
|
2020-04-01 15:32:52 -04:00
|
|
|
"a {\n color: map-get((\"a\": b), 'a');\n}\n",
|
2020-03-30 15:43:15 -04:00
|
|
|
"a {\n color: b;\n}\n"
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_arbitrary_number_of_entries,
|
|
|
|
"a {\n color: inspect((a: b, c: d, e: f, g: h, i: j, h: k, l: m, n: o));\n}\n",
|
|
|
|
"a {\n color: (a: b, c: d, e: f, g: h, i: j, h: k, l: m, n: o);\n}\n"
|
|
|
|
);
|
2020-03-30 16:01:44 -04:00
|
|
|
test!(
|
|
|
|
map_length,
|
|
|
|
"a {\n color: length((a: b, c: d, e: f));\n}\n",
|
|
|
|
"a {\n color: 3;\n}\n"
|
|
|
|
);
|
2020-03-30 16:41:00 -04:00
|
|
|
error!(
|
|
|
|
map_has_key_one_arg,
|
2020-03-30 17:06:23 -04:00
|
|
|
"a {\n color: map-has-key(1);\n}\n", "Error: Missing argument $key."
|
2020-03-30 16:41:00 -04:00
|
|
|
);
|
2020-04-02 13:49:39 -04:00
|
|
|
test!(
|
|
|
|
map_remove_one,
|
|
|
|
"a {\n color: inspect(map-remove((\"foo\": 1, \"bar\": 2), \"bar\"));\n}\n",
|
|
|
|
"a {\n color: (\"foo\": 1);\n}\n"
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_remove_two,
|
|
|
|
"a {\n color: inspect(map-remove((\"foo\": 1, \"bar\": 2, \"baz\": 3), \"bar\", \"baz\"));\n}\n",
|
|
|
|
"a {\n color: (\"foo\": 1);\n}\n"
|
|
|
|
);
|
2020-05-18 17:56:25 -04:00
|
|
|
test!(
|
|
|
|
map_remove_empty_list,
|
|
|
|
"a {\n color: inspect(map-remove((), foo));\n}\n",
|
|
|
|
"a {\n color: ();\n}\n"
|
|
|
|
);
|
2020-04-03 16:38:01 -04:00
|
|
|
error!(
|
|
|
|
duplicate_key_in_declaration,
|
2020-05-16 22:46:13 -04:00
|
|
|
"a {\n $a: (foo: a, foo: b);\n}\n", "Error: Duplicate key."
|
2020-04-03 16:38:01 -04:00
|
|
|
);
|
2020-04-18 20:11:49 -04:00
|
|
|
error!(
|
|
|
|
display_map,
|
|
|
|
"a {\n color: (a: b, c: d);\n}\n", "Error: (a: b, c: d) isn't a valid CSS value."
|
|
|
|
);
|
2020-05-20 20:35:59 -04:00
|
|
|
test!(
|
|
|
|
map_comma_separated_list_as_key,
|
|
|
|
"a {\n color: map-keys(((1, 2): 3));\n}\n",
|
|
|
|
"a {\n color: 1, 2;\n}\n"
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
map_inspect_comma_separated_list_as_key,
|
|
|
|
"a {\n color: inspect(((1, 2): 3));\n}\n",
|
|
|
|
"a {\n color: ((1, 2): 3);\n}\n"
|
|
|
|
);
|
2020-06-20 21:53:01 -04:00
|
|
|
test!(
|
|
|
|
map_with_map_as_value,
|
|
|
|
"$foo: (\"21by9\": (x: 21, y: 9));",
|
|
|
|
""
|
|
|
|
);
|
|
|
|
test!(
|
|
|
|
paren_with_paren_element_and_trailing_comma,
|
|
|
|
"$foo: ((\"<\", \"%3c\"), );",
|
|
|
|
""
|
|
|
|
);
|
2020-07-02 14:44:00 -04:00
|
|
|
test!(
|
|
|
|
map_with_whitespace_after_trailing_comma,
|
|
|
|
"$a: (foo: red, ); a {\n color: inspect($a);\n}\n",
|
|
|
|
"a {\n color: (foo: red);\n}\n"
|
|
|
|
);
|
2020-07-07 00:01:34 -04:00
|
|
|
test!(
|
|
|
|
map_merge_not_exactly_equal,
|
2020-07-07 01:06:22 -04:00
|
|
|
"a {\n color: inspect(map-merge((0cm: a), (0mm: b)));\n}\n",
|
2020-07-07 00:01:34 -04:00
|
|
|
"a {\n color: (0cm: b);\n}\n"
|
|
|
|
);
|
2020-07-07 01:06:22 -04:00
|
|
|
test!(
|
|
|
|
map_equality_is_independent_of_order,
|
|
|
|
"a {\n color: (c: d, a: b)==(a: b, c: d);\n}\n",
|
|
|
|
"a {\n color: true;\n}\n"
|
|
|
|
);
|
2020-07-07 10:55:37 -04:00
|
|
|
test!(
|
|
|
|
map_equality_considers_both_key_and_value,
|
|
|
|
"a {\n color: (a: b)==(a: c);\n}\n",
|
|
|
|
"a {\n color: false;\n}\n"
|
|
|
|
);
|
2022-12-28 21:42:58 -05:00
|
|
|
test!(
|
|
|
|
important_as_key,
|
|
|
|
"a {\n color: inspect((a: b, !important: c));\n}\n",
|
|
|
|
"a {\n color: (a: b, !important: c);\n}\n"
|
|
|
|
);
|
|
|
|
error!(
|
|
|
|
bang_identifier_not_important_as_key,
|
|
|
|
"a {\n color: inspect((a: b, !a: c));\n}\n", r#"Error: expected ")"."#
|
|
|
|
);
|
|
|
|
error!(
|
|
|
|
bang_identifier_not_important_but_starts_with_i_as_key,
|
|
|
|
"a {\n color: inspect((a: b, !i: c));\n}\n", r#"Error: Expected "important"."#
|
|
|
|
);
|
|
|
|
error!(
|
|
|
|
bang_identifier_not_important_ascii_whitespace_as_key,
|
|
|
|
"a {\n color: inspect((a: b, ! : c));\n}\n", r#"Error: Expected "important"."#
|
|
|
|
);
|
|
|
|
error!(
|
|
|
|
bang_identifier_not_important_loud_comment_as_key,
|
|
|
|
"a {\n color: inspect((a: b, !/**/: c));\n}\n", r#"Error: expected ")"."#
|
|
|
|
);
|
2020-07-27 22:09:38 -04:00
|
|
|
test!(
|
|
|
|
empty_with_single_line_comments,
|
|
|
|
"$foo: (\n \n // :/a.b\n \n );
|
|
|
|
a {
|
|
|
|
color: inspect($foo);
|
|
|
|
}",
|
|
|
|
"a {\n color: ();\n}\n"
|
|
|
|
);
|
2020-08-07 20:10:49 -04:00
|
|
|
test!(
|
|
|
|
trailing_comma_in_doubly_nested_map,
|
|
|
|
r#"$a: (
|
|
|
|
foo: (
|
|
|
|
a: b,
|
|
|
|
c: d,
|
|
|
|
)
|
|
|
|
);"#,
|
|
|
|
""
|
|
|
|
);
|
2020-08-07 13:00:55 -04:00
|
|
|
error!(
|
|
|
|
second_map_value_missing_colon,
|
|
|
|
"a {\n color: (a: b, c", "Error: expected \":\"."
|
|
|
|
);
|
|
|
|
error!(
|
|
|
|
second_map_value_missing_closing_paren,
|
|
|
|
"$a: (a: b, c: d", "Error: expected \")\"."
|
|
|
|
);
|
|
|
|
error!(
|
|
|
|
first_map_value_missing_closing_paren,
|
|
|
|
"$a: (a: b", "Error: expected \")\"."
|
|
|
|
);
|
2020-08-16 20:00:14 -04:00
|
|
|
error!(
|
|
|
|
denies_comma_separated_list_without_parens_as_key,
|
|
|
|
"$map: (a: 1, b, c, d: e);", "Error: expected \":\"."
|
|
|
|
);
|
2022-12-28 21:42:58 -05:00
|
|
|
error!(
|
|
|
|
nothing_after_first_comma,
|
|
|
|
"$map: (a: b,", "Error: expected \")\"."
|
|
|
|
);
|