Simplification of the test code.

master
Philippe Pittoli 2024-01-19 18:24:02 +01:00
parent e459de778d
commit bbb5c1c415
1 changed files with 35 additions and 93 deletions

View File

@ -2,14 +2,14 @@ module Test.Main where
import GenericParser.Parser (Parser(..))
import GenericParser.DomainParser.Common (ldh_str, DomainError(..))
import GenericParser.DomainParserRFC1035 (domain, label, sub_eof, subdomain)
import GenericParser.DomainParserRFC1035 as RFC1035
import Prelude (Unit, discard, show, ($), (<>))
import Prelude (Unit, discard, show, ($), (<>), map)
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Data.String.CodeUnits (fromCharArray)
import Effect.Console (log)
import Effect (Effect)
import Effect (Effect, foreachE)
logtest :: forall e v. String -> Parser e v -> String -> (v -> String) -> (e -> String) -> Effect Unit
logtest fname (Parser p) str r e = do
@ -29,99 +29,41 @@ showerror (DomainTooLarge size) = "DomainTooLarge (size: " <> show size <> ")"
showerror (InvalidCharacter) = "InvalidCharacter"
showerror (EOFExpected) = "EOFExpected"
test_series :: forall e v. String -> Parser e v -> (v -> String) -> (e -> String) -> Array String -> Effect Unit
test_series l p v e a = foreachE a (\s -> logtest l p s v e)
main :: Effect Unit
main = do
logtest "ldh_str" ldh_str "a12B.fl" fromCharArray showerror
logtest "ldh_str" ldh_str "1efg.x1" fromCharArray showerror
logtest "ldh_str" ldh_str ".qjzleb" fromCharArray showerror
logtest "ldh_str" ldh_str "a-b.b-a" fromCharArray showerror
logtest "ldh_str" ldh_str "" fromCharArray showerror
let domains = [
"",
"-",
".",
"a",
"a.",
"a-",
"a.x",
"a2.org",
"a33.org",
"a444.org",
"a5555.org",
"a66666.org",
"a777777.org",
"a8888888.org",
"xblah.a.x",
"xblah.a2.org",
"xblah.a33.org",
"xblah.a444.org",
"xblah.a5555.org",
"xblah.a66666.org",
"xblah.a777777.org",
"xblah.a8888888.org"
]
test_series "ldh_str" ldh_str fromCharArray showerror domains
log ""
logtest "label" label "example.org" id showerror
logtest "label" label "" id showerror
logtest "label" label "a.x" id showerror
logtest "label" label "a2.org" id showerror
logtest "label" label "a33.org" id showerror
logtest "label" label "a444.org" id showerror
logtest "label" label "a5555.org" id showerror
logtest "label" label "a66666.org" id showerror
logtest "label" label "a777777.org" id showerror
logtest "label" label "a8888888.org" id showerror
test_series "RFC1035.label" RFC1035.label id showerror domains
log ""
logtest "label" label "-" id showerror
logtest "label" label "a-" id showerror
test_series "RFC1035.subdomain" RFC1035.subdomain id showerror domains
log ""
logtest "subdomain" subdomain "example.org" id showerror
logtest "subdomain" subdomain "" id showerror
logtest "subdomain" subdomain "a.x" id showerror
logtest "subdomain" subdomain "a2.org" id showerror
logtest "subdomain" subdomain "a33.org" id showerror
logtest "subdomain" subdomain "a444.org" id showerror
logtest "subdomain" subdomain "a5555.org" id showerror
logtest "subdomain" subdomain "a66666.org" id showerror
logtest "subdomain" subdomain "a777777.org" id showerror
logtest "subdomain" subdomain "a8888888.org" id showerror
logtest "subdomain" subdomain "xblah.a.x" id showerror
logtest "subdomain" subdomain "xblah.a2.org" id showerror
logtest "subdomain" subdomain "xblah.a33.org" id showerror
logtest "subdomain" subdomain "xblah.a444.org" id showerror
logtest "subdomain" subdomain "xblah.a5555.org" id showerror
logtest "subdomain" subdomain "xblah.a66666.org" id showerror
logtest "subdomain" subdomain "xblah.a777777.org" id showerror
logtest "subdomain" subdomain "xblah.a8888888.org" id showerror
logtest "subdomain" subdomain "-" id showerror
logtest "subdomain" subdomain "a-" id showerror
test_series "RFC1035.sub_eof" RFC1035.sub_eof id showerror domains
log ""
logtest "sub_eof" sub_eof " " id showerror
logtest "sub_eof" sub_eof " " id showerror
logtest "sub_eof" sub_eof "example.org" id showerror
logtest "sub_eof" sub_eof "" id showerror
logtest "sub_eof" sub_eof "a.x" id showerror
logtest "sub_eof" sub_eof "a2.org" id showerror
logtest "sub_eof" sub_eof "a33.org" id showerror
logtest "sub_eof" sub_eof "a444.org" id showerror
logtest "sub_eof" sub_eof "a5555.org" id showerror
logtest "sub_eof" sub_eof "a66666.org" id showerror
logtest "sub_eof" sub_eof "a777777.org" id showerror
logtest "sub_eof" sub_eof "a8888888.org" id showerror
logtest "sub_eof" sub_eof "xblah.a.x" id showerror
logtest "sub_eof" sub_eof "xblah.a2.org" id showerror
logtest "sub_eof" sub_eof "xblah.a33.org" id showerror
logtest "sub_eof" sub_eof "xblah.a444.org" id showerror
logtest "sub_eof" sub_eof "xblah.a5555.org" id showerror
logtest "sub_eof" sub_eof "xblah.a66666.org" id showerror
logtest "sub_eof" sub_eof "xblah.a777777.org" id showerror
logtest "sub_eof" sub_eof "xblah.a8888888.org" id showerror
logtest "sub_eof" sub_eof "-" id showerror
logtest "sub_eof" sub_eof "a-" id showerror
log ""
logtest "domain" domain " " id showerror
logtest "domain" domain " " id showerror
logtest "domain" domain "example.org" id showerror
logtest "domain" domain "" id showerror
logtest "domain" domain "a.x" id showerror
logtest "domain" domain "a2.org" id showerror
logtest "domain" domain "a33.org" id showerror
logtest "domain" domain "a444.org" id showerror
logtest "domain" domain "a5555.org" id showerror
logtest "domain" domain "a66666.org" id showerror
logtest "domain" domain "a777777.org" id showerror
logtest "domain" domain "a8888888.org" id showerror
logtest "domain" domain "xblah.a.x" id showerror
logtest "domain" domain "xblah.a2.org" id showerror
logtest "domain" domain "xblah.a33.org" id showerror
logtest "domain" domain "xblah.a444.org" id showerror
logtest "domain" domain "xblah.a5555.org" id showerror
logtest "domain" domain "xblah.a66666.org" id showerror
logtest "domain" domain "xblah.a777777.org" id showerror
logtest "domain" domain "xblah.a8888888.org" id showerror
logtest "domain" domain "-" id showerror
logtest "domain" domain "a-" id showerror
test_series "RFC1035.domain" RFC1035.domain id showerror domains