From 8faf9f60be1993997ebffe664e01492bf078b86d Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 6 Aug 2017 19:40:45 -0400 Subject: [PATCH] Correct the tests. --- test/Data/Syntax/Assignment/Spec.hs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/Data/Syntax/Assignment/Spec.hs b/test/Data/Syntax/Assignment/Spec.hs index 17102b8da..2e4130439 100644 --- a/test/Data/Syntax/Assignment/Spec.hs +++ b/test/Data/Syntax/Assignment/Spec.hs @@ -103,10 +103,10 @@ spec = do `shouldBe` Right (Out "green") - it "matches rules to the right of pure" $ + it "matches pure instead of rules to its right" $ fst <$> runAssignment headF "blue" ((green <|> pure (Out "other") <|> blue) <* many source) (makeState [node Blue 0 4 []]) `shouldBe` - Right (Out "blue") + Right (Out "other") it "matches other nodes with pure" $ fst <$> runAssignment headF "red" ((green <|> pure (Out "other") <|> blue) <* many source) (makeState [node Red 0 3 []]) @@ -123,7 +123,7 @@ spec = do fst <$> runAssignment headF "hello" red (makeState [node Red 0 5 []]) `shouldBe` Right (Out "hello") it "does not advance past the current node" $ - first fst (runAssignment headF "hi" (symbol Red) (makeState [ node Red 0 2 [] ])) `shouldBe` Left (Error (Span (Pos 1 1) (Pos 1 1)) [] (Just (Right Red))) + first fst (runAssignment headF "hi" (symbol Red) (makeState [ node Red 0 2 [] ])) `shouldBe` Left (Error (Span (Pos 1 1) (Pos 1 3)) [] (Just (Right Red))) describe "without catchError" $ do it "assignment returns unexpected symbol error" $ @@ -131,7 +131,7 @@ spec = do red (makeState [node Green 0 1 []])) `shouldBe` - Left (Error (Span (Pos 1 1) (Pos 1 1)) [Right Red] (Just (Right Green))) + Left (Error (Span (Pos 1 1) (Pos 1 2)) [Right Red] (Just (Right Green))) it "assignment returns unexpected end of input" $ first fst (runAssignment headF "A" @@ -160,7 +160,7 @@ spec = do (red `catchError` const blue) (makeState [node Green 0 1 []])) `shouldBe` - Left (Error (Span (Pos 1 1) (Pos 1 1)) [Right Blue] (Just (Right Green))) + Left (Error (Span (Pos 1 1) (Pos 1 2)) [Right Blue] (Just (Right Green))) describe "in many" $ do it "handler that always matches" $ @@ -184,16 +184,16 @@ spec = do (symbol Palette *> children ( many (red `catchError` const blue) )) (makeState [node Palette 0 1 [node Green 1 2 []]])) `shouldBe` - Left (Error (Span (Pos 1 2) (Pos 1 2)) [] (Just (Right Green))) + Left (Error (Span (Pos 1 2) (Pos 1 3)) [] (Just (Right Green))) - it "handlers defer to later rules" $ - fst <$> runAssignment headF "PG" + it "handlers are greedy" $ + first fst (runAssignment headF "PG" (symbol Palette *> children ( (,) <$> many (red `catchError` (\ _ -> OutError <$ location <*> source)) <*> green )) - (makeState [node Palette 0 1 [node Green 1 2 []]]) + (makeState [node Palette 0 1 [node Green 1 2 []]])) `shouldBe` - Right ([], Out "G") + Left (Error (Span (Pos 1 3) (Pos 1 3)) [Right Green] Nothing) it "handler that doesn't match with apply" $ fst <$> runAssignment headF "PG" @@ -235,7 +235,7 @@ spec = do it "does not match if its subrule does not match" $ first fst (runAssignment headF "a" (children red) (makeState [node Blue 0 1 [node Green 0 1 []]])) `shouldBe` - Left (Error (Span (Pos 1 1) (Pos 1 1)) [Right Red] (Just (Right Green))) + Left (Error (Span (Pos 1 1) (Pos 1 2)) [Right Red] (Just (Right Green))) it "matches nested children" $ fst <$> runAssignment headF "1" @@ -267,10 +267,10 @@ spec = do `shouldBe` Right (Out "red") - it "does not drop anonymous nodes after matching" $ + it "drops anonymous nodes after matching to ensure exhaustiveness" $ stateNodes . snd <$> runAssignment headF "red magenta" red (makeState [node Red 0 3 [], node Magenta 4 11 []]) `shouldBe` - Right [node Magenta 4 11 []] + Right [] it "does not drop anonymous nodes when requested" $ fst <$> runAssignment headF "magenta red" ((,) <$> magenta <*> red) (makeState [node Magenta 0 7 [], node Red 8 11 []])