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 specs for string split #2

Closed
wants to merge 9 commits into from
Closed
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
179 changes: 179 additions & 0 deletions spec/core_functions/string/split.hrx
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<===> options.yml
---
:ignore_for:
- libsass

<===>
================================================================================
<===> empty/input.scss
a {b: split("")}

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

<===>
================================================================================
<===> separator/input.scss
a {b: split("a, b, c", ", ")}

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

<===>
================================================================================
<===> empty_separator/input.scss
a {b: split("Helvetica", "")}

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

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

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

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

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

<===>
================================================================================
<===> limit_zero/input.scss
a {b: split("a, b, c", ", ", 0)}

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

<===>
================================================================================
<===> double_width_character/input.scss
// 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: split("👭a", "")}

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

<===>
================================================================================
<===> private_use_character/input.scss
// Dart Sass emits private-use characters as escapes in expanded mode, but it
// should stil treat them as single characters for the purpose of functions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: still

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I'll fix.

a {b: split("\E000"), ""}

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

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

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

<===>
================================================================================
<===> error/too_many_args/input.scss
a {b: split("a/b/c", "/", 1, 3)}

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

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

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

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

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

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

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

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

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

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

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