grass/tests/min-max.rs

250 lines
6.7 KiB
Rust
Raw Normal View History

#[macro_use]
mod macros;
test!(
min_not_evaluated_units_percent,
"a {\n color: min(1%, 2%);\n}\n",
"a {\n color: min(1%, 2%);\n}\n"
);
test!(
min_not_evaluated_units_px,
"a {\n color: min(1px, 2px);\n}\n",
"a {\n color: min(1px, 2px);\n}\n"
);
test!(
min_not_evaluated_no_units,
"a {\n color: min(1, 2);\n}\n",
"a {\n color: min(1, 2);\n}\n"
);
test!(
min_not_evaluated_incompatible_units,
"a {\n color: min(1%, 2vh);\n}\n",
"a {\n color: min(1%, 2vh);\n}\n"
);
test!(
min_not_evaluated_interpolation,
"$a: 1%;\n$b: 2%;\na {\n color: min(#{$a}, #{$b});;\n}\n",
"a {\n color: min(1%, 2%);\n}\n"
);
test!(
min_evaluated_variable_units_percent,
"$a: 1%;\n$b: 2%;\na {\n color: min($a, $b);\n}\n",
"a {\n color: 1%;\n}\n"
);
test!(
min_evaluated_variable_units_px,
"$a: 1px;\n$b: 2px;\na {\n color: min($a, $b);\n}\n",
"a {\n color: 1px;\n}\n"
);
error!(
min_arg_of_incorrect_type,
"$a: 1px;\n$b: 2px;\na {\n color: min($a, $b, foo);\n}\n", "Error: foo is not a number."
);
error!(
min_too_few_args,
"a {\n color: min();\n}\n", "Error: At least one argument must be passed."
);
// note: we explicitly have units in the opposite order of `dart-sass`.
// see https://github.com/sass/dart-sass/issues/766
error!(
min_incompatible_units,
"$a: 1px;\n$b: 2%;\na {\n color: min($a, $b);\n}\n", "Error: Incompatible units px and %."
);
test!(
max_not_evaluated_units_percent,
"a {\n color: max(1%, 2%);\n}\n",
"a {\n color: max(1%, 2%);\n}\n"
);
test!(
max_not_evaluated_units_px,
"a {\n color: max(1px, 2px);\n}\n",
"a {\n color: max(1px, 2px);\n}\n"
);
test!(
max_not_evaluated_no_units,
"a {\n color: max(1, 2);\n}\n",
"a {\n color: max(1, 2);\n}\n"
);
test!(
max_not_evaluated_incompatible_units,
"a {\n color: max(1%, 2vh);\n}\n",
"a {\n color: max(1%, 2vh);\n}\n"
);
test!(
max_not_evaluated_interpolation,
"$a: 1%;\n$b: 2%;\na {\n color: max(#{$a}, #{$b});;\n}\n",
"a {\n color: max(1%, 2%);\n}\n"
);
test!(
max_evaluated_variable_units_percent,
"$a: 1%;\n$b: 2%;\na {\n color: max($a, $b);\n}\n",
"a {\n color: 2%;\n}\n"
);
test!(
max_evaluated_variable_units_px,
"$a: 1px;\n$b: 2px;\na {\n color: max($a, $b);\n}\n",
"a {\n color: 2px;\n}\n"
);
2020-06-22 10:21:18 -04:00
test!(
max_evaluated_binop,
"a {\n color: max(100% - lightness(red) - 2%);\n}\n",
"a {\n color: 48%;\n}\n"
2020-06-22 10:21:18 -04:00
);
error!(
max_arg_of_incorrect_type,
"$a: 1px;\n$b: 2px;\na {\n color: max($a, $b, foo);\n}\n", "Error: foo is not a number."
);
error!(
max_too_few_args,
"a {\n color: max();\n}\n", "Error: At least one argument must be passed."
);
// note: we explicitly have units in the opposite order of `dart-sass`.
// see https://github.com/sass/dart-sass/issues/766
error!(
max_incompatible_units,
"$a: 1px;\n$b: 2%;\na {\n color: max($a, $b);\n}\n", "Error: Incompatible units px and %."
);
2020-06-22 10:22:13 -04:00
// todo: special functions, min(calc(1), $b);
test!(
min_containing_max,
"a {\n color: min(1, max(2));\n}\n",
"a {\n color: min(1, max(2));\n}\n"
);
test!(
max_containing_min,
"a {\n color: max(1, min(2));\n}\n",
"a {\n color: max(1, min(2));\n}\n"
);
test!(
min_containing_max_as_only_arg,
"a {\n color: min(max(1px, 2px));\n}\n",
"a {\n color: min(max(1px, 2px));\n}\n"
);
test!(
max_containing_min_as_only_arg,
"a {\n color: max(min(1px, 2px));\n}\n",
"a {\n color: max(min(1px, 2px));\n}\n"
);
test!(
extremely_nested_min_and_max,
"a {\n color: min(max(min(max(min(min(1), max(2))))), min(max(min(3))));\n}\n",
"a {\n color: min(max(min(max(min(min(1), max(2))))), min(max(min(3))));\n}\n"
);
2021-07-12 01:59:30 -04:00
test!(
decimal_without_leading_integer_is_evaluated,
"a {\n color: min(.2, .4);\n}\n",
"a {\n color: 0.2;\n}\n"
);
test!(
decimal_with_leading_integer_is_not_evaluated,
"a {\n color: min(0.2, 0.4);\n}\n",
"a {\n color: min(0.2, 0.4);\n}\n"
);
test!(
min_conains_special_fn_env,
"a {\n color: min(env(\"foo\"));\n}\n",
"a {\n color: min(env(\"foo\"));\n}\n"
);
test!(
min_conains_special_fn_calc_with_div_and_spaces,
"a {\n color: min(calc(1 / 2));\n}\n",
"a {\n color: min(calc(1 / 2));\n}\n"
);
test!(
min_conains_special_fn_calc_with_div_without_spaces,
"a {\n color: min(calc(1/2));\n}\n",
"a {\n color: min(calc(1/2));\n}\n"
);
test!(
min_conains_special_fn_calc_with_plus_only,
"a {\n color: min(calc(+));\n}\n",
"a {\n color: min(calc(+));\n}\n"
);
test!(
min_conains_special_fn_calc_space_separated_list,
"a {\n color: min(calc(1 2));\n}\n",
"a {\n color: min(calc(1 2));\n}\n"
);
test!(
min_conains_special_fn_var,
"a {\n color: min(1, var(--foo));\n}\n",
"a {\n color: min(1, var(--foo));\n}\n"
);
test!(
min_conains_multiline_comment,
"a {\n color: min(1/**/);\n}\n",
"a {\n color: min(1);\n}\n"
);
test!(
min_conains_calc_contains_multiline_comment,
"a {\n color: min(calc(1 /**/ 2));\n}\n",
"a {\n color: min(calc(1 /**/ 2));\n}\n"
);
test!(
#[ignore = "we currently resolve interpolation eagerly inside loud comments"]
min_conains_calc_contains_multiline_comment_with_interpolation,
"a {\n color: min(calc(1 /* #{5} */ 2));\n}\n",
"a {\n color: min(calc(1 /* #{5} */ 2));\n}\n"
);
test!(
min_uppercase,
"a {\n color: MIN(1);\n}\n",
"a {\n color: min(1);\n}\n"
);
test!(
max_uppercase,
"a {\n color: MAX(1);\n}\n",
"a {\n color: max(1);\n}\n"
);
test!(
min_parenthesis_around_arg,
"a {\n color: min((1));\n}\n",
"a {\n color: min((1));\n}\n"
);
error!(
min_parenthesis_around_arg_with_comma,
"a {\n color: min((1, 1));\n}\n", "Error: 1, 1 is not a number."
);
error!(
min_hash_without_interpolation,
"a {\n color: min(#a);\n}\n", "Error: #a is not a number."
);
error!(
min_calc_no_parens,
"a {\n color: min(calc);\n}\n", "Error: calc is not a number."
);
error!(
min_env_no_parens,
"a {\n color: min(env);\n}\n", "Error: env is not a number."
);
error!(
min_var_no_parens,
"a {\n color: min(var);\n}\n", "Error: var is not a number."
);
error!(
min_min_unfinished,
"a {\n color: min(mi);\n}\n", "Error: mi is not a number."
);
error!(
min_max_unfinished,
"a {\n color: min(ma);\n}\n", "Error: ma is not a number."
);
error!(
min_min_no_parens,
"a {\n color: min(min);\n}\n", "Error: min is not a number."
);
error!(
min_max_no_parens,
"a {\n color: min(max);\n}\n", "Error: max is not a number."
);
error!(
min_min_invalid,
"a {\n color: min(min(#));\n}\n", "Error: Expected identifier."
);
test!(
min_calc_parens_no_args,
"a {\n color: min(calc());\n}\n",
"a {\n color: min(calc());\n}\n"
);