Added a test: see if my parsers aren't modifying the input.
This commit is contained in:
parent
ea72414e6a
commit
d7f713839c
@ -1,6 +1,6 @@
|
|||||||
module Test.Main where
|
module Test.Main where
|
||||||
|
|
||||||
import Prelude (Unit, discard, show, ($), (<>))
|
import Prelude (Unit, discard, show, ($), (<>), (==))
|
||||||
import Data.Either (Either(..))
|
import Data.Either (Either(..))
|
||||||
import Data.Maybe (Maybe(..), maybe)
|
import Data.Maybe (Maybe(..), maybe)
|
||||||
import Data.String.CodeUnits (fromCharArray)
|
import Data.String.CodeUnits (fromCharArray)
|
||||||
@ -17,6 +17,29 @@ import GenericParser.IPAddress as IP
|
|||||||
import GenericParser.EmailAddress as E
|
import GenericParser.EmailAddress as E
|
||||||
import Test.TestValues as T
|
import Test.TestValues as T
|
||||||
|
|
||||||
|
run :: forall e v. Parser e v -> String -> P.Result e v
|
||||||
|
run (Parser p) str = p { string: str, position: 0 }
|
||||||
|
|
||||||
|
data COMPARISON = SAME | DIFFERENT | FAILED
|
||||||
|
compare_results :: forall e v. Parser e v -> Parser e v -> String -> COMPARISON
|
||||||
|
compare_results p1 p2 str
|
||||||
|
= let e1 = run p1 str
|
||||||
|
e2 = run p2 str
|
||||||
|
in case e1, e2 of
|
||||||
|
Right r1, Right r2 -> if r1.suffix == r2.suffix
|
||||||
|
then SAME
|
||||||
|
else DIFFERENT
|
||||||
|
_, _ -> FAILED
|
||||||
|
|
||||||
|
compare_parsers :: forall e v. String -> Parser e v -> Parser e v -> String -> Effect Unit
|
||||||
|
compare_parsers s p1 p2 str
|
||||||
|
= log $ s <> " "
|
||||||
|
<> case compare_results p1 p2 str of
|
||||||
|
SAME -> "SAME"
|
||||||
|
DIFFERENT -> "DIFFERENT"
|
||||||
|
FAILED -> "FAILED"
|
||||||
|
<> " [" <> str <>"] "
|
||||||
|
|
||||||
logtest :: forall e v. String -> Parser e v -> String -> (v -> String) -> (e -> String) -> Effect Unit
|
logtest :: forall e v. String -> Parser e v -> String -> (v -> String) -> (e -> String) -> Effect Unit
|
||||||
logtest fname (Parser p) str r e = do
|
logtest fname (Parser p) str r e = do
|
||||||
log $ "(" <> fname <> ") parsing '" <> str <> "': "
|
log $ "(" <> fname <> ") parsing '" <> str <> "': "
|
||||||
@ -99,3 +122,6 @@ main = do
|
|||||||
let quotedstrings = [ """" "spaces?""", """ " " """ ]
|
let quotedstrings = [ """" "spaces?""", """ " " """ ]
|
||||||
test_series "E.quoted_string---------------" E.quoted_string id showerror_email quotedstrings
|
test_series "E.quoted_string---------------" E.quoted_string id showerror_email quotedstrings
|
||||||
test_series "P.read_input (E.quoted_string)" (P.read_input E.quoted_string) id showerror_email quotedstrings
|
test_series "P.read_input (E.quoted_string)" (P.read_input E.quoted_string) id showerror_email quotedstrings
|
||||||
|
|
||||||
|
log "Does parsers behave correctly (give the exact same input)?"
|
||||||
|
foreachE T.valid_email_addresses_short (\s -> compare_parsers "E.address" (P.read_input E.address) E.address s)
|
||||||
|
Loading…
Reference in New Issue
Block a user