grass/tests/list.rs
2020-03-20 19:27:26 -04:00

83 lines
1.8 KiB
Rust

#![cfg(test)]
#[macro_use]
mod macros;
test!(
length_of_list_as_var,
"$a: 1 2 3 4 5;a {\n color: length($a);\n}\n",
"a {\n color: 5;\n}\n"
);
test!(
length_of_list,
"a {\n color: length(1 2 3 4 5);\n}\n",
"a {\n color: 5;\n}\n"
);
test!(
length_of_comma_list,
"a {\n color: length((1, 2, 3, 4, 5));\n}\n",
"a {\n color: 5;\n}\n"
);
test!(
nth_space_separated,
"a {\n color: nth(a b c, 1);\n}\n",
"a {\n color: a;\n}\n"
);
test!(
nth_negative_index,
"a {\n color: nth(a b c, -2);\n}\n",
"a {\n color: b;\n}\n"
);
test!(
nth_comma_separated,
"a {\n color: nth((a, b, c), 3);\n}\n",
"a {\n color: c;\n}\n"
);
test!(
nth_non_list,
"a {\n color: nth(foo, 1);\n}\n",
"a {\n color: foo;\n}\n"
);
test!(
list_separator_space_separated,
"a {\n color: list-separator(a b c);\n}\n",
"a {\n color: space;\n}\n"
);
test!(
list_separator_foo,
"a {\n color: list-separator(foo);\n}\n",
"a {\n color: space;\n}\n"
);
test!(
list_separator_comma_separated,
"a {\n color: list-separator((a, b, c));\n}\n",
"a {\n color: comma;\n}\n"
);
// blocked on better parsing of comma separated lists with
// space separated lists inside
// test!(
// list_separator_comma_separated_with_space,
// "a {\n color: list-separator(((a b, c d)));\n}\n",
// "a {\n color: comma;\n}\n"
// );
test!(
set_nth_named_args,
"a {\n color: set-nth($list: 1 2 3, $n: 2, $value: foo);\n}\n",
"a {\n color: 1 foo 3;\n}\n"
);
test!(
set_nth_non_list,
"a {\n color: set-nth(c, 1, e);\n}\n",
"a {\n color: e;\n}\n"
);
test!(
set_nth_2_long,
"a {\n color: set-nth(c d, 1, e);\n}\n",
"a {\n color: e d;\n}\n"
);
test!(
set_nth_comma_separated,
"a {\n color: set-nth((a, b, c), 1, e);\n}\n",
"a {\n color: e, b, c;\n}\n"
);