From a35a8a23d9058012f5113d841cfafae9e0e58093 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 12 Jul 2019 17:13:21 +1200 Subject: [PATCH] Test cascade logic. --- src/Data/CSS/Style.hs | 2 +- test/Test.hs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Data/CSS/Style.hs b/src/Data/CSS/Style.hs index 6c4b2a5..1eb2f41 100644 --- a/src/Data/CSS/Style.hs +++ b/src/Data/CSS/Style.hs @@ -1,5 +1,5 @@ module Data.CSS.Style( - QueryableStyleSheet(..), queryableStyleSheet, + QueryableStyleSheet(..), QueryableStyleSheet'(..), queryableStyleSheet, queryRules, PropertyParser(..), cascade, TrivialPropertyParser(..), diff --git a/test/Test.hs b/test/Test.hs index da91cec..4697959 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -224,6 +224,42 @@ spec = do let rules = parse queryable "a.link {color: green} a {color: red}" let TrivialPropertyParser style = cascade rules el [] temp::TrivialPropertyParser style ! "color" `shouldBe` [Ident "green"] + it "respects syntax order" $ do + let el = ElementNode { + name = "a", + parent = Nothing, + previous = Nothing, + attributes = [Attribute "class" "link"] + } + let rules = parse queryable "a {color: red; color: green}" + let TrivialPropertyParser style = cascade rules el [] temp::TrivialPropertyParser + style ! "color" `shouldBe` [Ident "green"] + + let rules = parse queryable "a {color: red} a {color: green}" + let TrivialPropertyParser style = cascade rules el [] temp::TrivialPropertyParser + style ! "color" `shouldBe` [Ident "green"] + it "respects stylesheet precedence" $ do + let el = ElementNode { + name = "a", + parent = Nothing, + previous = Nothing, + attributes = [Attribute "class" "link"] + } + let rules = parse (queryable {priority = 1}) "a {color: green}" + let rules2 = parse (rules {priority = 2}) "a {color: red}" :: QueryableStyleSheet TrivialPropertyParser + let TrivialPropertyParser style = cascade rules2 el [] temp::TrivialPropertyParser + style ! "color" `shouldBe` [Ident "green"] + + let el = ElementNode { + name = "a", + parent = Nothing, + previous = Nothing, + attributes = [Attribute "class" "link"] + } + let rules = parse (queryable {priority = 1}) "a {color: red}" + let rules2 = parse (rules {priority = 2}) "a {color: green !important}" :: QueryableStyleSheet TrivialPropertyParser + let TrivialPropertyParser style = cascade rules2 el [] temp::TrivialPropertyParser + style ! "color" `shouldBe` [Ident "green"] styleIndex :: StyleIndex styleIndex = new -- 2.30.2