~alcinnz/haskell-stylist

a35a8a23d9058012f5113d841cfafae9e0e58093 — Adrian Cochrane 5 years ago 3bd6ae5
Test cascade logic.
2 files changed, 37 insertions(+), 1 deletions(-)

M src/Data/CSS/Style.hs
M test/Test.hs
M src/Data/CSS/Style.hs => src/Data/CSS/Style.hs +1 -1
@@ 1,5 1,5 @@
module Data.CSS.Style(
        QueryableStyleSheet(..), queryableStyleSheet,
        QueryableStyleSheet(..), QueryableStyleSheet'(..), queryableStyleSheet,
        queryRules,
        PropertyParser(..), cascade,
        TrivialPropertyParser(..),

M test/Test.hs => test/Test.hs +36 -0
@@ 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