Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for string.split() #1841

Merged
merged 14 commits into from
Dec 16, 2022
225 changes: 225 additions & 0 deletions spec/core_functions/string/split.hrx
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
<===> options.yml
---
:ignore_for:
- libsass

<===>
================================================================================
<===> empty_string/input.scss
@use "sass:string";
a {b: string.split("", "/")}

<===> empty_string/output.css
a {
b: [];
}

<===>
================================================================================
<===> empty_separator/input.scss
@use "sass:string";
a {b: string.split("Helvetica", "")}

<===> empty_separator/output.css
a {
b: ["H", "e", "l", "v", "e", "t", "i", "c", "a"];
}

<===>
================================================================================
<===> both_empty/input.scss
@use "sass:string";
a {b: string.split("", "")}

<===> both_empty/output.css
a {
b: [];
}

<===>
================================================================================
<===> separator/input.scss
@use "sass:string";
a {b: string.split("a, b, c", ", ")}

<===> separator/output.css
a {
b: ["a", "b", "c"];
}

<===>
================================================================================
<===> separator_not_found/input.scss
@use "sass:string";
a {b: string.split("a, b, c", "&")}

<===> separator_not_found/output.css
a {
b: ["a, b, c"];
}

<===>
================================================================================
<===> limit/input.scss
@use "sass:string";
a {b: string.split("a, b, c, d", ", ", 2)}

<===> limit/output.css
a {
b: ["a", "b", "c, d"];
}

<===>
================================================================================
<===> double_width_character/input.scss
@use "sass:string";
// Sass treats strings as sequences of Unicode codepoint; it doesn't care if a
// character is represented as two UTF-16 code units.
a {b: string.split("👭a", "")}

<===> double_width_character/output.css
a {
b: ["👭", "a"];
}

<===>
================================================================================
<===> private_use_character/input.scss
@use "sass:string";
// Dart Sass emits private-use characters as escapes in expanded mode, but it
// should still treat them as single characters for the purpose of functions.
a {b: string.split("\E000", "")}

<===> private_use_character/output.css
a {
b: ["\E000"];
}

<===>
================================================================================
<===> named/input.scss
@use "sass:string";
a {b: string.split($string: "a/b/c", $separator: "/", $limit: 1)}

<===> named/output.css
a {
b: ["a", "b/c"];
}

<===>
================================================================================
<===> error/too_many_args/input.scss
nex3 marked this conversation as resolved.
Show resolved Hide resolved
@use "sass:string";
a {b: string.split("a/b/c", "/", 1, 3)}

<===> error/too_many_args/error
nex3 marked this conversation as resolved.
Show resolved Hide resolved
Error: Only 3 arguments allowed, but 4 were passed.
1 | a {b: string.split("a/b/c", "/", 1, 3)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ invocation
'
,--> sass:string
1 | @function split($string, $separator, $limit: null) {
| ======================================== declaration
'
input.scss 1:7 root stylesheet

<===>
================================================================================
<===> error/too_few_args/input.scss
@use "sass:string";
a {b: string.split("a/b/c")}

<===> error/too_few_args/error
Error: Missing argument $separator.
1 | a {b: string.split("a/b/c")}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ invocation
'
,--> sass:string
1 | @function split($string, $separator, $limit: null) {
| ======================================== declaration
'
input.scss 1:7 root stylesheet

<===>
================================================================================
<===> error/type/string/input.scss
@use "sass:string";
a {b: string.split(1, "%")}

<===> error/type/string/error
Error: $string: 1 is not a string.
,
1 | a {b: string.split(1, "%")}
| ^^^^^^^^^^^^^
'
input.scss 1:7 root stylesheet

<===>
================================================================================
<===> error/type/separator/input.scss
@use "sass:string";
a {b: string.split("1/2/3", /)}

<===> error/type/separator/error
Error: $separator: / is not a string.
,
1 | a {b: string.split("1/2/3", /)}
dvdherron marked this conversation as resolved.
Show resolved Hide resolved
| ^^^^^^^^^^^^^^^^^
'
input.scss 1:7 root stylesheet

<===>
================================================================================
<===> error/type/limit/input.scss
@use "sass:string";
a {b: string.split("1/2/3", "/", "1")}

<===> error/type/limit/error
Error: $limit: "1" is not a number.
,
1 | a {b: string.split("1/2/3", "/", "1")}
| ^^^^^^^^^^^^^^^^^^^^^^^^
'
input.scss 1:7 root stylesheet

<===>
================================================================================
<===> error/decimal/input.scss
@use "sass:string";
a {b: string.split("1/2/3", "/", 0.5)}

<===> error/decimal/error
Error: $limit: 0.5 is not an int.
,
1 | a {b: string.split("1/2/3", "/", 0.5)}
| ^^^^^^^^^^^^^^^^^^^^^^^
'
input.scss 1:7 root stylesheet

<===>
================================================================================
<===> error/negative_limit/input.scss
@use "sass:string";
a {b: string.split("1/2/3", "/", -1)}

<===> error/negative_limit/error
Error: $limit: Must be a positive int or null.
,
1 | a {b: string.split("1/2/3", "/", -1)}
| ^^^^^^^^^^^^^^^^^^^^^^^
'
input.scss 1:7 root stylesheet

<===>
================================================================================
<===> error/limit_zero/input.scss
@use "sass:string";
a {b: string.split("a, b, c", ", ", 0)}

<===> error/limit_zero/error
Error: $limit: Must be null or an int greather than or equal to 1.
,
1 | a {b: string.split("a, b, c", ", ", 0)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'
input.scss 1:7 root stylesheet