Skip to content

Commit

Permalink
Update tests to 2024-09-30
Browse files Browse the repository at this point in the history
Some order of unified selectors was cleaned up in dart sass, and can
now be cleaned up in rsass.
  • Loading branch information
kaj committed Oct 6, 2024
1 parent 8fc1bee commit 5396efc
Show file tree
Hide file tree
Showing 21 changed files with 161 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ project adheres to
* Improved parse error handling (PR #201, Issue #141).
Many parse errors now match the dart sass error message.
Also allow "loud" comments in more places.
* Updated sass-spec test suite to 2024-09-20.
* Updated sass-spec test suite to 2024-09-30.


## Release 0.28.10
Expand Down
10 changes: 5 additions & 5 deletions rsass/src/css/selectors/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,12 @@ fn unify_relbox(a: RelBox, b: RelBox) -> Option<Vec<RelBox>> {
s.into_iter().map(|s| Box::new((kind, s))).collect()
}
if a.0 == b.0 && a.1.compound.is_rootish() && b.1.compound.is_rootish() {
return Some(as_rel_vec(a.0, b.1.unify(a.1)));
return Some(as_rel_vec(a.0, a.1.unify(b.1)));
}

Some(match (*a, *b) {
((k @ AdjacentSibling, a), (AdjacentSibling, b))
| ((k @ Parent, a), (Parent, b)) => as_rel_vec(k, b._unify(a)?),
| ((k @ Parent, a), (Parent, b)) => as_rel_vec(k, a._unify(b)?),
((Ancestor, a), (Ancestor, b)) => {
if b.is_local_superselector(&a) {
as_rel_vec(Ancestor, a._unify(b)?)
Expand Down Expand Up @@ -560,10 +560,10 @@ fn unify_relbox(a: RelBox, b: RelBox) -> Option<Vec<RelBox>> {
.with_rel_of(k, a.clone())
.into_iter()
.chain(a.clone().with_rel_of(k, b.clone()))
.chain(b.unify(a)),
.chain(a.unify(b)),
)
} else {
as_rel_vec(Sibling, b.unify(a))
as_rel_vec(Sibling, a.unify(b))
}
}
((a_k @ AdjacentSibling, a_s), (Sibling, b_s))
Expand All @@ -578,7 +578,7 @@ fn unify_relbox(a: RelBox, b: RelBox) -> Option<Vec<RelBox>> {
a_s.clone()
.with_rel_of(Sibling, b_s.clone())
.into_iter()
.chain(a_s.unify(b_s)),
.chain(b_s.unify(a_s)),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod and_child {
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\".c > .d\", \".e > .f\")}\n"),
"a {\
\n b: .e.c > .d.f;\
\n b: .c.e > .d.f;\
\n}\n"
);
}
Expand All @@ -40,7 +40,7 @@ mod and_child {
\na {b: selector.unify(\".c.s1-1 > .s1-2\", \".c.s2-1 > .s2-2\")}\n"
),
"a {\
\n b: .c.s2-1.s1-1 > .s1-2.s2-2;\
\n b: .c.s1-1.s2-1 > .s1-2.s2-2;\
\n}\n"
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn isolated() {
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\".c > .d + .e\", \".f .g ~ .h\")}\n"),
"a {\
\n b: .f .c > .g ~ .d + .e.h, .f .c > .d.g + .e.h;\
\n b: .f .c > .g ~ .d + .e.h, .f .c > .g.d + .e.h;\
\n}\n"
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod and_next_sibling {
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\".c + .d\", \".e + .f\")}\n"),
"a {\
\n b: .e.c + .d.f;\
\n b: .c.e + .d.f;\
\n}\n"
);
}
Expand All @@ -60,7 +60,7 @@ mod and_next_sibling {
\na {b: selector.unify(\".c.s1-1 + .s1-2\", \".c.s2-1 + .s2-2\")}\n"
),
"a {\
\n b: .c.s2-1.s1-1 + .s1-2.s2-2;\
\n b: .c.s1-1.s2-1 + .s1-2.s2-2;\
\n}\n"
);
}
Expand Down Expand Up @@ -97,7 +97,7 @@ mod and_sibling {
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\".c + .d\", \".e ~ .f\")}\n"),
"a {\
\n b: .e ~ .c + .d.f, .c.e + .d.f;\
\n b: .e ~ .c + .d.f, .e.c + .d.f;\
\n}\n"
);
}
Expand All @@ -119,7 +119,7 @@ mod and_sibling {
\na {b: selector.unify(\".c.s1-1 + .s1-2\", \".c.s2-1 ~ .s2-2\")}\n"
),
"a {\
\n b: .c.s2-1 ~ .c.s1-1 + .s1-2.s2-2, .c.s1-1.s2-1 + .s1-2.s2-2;\
\n b: .c.s2-1 ~ .c.s1-1 + .s1-2.s2-2, .c.s2-1.s1-1 + .s1-2.s2-2;\
\n}\n"
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod and_next_sibling {
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\".c ~ .d\", \".e + .f\")}\n"),
"a {\
\n b: .c ~ .e + .d.f, .e.c + .d.f;\
\n b: .c ~ .e + .d.f, .c.e + .d.f;\
\n}\n"
);
}
Expand All @@ -69,7 +69,7 @@ mod and_next_sibling {
\na {b: selector.unify(\".c.s1-1 ~ .s1-2\", \".c.s2-1 + .s2-2\")}\n"
),
"a {\
\n b: .c.s1-1 ~ .c.s2-1 + .s1-2.s2-2, .c.s2-1.s1-1 + .s1-2.s2-2;\
\n b: .c.s1-1 ~ .c.s2-1 + .s1-2.s2-2, .c.s1-1.s2-1 + .s1-2.s2-2;\
\n}\n"
);
}
Expand Down Expand Up @@ -106,7 +106,7 @@ mod and_sibling {
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\".c ~ .d\", \".e ~ .f\")}\n"),
"a {\
\n b: .c ~ .e ~ .d.f, .e ~ .c ~ .d.f, .e.c ~ .d.f;\
\n b: .c ~ .e ~ .d.f, .e ~ .c ~ .d.f, .c.e ~ .d.f;\
\n}\n"
);
}
Expand All @@ -128,7 +128,7 @@ mod and_sibling {
\na {b: selector.unify(\".c.s1-1 ~ .s1-2\", \".c.s2-1 ~ .s2-2\")}\n"
),
"a {\
\n b: .c.s1-1 ~ .c.s2-1 ~ .s1-2.s2-2, .c.s2-1 ~ .c.s1-1 ~ .s1-2.s2-2, .c.s2-1.s1-1 ~ .s1-2.s2-2;\
\n b: .c.s1-1 ~ .c.s2-1 ~ .s1-2.s2-2, .c.s2-1 ~ .c.s1-1 ~ .s1-2.s2-2, .c.s1-1.s2-1 ~ .s1-2.s2-2;\
\n}\n"
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn mixed() {
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\":root .c .d\", \":scope .e .f\")}\n"),
"a {\
\n b: :scope:root .c .e .d.f, :scope:root .e .c .d.f;\
\n b: :root:scope .c .e .d.f, :root:scope .e .c .d.f;\
\n}\n"
);
}
Expand All @@ -52,7 +52,7 @@ mod root {
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\".c:root .d\", \".e:root .f\")}\n"),
"a {\
\n b: .e.c:root .d.f;\
\n b: .c.e:root .d.f;\
\n}\n"
);
}
Expand Down
134 changes: 128 additions & 6 deletions rsass/tests/spec/core_functions/selector/unify/compound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,50 @@ fn runner() -> crate::TestRunner {
super::runner().with_cwd("compound")
}

#[test]
fn full_overlap() {
assert_eq!(
runner().ok("@use \"sass:selector\";\
mod full_overlap {
#[allow(unused)]
use super::runner;

#[test]
fn class() {
assert_eq!(
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\".c.d\", \".c.d\")}\n"),
"a {\
"a {\
\n b: .c.d;\
\n}\n"
);
);
}
#[test]
fn pseudo_class() {
assert_eq!(
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\".c:d\", \".c:d\")}\n"),
"a {\
\n b: .c:d;\
\n}\n"
);
}
#[test]
fn pseudo_element() {
assert_eq!(
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\".c::d\", \".c::d\")}\n"),
"a {\
\n b: .c::d;\
\n}\n"
);
}
#[test]
fn pseudo_selector_and_class() {
assert_eq!(
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\".c:d::e\", \".c:d::e\")}\n"),
"a {\
\n b: .c:d::e;\
\n}\n"
);
}
}
#[test]
fn no_overlap() {
Expand All @@ -29,6 +64,93 @@ mod order {
#[allow(unused)]
use super::runner;

mod do_not_cross_pseudo_element {
#[allow(unused)]
use super::runner;

mod pseudo_class_and_element {
#[allow(unused)]
use super::runner;

#[test]
fn into_different_pseudo_element_and_different_pseudo_class() {
assert_eq!(
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\"::foo:bar\", \"::other:baz\")}\n"),
""
);
}
#[test]
#[ignore] // wrong result
fn into_pseudo_element() {
assert_eq!(
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\"::bar:baz\", \":foo\")}\n"),
"a {\
\n b: :foo::bar:baz;\
\n}\n"
);
}
#[test]
#[ignore] // wrong result
fn into_same_pseudo_element_and_different_pseudo_class() {
assert_eq!(
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\"::foo:bar\", \"::foo:baz\")}\n"),
"a {\
\n b: ::foo:bar:baz;\
\n}\n"
);
}
#[test]
#[ignore] // wrong result
fn into_simple() {
assert_eq!(
runner().ok(
"@use \"sass:selector\";\
\na {b: selector.unify(\".x::scrollbar:horizontal\", \".y\")}\n"
),
"a {\
\n b: .x.y::scrollbar:horizontal;\
\n}\n"
);
}
}
mod pseudo_element {
#[allow(unused)]
use super::runner;

#[test]
#[ignore] // wrong result
fn into_pseudo_class_and_element() {
assert_eq!(
runner().ok("@use \"sass:selector\";\
\na {b: selector.unify(\":foo\", \"::bar:baz\")}\n"),
"a {\
\n b: :foo::bar:baz;\
\n}\n"
);
}
}
mod simple {
#[allow(unused)]
use super::runner;

#[test]
#[ignore] // wrong result
fn into_pseudo_class_and_element() {
assert_eq!(
runner().ok(
"@use \"sass:selector\";\
\na {b: selector.unify(\".x\", \".y::scrollbar:horizontal\")}\n"
),
"a {\
\n b: .x.y::scrollbar:horizontal;\
\n}\n"
);
}
}
}
#[test]
fn element_at_start() {
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion rsass/tests/spec/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Tests auto-converted from "sass-spec/spec"
//! version ddf4b0999, 2024-09-20 20:55:56 +0000.
//! version 83bd49982, 2024-09-30 17:39:23 -0700.
//! See <https://github.com/sass/sass-spec> for source material.\n
//! The following tests are excluded from conversion:
//! ["directives/extend", "libsass-todo-issues/issue_221260.hrx", "libsass-todo-issues/issue_221262.hrx", "libsass-todo-issues/issue_221264.hrx", "libsass-todo-issues/issue_221292.hrx", "libsass/unicode-bom/utf-16-big", "libsass/unicode-bom/utf-16-little", "non_conformant/scss/huge.hrx", "non_conformant/scss/multiline-var.hrx"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn test() {
assert_eq!(
runner().ok(".foo > .bar {a: b}\
\n.bip > .baz {@extend .bar}\n"),
".foo > .bar, .bip.foo > .baz {\
".foo > .bar, .foo.bip > .baz {\
\n a: b;\
\n}\n"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn test() {
assert_eq!(
runner().ok(".a ~ x {a: b}\
\n.b ~ y {@extend x}\n"),
".a ~ x, .a ~ .b ~ y, .b ~ .a ~ y, .b.a ~ y {\
".a ~ x, .a ~ .b ~ y, .b ~ .a ~ y, .a.b ~ y {\
\n a: b;\
\n}\n"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn test() {
assert_eq!(
runner().ok(".a + x {a: b}\
\n.b ~ y {@extend x}\n"),
".a + x, .b ~ .a + y, .a.b + y {\
".a + x, .b ~ .a + y, .b.a + y {\
\n a: b;\
\n}\n"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn test() {
assert_eq!(
runner().ok(".a ~ x {a: b}\
\n.b + y {@extend x}\n"),
".a ~ x, .a ~ .b + y, .b.a + y {\
".a ~ x, .a ~ .b + y, .a.b + y {\
\n a: b;\
\n}\n"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn test() {
assert_eq!(
runner().ok(".a.b > x {a: b}\
\n.b > y {@extend x}\n"),
".a.b > x, .b.a > y {\
".a.b > x, .a.b > y {\
\n a: b;\
\n}\n"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn test() {
assert_eq!(
runner().ok(".a > x {a: b}\
\n.b > y {@extend x}\n"),
".a > x, .b.a > y {\
".a > x, .a.b > y {\
\n a: b;\
\n}\n"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn test() {
assert_eq!(
runner().ok(".a.b + x {a: b}\
\n.b + y {@extend x}\n"),
".a.b + x, .b.a + y {\
".a.b + x, .a.b + y {\
\n a: b;\
\n}\n"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn test() {
assert_eq!(
runner().ok(".a + x {a: b}\
\n.b + y {@extend x}\n"),
".a + x, .b.a + y {\
".a + x, .a.b + y {\
\n a: b;\
\n}\n"
);
Expand Down
Loading

0 comments on commit 5396efc

Please sign in to comment.