test: add more integration tests with insta. Like it!
This commit is contained in:
parent
cc476d367f
commit
8a98e73395
26 changed files with 413 additions and 21 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -3,3 +3,6 @@ rust-toolchain.toml
|
||||||
.vscode
|
.vscode
|
||||||
.profile
|
.profile
|
||||||
/Cargo.lock
|
/Cargo.lock
|
||||||
|
/tests/sabry_intermediate
|
||||||
|
/tests/sabry_output
|
||||||
|
/playground
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ sabry_intrnl = {workspace = true}
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
leptos = {version = "0.7.0-gamma3"}
|
leptos = {version = "0.7.0-gamma3"}
|
||||||
|
insta = {version = "^1.41", features = ["glob"]}
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["procmacro"]
|
default = ["procmacro"]
|
||||||
|
|
|
||||||
14
README.md
14
README.md
|
|
@ -51,7 +51,7 @@ Code your SASS in separate files to get proper syntax highlighting, or do sass-i
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
sabry::styly!(component {".btn {color: green;}"});
|
sabry::styly!(component {".btn {color: green;}"});
|
||||||
sabry::styly!(extras "tests/assets/mixins.scss");
|
sabry::styly!(extras "tests/assets/mixin-module.scss");
|
||||||
```
|
```
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
|
|
@ -88,7 +88,7 @@ sabry::styly!(breadbadge {"
|
||||||
Keep things as private and modular as you wish
|
Keep things as private and modular as you wish
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
sabry::styly!(pub cats "tests/assets/mixins.scss");
|
sabry::styly!(pub cats "tests/assets/mixin-module.scss");
|
||||||
sabry::styly!(dogs {"#howl {border: none;}"});
|
sabry::styly!(dogs {"#howl {border: none;}"});
|
||||||
```
|
```
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
|
|
@ -148,7 +148,7 @@ And a proc-macro
|
||||||
// lib.rs
|
// lib.rs
|
||||||
use sabry::sassy;
|
use sabry::sassy;
|
||||||
|
|
||||||
sassy!(mixins "tests/assets/mixins.scss");
|
sassy!(mixins "tests/assets/mixin-module.scss");
|
||||||
sassy!(styles {"
|
sassy!(styles {"
|
||||||
$primary-color: black;
|
$primary-color: black;
|
||||||
@mixin colored($col: primary) {
|
@mixin colored($col: primary) {
|
||||||
|
|
@ -443,8 +443,8 @@ Examples:
|
||||||
use sabry::sassy;
|
use sabry::sassy;
|
||||||
|
|
||||||
sassy!(module1 {"$primary-color: red;"});
|
sassy!(module1 {"$primary-color: red;"});
|
||||||
sassy!(module2 "tests/assets/mixins.scss");
|
sassy!(module2 "tests/assets/mixin-module.scss");
|
||||||
sassy!(module3:sass "tests/assets/mixins.sass");
|
sassy!(module3:sass "tests/assets/mixin-module.sass");
|
||||||
// works, but there are catches.
|
// works, but there are catches.
|
||||||
sassy!(module4:sass {"
|
sassy!(module4:sass {"
|
||||||
@mixin colored($col: primary)
|
@mixin colored($col: primary)
|
||||||
|
|
@ -514,7 +514,7 @@ You can read more about scoping and hashing in the [scoping](#scoping) section.
|
||||||
By default generated `mod` is private. You can make both mod and wrapper style constant public by adding the `pub` to macro call:
|
By default generated `mod` is private. You can make both mod and wrapper style constant public by adding the `pub` to macro call:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
sabry::styly!(pub whatever "tests/assets/mixins.scss");
|
sabry::styly!(pub whatever "tests/assets/mixin-module.scss");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Constant styly scopes
|
#### Constant styly scopes
|
||||||
|
|
@ -524,7 +524,7 @@ As you've seen above, scope doe not contain any style code by itself. That's the
|
||||||
However you could still compile styles into the artifact by simply adding the `const` to the macro call:
|
However you could still compile styles into the artifact by simply adding the `const` to the macro call:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
sabry::styly!(const scope "tests/assets/mixins.scss");
|
sabry::styly!(const scope "tests/assets/mixin-module.scss");
|
||||||
```
|
```
|
||||||
Which results in following:
|
Which results in following:
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
|
|
|
||||||
19
tests/assets/mixin-module.sass
Normal file
19
tests/assets/mixin-module.sass
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
|
||||||
|
@mixin color($color: black)
|
||||||
|
@if $color == black
|
||||||
|
color: white
|
||||||
|
background-color: green
|
||||||
|
@else if $color == white
|
||||||
|
color: red
|
||||||
|
background-color: black
|
||||||
|
@else
|
||||||
|
color: #c6c6c6
|
||||||
|
background-color: #00ffff
|
||||||
|
&::after
|
||||||
|
content: 'Colored'
|
||||||
|
color: $color
|
||||||
|
background-color: blue
|
||||||
|
&:hover
|
||||||
|
transform: scale(2)
|
||||||
|
&:hover
|
||||||
|
transform: translateX(10%)
|
||||||
24
tests/assets/mixin-module.scss
Normal file
24
tests/assets/mixin-module.scss
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
|
||||||
|
@mixin surface($color: black){
|
||||||
|
@if $color == black{
|
||||||
|
color: white;
|
||||||
|
background-color: green;
|
||||||
|
}@else if $color == white{
|
||||||
|
color: red;
|
||||||
|
background-color: black;
|
||||||
|
}@else{
|
||||||
|
color: #c6c6c6;
|
||||||
|
background-color: #00ffff;
|
||||||
|
}
|
||||||
|
&::after{
|
||||||
|
content: 'Colored';
|
||||||
|
color: $color;
|
||||||
|
background-color: blue;
|
||||||
|
&:hover{
|
||||||
|
transform: scale(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&:hover{
|
||||||
|
transform: translateX(10%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
@mixin colored($color: primary)
|
|
||||||
@if $color == primary
|
|
||||||
color: white
|
|
||||||
@else
|
|
||||||
color: $col
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
$primary-color: black;
|
|
||||||
|
|
||||||
@mixin colored($col: primary) {
|
|
||||||
@if $col == primary {
|
|
||||||
color: $primary-color;
|
|
||||||
} @else {
|
|
||||||
color: $col;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
3
tests/assets/module-forward.sass
Normal file
3
tests/assets/module-forward.sass
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
|
||||||
|
@forward 'mixins_a'
|
||||||
|
@forward 'mixins_c'
|
||||||
3
tests/assets/module-forward.scss
Normal file
3
tests/assets/module-forward.scss
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
|
||||||
|
@forward 'mixins_a';
|
||||||
|
@forward 'mixins_c';
|
||||||
15
tests/assets/module-usage.sass
Normal file
15
tests/assets/module-usage.sass
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
@use 'mixins_a' as *
|
||||||
|
@use 'mixins_c' as *
|
||||||
|
|
||||||
|
.coated
|
||||||
|
@include color(green)
|
||||||
|
@include surface(black)
|
||||||
|
&-dark
|
||||||
|
@include surface(red)
|
||||||
|
a
|
||||||
|
@include surface(blue)
|
||||||
|
img
|
||||||
|
@include color(black)
|
||||||
|
span
|
||||||
|
@include color(green)
|
||||||
|
display: block
|
||||||
20
tests/assets/module-usage.scss
Normal file
20
tests/assets/module-usage.scss
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
@use 'mixins_a' as *;
|
||||||
|
@use 'mixins_c' as *;
|
||||||
|
|
||||||
|
.coated{
|
||||||
|
@include color(green);
|
||||||
|
@include surface(black);
|
||||||
|
&-dark{
|
||||||
|
@include surface(red);
|
||||||
|
a{
|
||||||
|
@include surface(blue);
|
||||||
|
img{
|
||||||
|
@include color(black);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
span{
|
||||||
|
@include color(green);
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
3
tests/assets/prelude.css
Normal file
3
tests/assets/prelude.css
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
html {
|
||||||
|
background-color: dark;
|
||||||
|
}
|
||||||
5
tests/assets/prelude.sass
Normal file
5
tests/assets/prelude.sass
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
@use 'mixins_a' as *
|
||||||
|
@use 'mixins_c' as *
|
||||||
|
|
||||||
|
body
|
||||||
|
@include color()
|
||||||
6
tests/assets/prelude.scss
Normal file
6
tests/assets/prelude.scss
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
@use 'mixins_a' as *;
|
||||||
|
@use 'mixins_c' as *;
|
||||||
|
|
||||||
|
body {
|
||||||
|
@include surface();
|
||||||
|
}
|
||||||
17
tests/assets/sole-code.sass
Normal file
17
tests/assets/sole-code.sass
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
.fuzz
|
||||||
|
background-color: red
|
||||||
|
display: block
|
||||||
|
&-dark
|
||||||
|
background-color: black
|
||||||
|
color: white
|
||||||
|
a
|
||||||
|
text-transform: uppercase
|
||||||
|
img
|
||||||
|
position: absolute
|
||||||
|
top: 0
|
||||||
|
left: 10rem
|
||||||
|
span
|
||||||
|
position: relative
|
||||||
|
display: grid
|
||||||
|
grid-template-areas: 'a b c' 'd e f' 'x x x'
|
||||||
|
display: block
|
||||||
22
tests/assets/sole-code.scss
Normal file
22
tests/assets/sole-code.scss
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
.fuzz{
|
||||||
|
background-color: red;
|
||||||
|
display: block;
|
||||||
|
&-dark{
|
||||||
|
background-color: black;
|
||||||
|
color: white;
|
||||||
|
a{
|
||||||
|
text-transform: uppercase;
|
||||||
|
img{
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 10rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
span{
|
||||||
|
position: relative;
|
||||||
|
display: grid;
|
||||||
|
grid-template-areas: 'a b c' 'd e f' 'x x x';
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
tests/assets/use-forwarded.sass
Normal file
14
tests/assets/use-forwarded.sass
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
@use 'module_a' as *
|
||||||
|
|
||||||
|
.coated
|
||||||
|
@include color(green)
|
||||||
|
@include surface(black)
|
||||||
|
&-dark
|
||||||
|
@include surface(red)
|
||||||
|
a
|
||||||
|
@include surface(blue)
|
||||||
|
img
|
||||||
|
@include color(black)
|
||||||
|
span
|
||||||
|
@include color(green)
|
||||||
|
display: block
|
||||||
20
tests/assets/use-forwarded.scss
Normal file
20
tests/assets/use-forwarded.scss
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
@use 'module_c' as *;
|
||||||
|
|
||||||
|
|
||||||
|
.coated{
|
||||||
|
@include color(green);
|
||||||
|
@include surface(black);
|
||||||
|
&-dark{
|
||||||
|
@include surface(red);
|
||||||
|
a{
|
||||||
|
@include surface(blue);
|
||||||
|
img{
|
||||||
|
@include color(black);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
span{
|
||||||
|
@include color(green);
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
182
tests/macros.rs
Normal file
182
tests/macros.rs
Normal file
|
|
@ -0,0 +1,182 @@
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
use insta::{glob, Settings};
|
||||||
|
|
||||||
|
use sabry::{
|
||||||
|
buildmagic::SabryBuilder,
|
||||||
|
config::{BehavHashCollision, BehavSassModCollision, SabryConfig},
|
||||||
|
sassy, styly, usey,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub mod sass {
|
||||||
|
use sabry::sassy;
|
||||||
|
|
||||||
|
sassy!(mixins_sass:sass "tests/assets/mixin-module.sass");
|
||||||
|
sassy!(mixins_inline_sass:sass {"
|
||||||
|
@mixin color($color: black)
|
||||||
|
@if $color == black
|
||||||
|
color: white
|
||||||
|
background-color: green
|
||||||
|
@else if $color == white
|
||||||
|
color: red
|
||||||
|
background-color: black
|
||||||
|
@else
|
||||||
|
color: #c6c6c6
|
||||||
|
background-color: #00ffff
|
||||||
|
&::after
|
||||||
|
content: 'Colored'
|
||||||
|
color: $color
|
||||||
|
background-color: blue
|
||||||
|
&:hover
|
||||||
|
transform: scale(2)
|
||||||
|
&:hover
|
||||||
|
transform: translateX(10%)
|
||||||
|
"});
|
||||||
|
sassy!(module_sass:sass "tests/assets/module-forward.sass");
|
||||||
|
sassy!(module_inline_sass:sass {"
|
||||||
|
@forward 'mixins_a'
|
||||||
|
@forward 'mixins_c'
|
||||||
|
"});
|
||||||
|
pub(crate) use mixins_inline_sass as mixins_inline_a;
|
||||||
|
pub(crate) use mixins_sass as mixins_a;
|
||||||
|
pub(crate) use module_inline_sass as module_inline_a;
|
||||||
|
pub(crate) use module_sass as module_a;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod scss {
|
||||||
|
use sabry::sassy;
|
||||||
|
|
||||||
|
sassy!(mixins_scss:scss "tests/assets/mixin-module.scss");
|
||||||
|
sassy!(mixins_inline_scss:scss {"
|
||||||
|
@mixin surface($color: black){
|
||||||
|
@if $color == black{
|
||||||
|
color: white;
|
||||||
|
background-color: green;
|
||||||
|
}@else if $color == white{
|
||||||
|
color: red;
|
||||||
|
background-color: black;
|
||||||
|
}@else{
|
||||||
|
color: #c6c6c6;
|
||||||
|
background-color: #00ffff;
|
||||||
|
}
|
||||||
|
&::after{
|
||||||
|
content: 'Colored';
|
||||||
|
color: $color;
|
||||||
|
background-color: blue;
|
||||||
|
&:hover{
|
||||||
|
transform: scale(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&:hover{
|
||||||
|
transform: translateX(10%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"});
|
||||||
|
sassy!(module_scss:scss "tests/assets/module-forward.scss");
|
||||||
|
sassy!(module_inline_scss:scss {"
|
||||||
|
@forward 'mixins_a';
|
||||||
|
@forward 'mixins_c';
|
||||||
|
"});
|
||||||
|
|
||||||
|
pub(crate) use mixins_inline_scss as mixins_inline_c;
|
||||||
|
pub(crate) use mixins_scss as mixins_c;
|
||||||
|
pub(crate) use module_inline_scss as module_inline_c;
|
||||||
|
pub(crate) use module_scss as module_c;
|
||||||
|
}
|
||||||
|
|
||||||
|
styly!(sole_code_sass:sass "tests/assets/sole-code.sass");
|
||||||
|
styly!(sole_code_scss:scss "tests/assets/sole-code.scss");
|
||||||
|
styly!(module_usage_sass:sass "tests/assets/module-usage.sass");
|
||||||
|
styly!(module_usage_scss:scss "tests/assets/module-usage.scss");
|
||||||
|
styly!(use_forwarded_sass:sass "tests/assets/use-forwarded.sass");
|
||||||
|
styly!(use_forwarded_scss:scss "tests/assets/use-forwarded.scss");
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ensure_inline_matches_file() {
|
||||||
|
assert_eq!(sass::mixins_a!(), sass::mixins_inline_a!());
|
||||||
|
assert_eq!(scss::mixins_c!(), scss::mixins_inline_c!());
|
||||||
|
|
||||||
|
assert_eq!(sass::module_a!(), sass::module_inline_a!());
|
||||||
|
assert_eq!(scss::module_c!(), scss::module_inline_c!());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn syntax_contract() {
|
||||||
|
assert_eq!(scss::mixins_inline_c!(syntax), "scss");
|
||||||
|
assert_eq!(scss::mixins_c!(syntax), "scss");
|
||||||
|
assert_eq!(scss::module_inline_c!(syntax), "scss");
|
||||||
|
assert_eq!(scss::module_c!(syntax), "scss");
|
||||||
|
|
||||||
|
assert_eq!(sass::mixins_a!(syntax), "sass");
|
||||||
|
assert_eq!(sass::mixins_inline_a!(syntax), "sass");
|
||||||
|
assert_eq!(sass::module_a!(syntax), "sass");
|
||||||
|
assert_eq!(sass::module_inline_a!(syntax), "sass");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gen_config() -> SabryConfig {
|
||||||
|
let mut config = SabryConfig::require().unwrap();
|
||||||
|
config.css.bundle = Some("tests/sabry_output/bundle.css".into());
|
||||||
|
config.css.scopes = Some("tests/sabry_output/scopes".into());
|
||||||
|
config.css.minify = true;
|
||||||
|
config.css.prelude = Some(vec!["tests/assets/prelude.css".into()]);
|
||||||
|
|
||||||
|
config.sass.prelude = Some(vec![
|
||||||
|
"tests/assets/prelude.sass".into(),
|
||||||
|
"tests/assets/prelude.scss".into(),
|
||||||
|
]);
|
||||||
|
config.sass.intermediate_dir = "tests/sabry_intermediate".into();
|
||||||
|
config.sass.scanroot = "tests".into();
|
||||||
|
config.sass.module_name_collision = BehavSassModCollision::Merge;
|
||||||
|
|
||||||
|
config.hash.collision = BehavHashCollision::Error;
|
||||||
|
config.hash.size = 16;
|
||||||
|
config.hash.use_code_size = true;
|
||||||
|
config.hash.use_code_text = true;
|
||||||
|
config.hash.use_item_names = true;
|
||||||
|
config.hash.use_scope_name = true;
|
||||||
|
|
||||||
|
config.lightningcss.targets.android = Some("10".into());
|
||||||
|
config.lightningcss.targets.chrome = Some("100".into());
|
||||||
|
config.lightningcss.targets.edge = Some("80".into());
|
||||||
|
config.lightningcss.targets.firefox = Some("100".into());
|
||||||
|
config.lightningcss.targets.ie = Some("8".into());
|
||||||
|
config.lightningcss.targets.ios_saf = Some("13.2".into());
|
||||||
|
config.lightningcss.targets.opera = Some("80".into());
|
||||||
|
config.lightningcss.targets.safari = Some("11".into());
|
||||||
|
config.lightningcss.targets.samsung = Some("80".into());
|
||||||
|
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gen_builder() -> SabryBuilder {
|
||||||
|
let config = gen_config();
|
||||||
|
let builder = SabryBuilder::new(config);
|
||||||
|
|
||||||
|
builder
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn compilation_with_buildy() {
|
||||||
|
let mut builder = gen_builder();
|
||||||
|
builder
|
||||||
|
.build(usey!(
|
||||||
|
sass::mixins_a!(),
|
||||||
|
sass::module_a!(),
|
||||||
|
scss::mixins_c!(),
|
||||||
|
scss::module_c!()
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
glob!("sabry_output/**/*.css", |path| {
|
||||||
|
let generated = fs::read_to_string(path).unwrap();
|
||||||
|
|
||||||
|
let mut settings = Settings::clone_current();
|
||||||
|
settings.set_snapshot_path("sabry_output_snapshots");
|
||||||
|
settings.set_prepend_module_to_snapshot(false);
|
||||||
|
settings.set_omit_expression(true);
|
||||||
|
settings.remove_info();
|
||||||
|
settings.bind(|| {
|
||||||
|
insta::assert_snapshot!(generated);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue