Skip to content

Commit

Permalink
chore: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed May 10, 2024
1 parent 5f83f1a commit fe65a6a
Show file tree
Hide file tree
Showing 2 changed files with 263 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,17 @@ impl<'s, D: HandleDependency<'s>, W: HandleWarning<'s>> LexDependencies<'s, D, W
Some(has_white_space)
}

fn lex_icss_import(&mut self, lexer: &mut Lexer<'s>) -> Option<()> {
// TODO: Implement, ignore for now
loop {
lexer.consume();
if lexer.cur()? == C_RIGHT_CURLY {
break;
}
}
Some(())
}

fn consume_icss_export_prop(&self, lexer: &mut Lexer<'s>) -> Option<()> {
loop {
let c = lexer.cur()?;
Expand Down Expand Up @@ -1495,8 +1506,14 @@ impl<'s, D: HandleDependency<'s>, W: HandleWarning<'s>> Visitor<'s> for LexDepen
});
return Some(());
}
if matches!(self.scope, Scope::TopLevel) && name == ":export" {
self.lex_icss_export(lexer)?;
let is_import = name == ":import";
let is_export = name == ":export";
if matches!(self.scope, Scope::TopLevel) && (is_import || is_export) {
if is_import {
self.lex_icss_import(lexer)?;
} else if is_export {
self.lex_icss_export(lexer)?;
}
self.handle_dependency
.handle_dependency(Dependency::Replace {
content: "",
Expand Down
244 changes: 244 additions & 0 deletions tests/postcss_plugins/modules_local_by_default_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1244,3 +1244,247 @@ fn css_nesting() {
Options { mode: Mode::Pure },
);
}

// #[test]
// fn consider_import_statements_pure() {
// test_with_options(
// ":import(\"~/lol.css\") { foo: __foo; }",
// ":import(\"~/lol.css\") { foo: __foo; }",
// Options { mode: Mode::Pure },
// );
// }

#[test]
fn consider_export_statements_pure() {
test_with_options(
":export { foo: __foo; }",
":export { foo: __foo; }",
Options { mode: Mode::Pure },
);
}

#[test]
fn handle_negative_animation_delay_in_animation_shorthand() {
test(
".foo { animation: 1s -500ms; }",
":local(.foo) { animation: 1s -500ms; }",
);
test(
".foo { animation: 1s -500.0ms; }",
":local(.foo) { animation: 1s -500.0ms; }",
);
test(
".foo { animation: 1s -500.0ms -a_value; }",
":local(.foo) { animation: 1s -500.0ms :local(-a_value); }",
);
}

#[test]
fn at_scope_at_rule() {
test(
indoc! {r#"
.article-header {
color: red;
}
.article-body {
color: blue;
}
@scope (.article-body) to (.article-header) {
.article-body {
border: 5px solid black;
background-color: goldenrod;
}
}
@scope(.article-body)to(.article-header){
.article-footer {
border: 5px solid black;
}
}
@scope ( .article-body ) {
img {
border: 5px solid black;
background-color: goldenrod;
}
}
@scope {
:scope {
color: red;
}
}
"#},
indoc! {r#"
:local(.article-header) {
color: red;
}
:local(.article-body) {
color: blue;
}
@scope (:local(.article-body)) to (:local(.article-header)) {
:local(.article-body) {
border: 5px solid black;
background-color: goldenrod;
}
}
@scope(:local(.article-body))to(:local(.article-header)){
:local(.article-footer) {
border: 5px solid black;
}
}
@scope ( :local(.article-body) ) {
img {
border: 5px solid black;
background-color: goldenrod;
}
}
@scope {
:scope {
color: red;
}
}
"#},
);
test(
indoc! {r#"
@scope (.article-body) to (figure) {
.article-footer {
border: 5px solid black;
}
}
"#},
indoc! {r#"
@scope (:local(.article-body)) to (figure) {
:local(.article-footer) {
border: 5px solid black;
}
}
"#},
);
test(
indoc! {r#"
@scope (:local(.article-body)) to (:global(.class)) {
.article-footer {
border: 5px solid black;
}
:local(.class-1) {
color: red;
}
:global(.class-2) {
color: blue;
}
}
"#},
indoc! {r#"
@scope (:local(.article-body)) to (.class) {
:local(.article-footer) {
border: 5px solid black;
}
:local(.class-1) {
color: red;
}
.class-2 {
color: blue;
}
}
"#},
);
test_with_options(
indoc! {r#"
@scope (.article-header) to (.class) {
.article-footer {
border: 5px solid black;
}
.class-1 {
color: red;
}
.class-2 {
color: blue;
}
}
"#},
indoc! {r#"
@scope (:local(.article-header)) to (:local(.class)) {
:local(.article-footer) {
border: 5px solid black;
}
:local(.class-1) {
color: red;
}
:local(.class-2) {
color: blue;
}
}
"#},
Options { mode: Mode::Pure },
);
test(
indoc! {r#"
@scope (.article-header) to (.class) {
.article-footer {
src: url("./font.woff");
}
}
"#},
indoc! {r#"
@scope (:local(.article-header)) to (:local(.class)) {
:local(.article-footer) {
src: url("./font.woff");
}
}
"#},
);
test(
indoc! {r#"
.foo {
@scope (.article-header) to (.class) {
:scope {
background: blue;
}
.bar {
color: red;
}
}
}
"#},
indoc! {r#"
:local(.foo) {
@scope (:local(.article-header)) to (:local(.class)) {
:scope {
background: blue;
}
:local(.bar) {
color: red;
}
}
}
"#},
);
test_with_options(
indoc! {r#"
@scope (:global(.article-header).foo) to (:global(.class).bar) {
.bar {
color: red;
}
}
"#},
indoc! {r#"
@scope (.article-header:local(.foo)) to (.class:local(.bar)) {
:local(.bar) {
color: red;
}
}
"#},
Options { mode: Mode::Pure },
);
}

0 comments on commit fe65a6a

Please sign in to comment.