mirror of
https://github.com/github/semantic.git
synced 2024-12-29 09:55:52 +03:00
Correct the tests.
This commit is contained in:
parent
6c1e9afbb0
commit
8faf9f60be
@ -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 []])
|
||||
|
Loading…
Reference in New Issue
Block a user