-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for first class mixins (#1933)
- Loading branch information
1 parent
dff3578
commit c55ca91
Showing
24 changed files
with
1,791 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2021 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import {SassMixin, compileString} from 'sass'; | ||
|
||
import {spy} from '../utils'; | ||
|
||
it('can round-trip a mixin reference from Sass', () => { | ||
const fn = spy(args => { | ||
expect(args).toBeArrayOfSize(1); | ||
const value = args[0]; | ||
expect(value).toBeInstanceOf(SassMixin); | ||
expect(value.assertCalculation).toThrow(); | ||
expect(value.assertColor).toThrow(); | ||
expect(value.assertFunction).toThrow(); | ||
expect(value.assertMap).toThrow(); | ||
expect(value.tryMap()).toBe(null); | ||
expect(value.assertMixin()).toBe(value); | ||
expect(value.assertNumber).toThrow(); | ||
expect(value.assertString).toThrow(); | ||
|
||
return value; | ||
}); | ||
|
||
expect( | ||
compileString( | ||
` | ||
@use 'sass:meta'; | ||
@mixin a() { | ||
a { | ||
b: c; | ||
} | ||
} | ||
@include meta.apply(foo(meta.get-mixin('a'))); | ||
`, | ||
{ | ||
functions: {'foo($arg)': fn}, | ||
} | ||
).css | ||
).toBe('a {\n b: c;\n}'); | ||
|
||
expect(fn).toHaveBeenCalled(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<===> options.yml | ||
--- | ||
:todo: | ||
- sass/libsass#2807 | ||
|
||
<===> | ||
================================================================================ | ||
<===> accepts/direct_child/input.scss | ||
@use "sass:meta"; | ||
|
||
@mixin a() {@content} | ||
|
||
a {b: meta.accepts-content(meta.get-mixin("a"))} | ||
|
||
<===> accepts/direct_child/output.css | ||
a { | ||
b: true; | ||
} | ||
|
||
<===> | ||
================================================================================ | ||
<===> accepts/nested_child/input.scss | ||
@use "sass:meta"; | ||
|
||
@mixin a() { | ||
@if false {@content} | ||
} | ||
|
||
a {b: meta.accepts-content(meta.get-mixin("a"))} | ||
|
||
<===> accepts/nested_child/output.css | ||
a { | ||
b: true; | ||
} | ||
|
||
<===> | ||
================================================================================ | ||
<===> accepts/builtin/input.scss | ||
@use "sass:meta"; | ||
|
||
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 a() {} | ||
|
||
a {b: meta.accepts-content(meta.get-mixin("a"))} | ||
|
||
<===> doesnt_accept/empty/output.css | ||
a { | ||
b: false; | ||
} | ||
|
||
<===> | ||
================================================================================ | ||
<===> doesnt_accept/builtin/input.scss | ||
@use "sass:meta"; | ||
@mixin a() {} | ||
|
||
a {b: meta.accepts-content(meta.get-mixin(load-css, meta))} | ||
|
||
<===> doesnt_accept/builtin/output.css | ||
a { | ||
b: false; | ||
} | ||
|
||
<===> | ||
================================================================================ | ||
<===> args/keyword/input.scss | ||
@use "sass:meta"; | ||
|
||
a {b: meta.accepts-content($mixin: meta.get-mixin(apply, meta))} | ||
|
||
<===> args/keyword/output.css | ||
a { | ||
b: true; | ||
} | ||
|
||
<===> | ||
================================================================================ | ||
<===> error/args/too_few/input.scss | ||
@use "sass:meta"; | ||
|
||
a {b: meta.accepts-content()} | ||
|
||
<===> error/args/too_few/error | ||
Error: Missing argument $mixin. | ||
,--> input.scss | ||
3 | a {b: meta.accepts-content()} | ||
| ^^^^^^^^^^^^^^^^^^^^^^ invocation | ||
' | ||
,--> sass:meta | ||
1 | @function accepts-content($mixin) { | ||
| ======================= declaration | ||
' | ||
input.scss 3:7 root stylesheet | ||
|
||
<===> | ||
================================================================================ | ||
<===> error/args/too_many/input.scss | ||
@use "sass:meta"; | ||
@mixin a() {} | ||
|
||
a {b: meta.accepts-content(a, a)} | ||
|
||
<===> error/args/too_many/error | ||
Error: Only 1 argument allowed, but 2 were passed. | ||
,--> input.scss | ||
4 | a {b: meta.accepts-content(a, a)} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ invocation | ||
' | ||
,--> sass:meta | ||
1 | @function accepts-content($mixin) { | ||
| ======================= declaration | ||
' | ||
input.scss 4:7 root stylesheet | ||
|
||
<===> | ||
================================================================================ | ||
<===> error/args/wrong_type/input.scss | ||
@use "sass:meta"; | ||
|
||
a {b: meta.accepts-content(meta.get-function("red"))} | ||
|
||
<===> error/args/wrong_type/error | ||
Error: $mixin: get-function("red") is not a mixin reference. | ||
, | ||
3 | a {b: meta.accepts-content(meta.get-function("red"))} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
' | ||
input.scss 3:7 root stylesheet |
Oops, something went wrong.