add string.split error tests
This commit is contained in:
parent
8831279ee1
commit
c494abc78e
@ -149,7 +149,7 @@ pub(crate) fn str_split(mut args: ArgumentResult, visitor: &mut Visitor) -> Sass
|
|||||||
let limit_int = limit.assert_int_with_name("limit", args.span())?;
|
let limit_int = limit.assert_int_with_name("limit", args.span())?;
|
||||||
if limit_int < 1 {
|
if limit_int < 1 {
|
||||||
return Err((
|
return Err((
|
||||||
format!("$limit: Must be greater than 1, was {}.", limit_int),
|
format!("$limit: Must be 1 or greater, was {}.", limit_int),
|
||||||
args.span(),
|
args.span(),
|
||||||
)
|
)
|
||||||
.into());
|
.into());
|
||||||
|
@ -53,6 +53,7 @@ pub(crate) fn fuzzy_as_int(num: f64) -> Option<i64> {
|
|||||||
let rounded = num.round();
|
let rounded = num.round();
|
||||||
|
|
||||||
if fuzzy_equals(num, rounded) {
|
if fuzzy_equals(num, rounded) {
|
||||||
|
// todo: this can oveflow
|
||||||
Some(rounded as i64)
|
Some(rounded as i64)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -311,27 +311,91 @@ test!(
|
|||||||
test!(
|
test!(
|
||||||
str_split_abc_space,
|
str_split_abc_space,
|
||||||
"@use 'sass:string';
|
"@use 'sass:string';
|
||||||
foo {
|
a {
|
||||||
bar: string.split('a b c', ' ');
|
color: string.split('a b c', ' ');
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
"foo {\n bar: [\"a\", \"b\", \"c\"];\n}\n"
|
"a {\n color: [\"a\", \"b\", \"c\"];\n}\n"
|
||||||
);
|
);
|
||||||
test!(
|
test!(
|
||||||
str_split_abc_space_1,
|
str_split_abc_space_1,
|
||||||
"@use 'sass:string';
|
"@use 'sass:string';
|
||||||
foo {
|
a {
|
||||||
bar: string.split('a b c', ' ', 1);
|
color: string.split('a b c', ' ', 1);
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
"foo {\n bar: [\"a\", \"b c\"];\n}\n"
|
"a {\n color: [\"a\", \"b c\"];\n}\n"
|
||||||
);
|
);
|
||||||
test!(
|
test!(
|
||||||
str_split_rgb_comma,
|
str_split_rgb_comma,
|
||||||
"@use 'sass:string';
|
"@use 'sass:string';
|
||||||
foo {
|
a {
|
||||||
bar: string.split('red,green,blue', ',');
|
color: string.split('red,green,blue', ',');
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
"foo {\n bar: [\"red\", \"green\", \"blue\"];\n}\n"
|
"a {\n color: [\"red\", \"green\", \"blue\"];\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
str_split_big_limit,
|
||||||
|
"@use 'sass:string';
|
||||||
|
a {
|
||||||
|
color: string.split('red,green,blue', ',', 9223372036854775808);
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"a {\n color: [\"red\", \"green\", \"blue\"];\n}\n"
|
||||||
|
);
|
||||||
|
error!(
|
||||||
|
str_split_negative_limit,
|
||||||
|
"@use 'sass:string';
|
||||||
|
a {
|
||||||
|
color: string.split('red,green,blue', ',', -1);
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"Error: $limit: Must be 1 or greater, was -1."
|
||||||
|
);
|
||||||
|
error!(
|
||||||
|
str_split_zero_limit,
|
||||||
|
"@use 'sass:string';
|
||||||
|
a {
|
||||||
|
color: string.split('red,green,blue', ',', 0);
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"Error: $limit: Must be 1 or greater, was 0."
|
||||||
|
);
|
||||||
|
error!(
|
||||||
|
str_split_string_limit,
|
||||||
|
"@use 'sass:string';
|
||||||
|
a {
|
||||||
|
color: string.split('red,green,blue', ',', '0');
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"Error: $limit: \"0\" is not a number."
|
||||||
|
);
|
||||||
|
error!(
|
||||||
|
str_split_first_arg_not_string,
|
||||||
|
"@use 'sass:string';
|
||||||
|
a {
|
||||||
|
color: string.split(1, ',');
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"Error: $string: 1 is not a string."
|
||||||
|
);
|
||||||
|
error!(
|
||||||
|
str_split_second_arg_not_string,
|
||||||
|
"@use 'sass:string';
|
||||||
|
a {
|
||||||
|
color: string.split('1', 2);
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"Error: $separator: 2 is not a string."
|
||||||
|
);
|
||||||
|
error!(
|
||||||
|
#[ignore = "overflow issue"]
|
||||||
|
str_split_limit_above_i64_max,
|
||||||
|
"@use 'sass:string';
|
||||||
|
a {
|
||||||
|
color: string.split('1', '1', 36893488147419103232);
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"Error: $limit: 36893488147419103000 is not an int."
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user