-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roland Peelen
committed
Aug 14, 2022
1 parent
eec403b
commit 99290c7
Showing
6 changed files
with
81 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ dependencies: | |
- containers | ||
- split | ||
- yaml-config | ||
- QuickCheck | ||
|
||
library: | ||
source-dirs: src | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Helpers (genSafeChar, genSafeString, SafeString, toString, checkN) where | ||
|
||
import Test.QuickCheck | ||
|
||
checkN x = quickCheckWith (stdArgs {maxSuccess = x}) | ||
|
||
genSafeChar :: Gen Char | ||
genSafeChar = elements $ ['a' .. 'z'] ++ ['A' .. 'Z'] | ||
|
||
genSafeString :: Gen String | ||
genSafeString = listOf genSafeChar | ||
|
||
newtype SafeString = SafeString {toString :: String} | ||
deriving (Show) | ||
|
||
instance Arbitrary SafeString where | ||
arbitrary = SafeString <$> genSafeString | ||
|
||
genType :: Gen String | ||
genType = listOf genSafeChar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{-# LANGUAGE NumericUnderscores #-} | ||
|
||
module SchemaParserSpec (run) where | ||
|
||
import qualified Data.Text as T | ||
import Helpers (SafeString, checkN, toString) | ||
import qualified SchemaParser | ||
import Test.QuickCheck | ||
import Text.Parsec | ||
|
||
parseError = "Some Parse Error" | ||
|
||
-- (String, String) -> Either ParseError (T.Text, T.Text) | ||
parseToEither fn s1 s2 = fn (toString s1) (toString s2) == Right (T.strip $ T.pack $ toString s1, T.strip $ T.pack $ toString s2) | ||
|
||
-- parseQualifiedType | ||
parseQualifiedType :: String -> String -> Either ParseError (T.Text, T.Text) | ||
parseQualifiedType s1 s2 = runParser SchemaParser.parseQualifiedType () parseError (T.pack (s1 <> "." <> s2)) | ||
|
||
parseQualifiedTypeTest :: SafeString -> SafeString -> Bool | ||
parseQualifiedTypeTest = parseToEither parseQualifiedType | ||
|
||
-- ParseTypecontainer | ||
parseTypeContainer :: String -> String -> Either ParseError (T.Text, T.Text) | ||
parseTypeContainer s1 s2 = runParser SchemaParser.parseTypeContainer () parseError (T.pack (s1 <> "<" <> s2 <> ">")) | ||
|
||
parseTypeContainerTest :: SafeString -> SafeString -> Bool | ||
parseTypeContainerTest = parseToEither parseTypeContainerTest | ||
|
||
-- ParseType | ||
parseType :: String -> String -> Either ParseError (T.Text, T.Text) | ||
parseType s1 s2 = runParser SchemaParser.parseType () parseError (T.pack (s1 <> "->" <> s2 <> ",")) | ||
|
||
parseTypeTest :: SafeString -> SafeString -> Bool | ||
parseTypeTest = parseToEither parseType | ||
|
||
run :: IO () | ||
run = do | ||
checkN 1_000 parseTypeTest | ||
checkN 1_000 parseTypeContainerTest | ||
checkN 1_000 parseQualifiedTypeTest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
import qualified SchemaParserSpec | ||
|
||
main :: IO () | ||
main = putStrLn "Test suite not yet implemented" | ||
main = SchemaParserSpec.run |