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 first class mixins #1933

Merged
merged 36 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a03b8f7
add tests for first class mixins
connorskees Aug 25, 2023
99ebbf1
add more apply and get-mixin tests
connorskees Sep 3, 2023
fe8b737
add another content scope test
connorskees Sep 8, 2023
634d71a
tidy, add tests
connorskees Sep 8, 2023
3168534
resolve lints
connorskees Sep 8, 2023
cb3b2d4
fix formatting
connorskees Sep 8, 2023
1dcde0f
ignore libsass
connorskees Sep 8, 2023
7058169
formatting
connorskees Sep 8, 2023
6dfcf9f
add apply built test, update error spans
connorskees Sep 14, 2023
68d906b
Merge branch 'main' of https://github.com/sass/sass-spec into feat/fi…
connorskees Sep 14, 2023
ee795d9
change error message for issue_1079
connorskees Sep 16, 2023
f1dc81d
lint spec
connorskees Sep 18, 2023
9384c56
Merge branch 'main' of https://github.com/sass/sass-spec into feat/fi…
connorskees Sep 18, 2023
e6d89d9
Merge branch 'main' of https://github.com/sass/sass-spec into feat/fi…
connorskees Sep 21, 2023
a6874bf
bump ci
connorskees Sep 21, 2023
a203dfc
pr review
connorskees Sep 22, 2023
565122a
more pr review
connorskees Sep 22, 2023
bdf1d4f
fix lint
connorskees Sep 22, 2023
ff5560f
ignore libsass
connorskees Sep 22, 2023
2617471
add apply tests
connorskees Sep 22, 2023
ad746a1
make more things be on a single line
connorskees Sep 22, 2023
ca84c9c
pr review
connorskees Sep 23, 2023
a290209
add rest argument tests
connorskees Sep 23, 2023
84d29a1
use semantic placeholders in fallthrough tests
connorskees Sep 23, 2023
2318026
use semantic placeholders in redeclare using test
connorskees Sep 25, 2023
6f0fc96
add different rest tests, move error tests
connorskees Sep 27, 2023
156da5b
Merge branch 'main' of https://github.com/sass/sass-spec into feat/fi…
connorskees Sep 29, 2023
f918847
add js api mixin test
connorskees Sep 29, 2023
36e7d78
use apply in test
connorskees Sep 29, 2023
896ccf6
bump ci
connorskees Sep 29, 2023
7ecf824
add negative assertions for mixin
connorskees Sep 29, 2023
2b017e3
alphabetize
connorskees Sep 29, 2023
55fe148
remove faulty assertion
connorskees Oct 4, 2023
d940acb
add back instanceof assertion
connorskees Oct 4, 2023
b3131b8
use proper instanceof check
connorskees Oct 4, 2023
7b989f0
stricter assertMixin, use toBeInstanceOf
connorskees Oct 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions spec/core_functions/meta/accepts_content.hrx
connorskees marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<===> options.yml
---
:todo:
- sass/libsass#2807

<===>
================================================================================
<===> accepts/direct-child/input.scss
@use "sass:meta";

@mixin foo() {
connorskees marked this conversation as resolved.
Show resolved Hide resolved
@content;
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved. It would be nice if lint-spec enforced this or if lint-spec --fix fixed this -- it was somewhat tedious to grep for to find all places with the wrong indentation.

}
connorskees marked this conversation as resolved.
Show resolved Hide resolved

a {b: meta.accepts-content(meta.get-mixin("foo"))}

<===> accepts/direct-child/output.css
a {
b: true;
}

<===>
================================================================================
<===> accepts/nested-child/input.scss
@use "sass:meta";

@mixin foo() {
@if false {
@content;
}
}

a {b: meta.accepts-content(meta.get-mixin("foo"))}

<===> accepts/nested-child/output.css
a {
b: true;
}

<===>
================================================================================
<===> accepts/builtin/input.scss
@use "sass:meta";
@mixin foo() {}
connorskees marked this conversation as resolved.
Show resolved Hide resolved

a {b: meta.accepts-content(meta.get-mixin(apply, meta))}

<===> accepts/builtin/output.css
a {
b: true;
}

<===>
================================================================================
<===> doesnt-accept/empty/input.scss
@use "sass:meta";
@mixin foo() {}

a {b: meta.accepts-content(meta.get-mixin("foo"))}

<===> doesnt-accept/empty/output.css
a {
b: false;
}

<===>
================================================================================
<===> doesnt-accept/builtin/input.scss
@use "sass:meta";
@mixin foo() {}

a {b: meta.accepts-content(meta.get-mixin(load-css, meta))}

<===> doesnt-accept/builtin/output.css
a {
b: false;
}
122 changes: 122 additions & 0 deletions spec/core_functions/meta/apply.hrx
connorskees marked this conversation as resolved.
Show resolved Hide resolved
connorskees marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<===> options.yml
---
:todo:
- sass/libsass#2807

<===>
================================================================================
<===> use-as-function/input.scss
connorskees marked this conversation as resolved.
Show resolved Hide resolved
@use "sass:meta";

@mixin foo {}
$foo: meta.get-mixin("foo");

a {b: meta.apply($foo)}

<===> use-as-function/error
Error: Undefined function.
,
6 | a {b: meta.apply($foo)}
| ^^^^^^^^^^^^^^^^
'
input.scss 6:7 root stylesheet

<===>
================================================================================
<===> no-args/input.scss
@use "sass:meta";

a {@include meta.apply()}

<===> no-args/error
Error: Missing argument $mixin.
,--> input.scss
3 | a {@include meta.apply()}
| ^^^^^^^^^^^^^^^^^^^^^ invocation
'
,--> sass:meta
1 | @mixin apply($mixin, $args...) {
| ======================= declaration
'
input.scss 3:4 root stylesheet

<===>
================================================================================
<===> wrong-arg-type/input.scss
@use "sass:meta";

a {@include meta.apply(2px)}

<===> wrong-arg-type/error
Error: $mixin: 2px is not a mixin reference.
,
3 | a {@include meta.apply(2px)}
| ^^^^^^^^^^^^^^^^^^^^^^^^
'
input.scss 3:4 root stylesheet

<===>
================================================================================
<===> too-many-args/input.scss
@use "sass:meta";

@mixin foo {}
$foo: meta.get-mixin("foo");

a {@include meta.apply($foo, 2px)}

<===> too-many-args/error
Error: Only 0 arguments allowed, but 1 was passed.
,
3 | @mixin foo {}
| === declaration
... |
6 | a {@include meta.apply($foo, 2px)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invocation
'
input.scss 6:4 foo()
input.scss 6:4 root stylesheet

<===>
================================================================================
<===> missing-mixin-args/input.scss
@use "sass:meta";

@mixin foo($a) {}
$foo: meta.get-mixin("foo");

a {@include meta.apply($foo)}

<===> missing-mixin-args/error
Error: Missing argument $a.
,
3 | @mixin foo($a) {}
| ======= declaration
... |
6 | a {@include meta.apply($foo)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ invocation
'
input.scss 6:4 foo()
input.scss 6:4 root stylesheet

<===>
================================================================================
<===> too-many-args-mixin-accepts-args/input.scss
@use "sass:meta";

@mixin foo($a) {}
$foo: meta.get-mixin("foo");

a {@include meta.apply($foo, 2px, 3px)}

<===> too-many-args-mixin-accepts-args/error
Error: Only 1 argument allowed, but 2 were passed.
,
3 | @mixin foo($a) {}
| ======= declaration
... |
6 | a {@include meta.apply($foo, 2px, 3px)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invocation
'
input.scss 6:4 foo()
input.scss 6:4 root stylesheet
172 changes: 172 additions & 0 deletions spec/core_functions/meta/get_mixin/content.hrx
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<===> passes-content/input.scss
@use "sass:meta";

@mixin foo {
@content;
}
connorskees marked this conversation as resolved.
Show resolved Hide resolved

a {
@include meta.apply(meta.get-mixin("foo")) {
b: red;
}
}

<===> passes-content/output.css
a {
b: red;
}

<===>
================================================================================
<===> passes-empty-content/input.scss
@use "sass:meta";

@mixin foo {
@content;
}

a {
@include meta.apply(meta.get-mixin("foo")) {}
}

<===> passes-empty-content/output.css

<===>
================================================================================
<===> denies-content/user-defined/input.scss
@use "sass:meta";
@mixin foo {}

a {
@include meta.apply(meta.get-mixin("foo")) {}
}

<===> denies-content/user-defined/error
Error: Mixin doesn't accept a content block.
,
2 | @mixin foo {}
| === declaration
... |
5 | @include meta.apply(meta.get-mixin("foo")) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invocation
'
input.scss 5:5 root stylesheet

<===>
================================================================================
<===> denies-content/builtin/input.scss
@use "sass:meta";

a {
@include meta.apply(meta.get-mixin(load-css, meta), "foo") {
a: b;
}
}

<===> denies-content/builtin/error
Error: Mixin doesn't accept a content block.
,--> input.scss
4 | @include meta.apply(meta.get-mixin(load-css, meta), "foo") {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invocation
'
,--> sass:meta
1 | @mixin load-css($url, $with: null) {
| =========================== declaration
'
input.scss 4:5 root stylesheet

<===>
================================================================================
<===> scope/redeclare-vars/input.scss
connorskees marked this conversation as resolved.
Show resolved Hide resolved
@use "sass:meta";
@mixin foo($a: a) {
$b: b;
@content;
a: $a;
b: $b;
connorskees marked this conversation as resolved.
Show resolved Hide resolved
}

$c: c;

a {
$d: d;
@include meta.apply(meta.get-mixin("foo")) {
$a: x;
$b: x;
$c: x;
$d: x;
}
c: $c;
d: $d;
}

<===> scope/redeclare-vars/output.css
a {
a: a;
b: b;
c: c;
d: x;
}

<===>
================================================================================
<===> scope/redeclare/using/input.scss
@use "sass:meta";
@mixin foo($a: x) {
@content(a);
}

$a: y;

a {
$a: z;
@include meta.apply(meta.get-mixin("foo")) using ($a) {
a: $a;
$a: a;
}
b: $a;
}

<===> scope/redeclare/using/output.css
a {
a: a;
b: z;
}

<===>
================================================================================
<===> scope/fall-through/input.scss
@use "sass:meta";
$b: x;

@mixin foo {
@content(x);
b: $b;
}

@mixin bar {
$b: a;
@include meta.apply(meta.get-mixin(foo)) using ($a) {
@content($a);
}
}

@mixin baz {
$b: b;
@include meta.apply(meta.get-mixin(bar)) using ($a) {
@content($a);
}
}

a {
$b: c;
@include meta.apply(meta.get-mixin(baz)) using ($a) {
a: $a;
}
}

<===> scope/fall-through/output.css
a {
a: x;
b: x;
}
Loading
Loading