time for sirdi

This commit is contained in:
rhiannon morris 2022-05-02 20:51:19 +02:00
parent f503cf5734
commit 9ae0e36a65
16 changed files with 99 additions and 109 deletions

View file

@ -1,101 +0,0 @@
module Tests.Equal
import Quox.Equal
import Quox.Pretty
import TAP
export
ToInfo Equal.Error where
toInfo (ClashT mode s t) =
[("clash", "term"),
("mode", show mode),
("left", prettyStr True s),
("right", prettyStr True t)]
toInfo (ClashU mode k l) =
[("clash", "universe"),
("mode", show mode),
("left", prettyStr True k),
("right", prettyStr True l)]
toInfo (ClashQ pi rh) =
[("clash", "quantity"),
("left", prettyStr True pi),
("right", prettyStr True rh)]
M = Error [Equal.Error]
testEq : String -> Lazy (M ()) -> Test
testEq = test
testNeq : String -> Lazy (M ()) -> Test
testNeq = testThrows
subT : {default 0 d, n : Nat} -> Term d n -> Term d n -> M ()
subT = Quox.Equal.subT
%hide Quox.Equal.subT
equalT : {default 0 d, n : Nat} -> Term d n -> Term d n -> M ()
equalT = Quox.Equal.equalT
%hide Quox.Equal.equalT
subE : {default 0 d, n : Nat} -> Elim d n -> Elim d n -> M ()
subE = Quox.Equal.subE
%hide Quox.Equal.subE
equalE : {default 0 d, n : Nat} -> Elim d n -> Elim d n -> M ()
equalE = Quox.Equal.equalE
%hide Quox.Equal.equalE
export
tests : Test
tests = "equality & subtyping" :- [
"universes" :- [
testEq "Type 0 == Type 0" $
equalT (TYPE (U 0)) (TYPE (U 0)),
testNeq "Type 0 =/= Type 1" $
equalT (TYPE (U 0)) (TYPE (U 1)),
testNeq "Type 1 =/= Type 0" $
equalT (TYPE (U 1)) (TYPE (U 0)),
testEq "Type 0 <: Type 0" $
subT (TYPE (U 0)) (TYPE (U 0)),
testEq "Type 0 <: Type 1" $
subT (TYPE (U 0)) (TYPE (U 1)),
testNeq "Type 1 </: Type 0" $
subT (TYPE (U 1)) (TYPE (U 0))
],
todo "pi",
todo "lambda",
todo "term closure",
todo "term d-closure",
"free var" :- [
testEq "A == A" $
equalE (F "A") (F "A"),
testNeq "A =/= B" $
equalE (F "A") (F "B"),
testEq "A <: A" $
subE (F "A") (F "A"),
testNeq "A </: B" $
subE (F "A") (F "B")
],
todo "bound var",
"application" :-
let a = F "a"; a' = E a
A = FT "A"
λxx = Lam "x" (TUsed (BVT 0))
A_A = Arr one A A
λxx' = λxx :# A_A
in [
testEq "(λx. x : A -> A) a == ((a : A) : A) (β)" $
equalE (λxx' :@ a') (E (a' :# A) :# A),
testEq "(λx. x : _) a == a (βυ)" $
equalE (λxx' :@ a') a
],
todo "annotation",
todo "elim closure",
todo "elim d-closure",
todo "clashes"
]

View file

@ -1,105 +0,0 @@
module Tests.Lexer
import Quox.Lexer
import TAP
export
ToInfo Error where
toInfo (Err line col char) =
[("line", show line), ("col", show col), ("char", show char)]
data ExtraError
= WrongAnswer (List Kind) (List Kind)
| TestFailed (List Kind)
ToInfo ExtraError where
toInfo (WrongAnswer exp got) =
[("expected", show exp), ("received", show got)]
toInfo (TestFailed got) = [("failed", show got)]
parameters (label : String) (input : String)
acceptsSuchThat' : (List Kind -> Maybe ExtraError) -> Test
acceptsSuchThat' p = test {es = [Lexer.Error, ExtraError]} label $ do
res <- map (kind . val) <$> lex input
case p res of
Just err => throw err
Nothing => pure ()
acceptsSuchThat : (List Kind -> Bool) -> Test
acceptsSuchThat p = acceptsSuchThat' $ \res =>
if p res then Nothing else Just $ TestFailed res
acceptsWith : List Kind -> Test
acceptsWith expect = acceptsSuchThat' $ \res =>
if res == expect then Nothing else Just $ WrongAnswer expect res
accepts : Test
accepts = acceptsSuchThat $ const True
rejects : Test
rejects = testThrows {es = [Lexer.Error]} label $ delay $
map (kind . val) <$> lex input
parameters (input : String) {default False esc : Bool}
show' : String -> String
show' s = if esc then show s else "\"\{s}\""
acceptsWith' : List Kind -> Test
acceptsWith' = acceptsWith (show' input) input
accepts' : Test
accepts' = accepts (show' input) input
rejects' : Test
rejects' = rejects "\{show' input} (reject)" input
tests = "lexer" :- [
"comments" :- [
acceptsWith' "" [],
acceptsWith' " \n \t\t " [] {esc = True},
acceptsWith' "-- a" [],
acceptsWith' "{- -}" [],
acceptsWith' "{--}" [],
acceptsWith' "{------}" [],
acceptsWith' "{- {- -} -}" [],
acceptsWith' "{- } -}" [],
rejects' "{-}",
rejects' "{- {- -}",
acceptsWith' "( -- comment \n )" [P LParen, P RParen] {esc = True}
],
"punctuation" :- [
acceptsWith' "({[:,::]})"
[P LParen, P LBrace, P LSquare,
P Colon, P Comma, P DblColon,
P RSquare, P RBrace, P RParen],
acceptsWith' " ( { [ : , :: ] } ) "
[P LParen, P LBrace, P LSquare,
P Colon, P Comma, P DblColon,
P RSquare, P RBrace, P RParen],
acceptsWith' "-> → => ⇒ ** × << ⊲ ∷"
[P Arrow, P Arrow, P DblArrow, P DblArrow,
P Times, P Times, P Triangle, P Triangle, P DblColon],
acceptsWith' "_" [P Wild]
],
"names & symbols" :- [
acceptsWith' "a" [Name],
acceptsWith' "abc" [Name],
acceptsWith' "_a" [Name],
acceptsWith' "a_" [Name],
acceptsWith' "a_b" [Name],
acceptsWith' "abc'" [Name],
acceptsWith' "a'b'c''" [Name],
acceptsWith' "abc123" [Name],
acceptsWith' "ab cd" [Name, Name],
acceptsWith' "ab{--}cd" [Name, Name],
acceptsWith' "'a" [Symbol],
acceptsWith' "'ab" [Symbol],
acceptsWith' "'_b" [Symbol],
rejects' "'"
]
]