From 2eff549d191ace945113095ecf29d7129abb93a2 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Mon, 15 Jul 2019 18:04:00 +1200 Subject: [PATCH] Test/fix parsing of psuedoclasses/elements. --- src/Data/CSS/Syntax/Selector.hs | 6 +++--- test/Test.hs | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Data/CSS/Syntax/Selector.hs b/src/Data/CSS/Syntax/Selector.hs index e96490e..0079c20 100644 --- a/src/Data/CSS/Syntax/Selector.hs +++ b/src/Data/CSS/Syntax/Selector.hs @@ -41,9 +41,9 @@ parseSelector (Delim '.':Ident class_:tokens) = parseSelector' (Class class_) to parseSelector (LeftSquareBracket:Ident prop:tokens) = concatP appendPropertySel parsePropertySel parseSelector tokens where appendPropertySel test selector = Property prop test : selector -parseSelector (Delim ':':Delim ':':Ident p:ts) = parseSelector' (Psuedoelement p) ts -parseSelector (Delim ':':Ident p:ts) = parseSelector' (Psuedoclass p []) ts -parseSelector (Delim ':':Function fn:tokens) = +parseSelector (Colon:Colon:Ident p:ts) = parseSelector' (Psuedoelement p) ts +parseSelector (Colon:Ident p:ts) = parseSelector' (Psuedoclass p []) ts +parseSelector (Colon:Function fn:tokens) = concatP appendPseudo scanBlock parseSelector tokens where appendPseudo args selector = Psuedoclass fn args : selector parseSelector tokens = ([], tokens) diff --git a/test/Test.hs b/test/Test.hs index 61bc96a..81ac26f 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -75,6 +75,14 @@ spec = do parse emptyStyle "a + b {}" `shouldBe` TrivialStyleSheet [ StyleRule (Adjacent (Element [Tag "a"]) [Tag "b"]) [] ] + parse emptyStyle "a::before {}" + `shouldBe` TrivialStyleSheet [ + StyleRule (Element [Tag "a", Psuedoelement "before"]) [] + ] + parse emptyStyle "a:before {}" + `shouldBe` TrivialStyleSheet [ + StyleRule (Element [Tag "a", Psuedoclass "before" []]) [] + ] describe "Style Index" $ do it "Retrieves appropriate styles" $ do let index = addStyleRule styleIndex 0 $ styleRule' sampleRule @@ -272,8 +280,7 @@ spec = do style ! "color" `shouldBe` [Ident "green"] describe "Parser freezes" $ do it "does not regress" $ do - -- TODO handle psuedoelements - parse emptyStyle "output::before {content: 'Output'; pitch: high}" + parse emptyStyle "output: {content: 'Output'; pitch: high}" `shouldBe` TrivialStyleSheet [ StyleRule (Element [Tag "output"]) [] ] -- Turned out to just be incorrect parsing -- 2.30.2