Add tests for variable scoping

This commit is contained in:
ConnorSkees 2020-01-17 21:15:38 -05:00
parent eaf1e8eb96
commit 4114cc6f9d
2 changed files with 15 additions and 1 deletions

View File

@ -719,6 +719,11 @@ mod css_variables {
"a {\n b {\n $c: red;\n }\n color: red;\n}\n",
"a {\n color: red;\n}\n"
);
test!(
variable_changes_through_new_ruleset,
"a {\n $c: red;\nb {\n $c: blue;\n }\n color: $c;\n}\n",
"a {\n color: blue;\n}\n"
);
}
#[cfg(test)]
@ -1097,4 +1102,14 @@ mod css_mixins {
"@mixin a {\n b {\n c {\n color: red;\n}\n}\n}\nd {\n @include a;\n}\n",
"d b c {\n color: red;\n}\n"
);
test!(
mixin_removes_empty_ruleset,
"@mixin a {\n color:red; b {\n}\n}\nd {\n @include a;\n}\n",
"d {\n color: red;\n}\n"
);
test!(
mixin_variable_scope_one_ruleset,
"@mixin a {\n $a: blue;\nb {\n $a: red;\n} color: $a\n}\nd {\n @include a;\n}\n",
"d {\n color: red;\n}\n"
);
}

View File

@ -41,7 +41,6 @@ impl Mixin {
pub fn eval(&mut self, super_selector: &Selector, scope: &mut Scope) -> Vec<Stmt> {
let mut stmts = Vec::new();
// dbg!(&scope);
while let Ok(expr) = eat_expr(&mut self.body, scope, super_selector) {
match expr {
Expr::Style(s) => stmts.push(Stmt::Style(s)),