module Tests.PrettyTerm import TAP import Quox.Syntax import PrettyExtra parameters (ds : BContext d) (ns : BContext n) testPrettyT : Term d n -> (uni, asc : String) -> {default uni label : String} -> Test testPrettyT t uni asc {label} = testPretty (prettyTerm ds ns) t uni asc {label} testPrettyT1 : Term d n -> (str : String) -> {default str label : String} -> Test testPrettyT1 t str {label} = testPrettyT t str str {label} testPrettyE : Elim d n -> (uni, asc : String) -> {default uni label : String} -> Test testPrettyE e uni asc {label} = testPrettyT (E e) uni asc {label} testPrettyE1 : Elim d n -> (str : String) -> {default str label : String} -> Test testPrettyE1 e str {label} = testPrettyT1 (E e) str {label} prefix 9 ^ (^) : (Loc -> a) -> a (^) a = a noLoc FromString BindName where fromString str = BN (fromString str) noLoc export tests : Test tests = "pretty printing terms" :- [ "free vars" :- [ testPrettyE1 [<] [<] (^F "x" 0) "x", testPrettyE [<] [<] (^F "x" 1) "xยน" "x^1", testPrettyE1 [<] [<] (^F (MakeName [< "A", "B", "C"] "x") 0) "A.B.C.x", testPrettyE [<] [<] (^F (MakeName [< "A", "B", "C"] "x") 2) "A.B.C.xยฒ" "A.B.C.x^2" ], "bound vars" :- [ testPrettyE1 [< "๐‘–", "๐‘—"] [< "x", "y"] (^BV 0) "y", testPrettyE1 [< "๐‘–", "๐‘—"] [< "x", "y"] (^BV 1) "x", testPrettyE1 [< "๐‘–", "๐‘—"] [< "x", "y"] (^DApp (^F "eq" 0) (^BV 1)) "eq @๐‘–", testPrettyE1 [< "๐‘–", "๐‘—"] [< "x", "y"] (^DApp (^DApp (^F "eq" 0) (^BV 1)) (^BV 0)) "eq @๐‘– @๐‘—" ], "applications" :- [ testPrettyE1 [<] [<] (^App (^F "f" 0) (^FT "x" 0)) "f x", testPrettyE1 [<] [<] (^App (^App (^F "f" 0) (^FT "x" 0)) (^FT "y" 0)) "f x y", testPrettyE1 [<] [<] (^DApp (^F "f" 0) (^K Zero)) "f @0", testPrettyE1 [<] [<] (^DApp (^App (^F "f" 0) (^FT "x" 0)) (^K Zero)) "f x @0", testPrettyE1 [<] [<] (^App (^DApp (^F "g" 0) (^K One)) (^FT "y" 0)) "g @1 y" ], "lambda" :- [ testPrettyT [<] [<] (^LamY "x" (^BVT 0)) "ฮป x โ‡’ x" "fun x => x", testPrettyT [<] [<] (^LamN (^FT "a" 0)) "ฮป _ โ‡’ a" "fun _ => a", testPrettyT [<] [< "y"] (^LamY "x" (^BVT 1)) "ฮป x โ‡’ y" "fun x => y", testPrettyT [<] [<] (^LamY "x" (^LamY "y" (^LamY "f" (E $ ^App (^App (^BV 0) (^BVT 2)) (^BVT 1))))) "ฮป x y f โ‡’ f x y" "fun x y f => f x y", testPrettyT [<] [<] (^DLam (SN (^FT "a" 0))) "ฮด _ โ‡’ a" "dfun _ => a", testPrettyT [<] [<] (^DLamY "i" (^FT "x" 0)) "ฮด i โ‡’ x" "dfun i => x", testPrettyT [<] [<] (^LamY "x" (^DLamY "i" (E $ ^DApp (^BV 0) (^BV 0)))) "ฮป x โ‡’ ฮด i โ‡’ x @i" "fun x => dfun i => x @i" ], "type universes" :- [ testPrettyT [<] [<] (^TYPE 0) "โ˜…โฐ" "Type 0", testPrettyT [<] [<] (^TYPE 100) "โ˜…ยนโฐโฐ" "Type 100" ], "function types" :- [ testPrettyT [<] [<] (^Arr One (^FT "A" 0) (^FT "B" 0)) "1.A โ†’ B" "1.A -> B", testPrettyT [<] [<] (^PiY One "x" (^FT "A" 0) (E $ ^App (^F "B" 0) (^BVT 0))) "1.(x : A) โ†’ B x" "1.(x : A) -> B x", testPrettyT [<] [<] (^PiY Zero "A" (^TYPE 0) (^Arr Any (^BVT 0) (^BVT 0))) "0.(A : โ˜…โฐ) โ†’ ฯ‰.A โ†’ A" "0.(A : Type 0) -> #.A -> A", testPrettyT [<] [<] (^Arr Any (^Arr Any (^FT "A" 0) (^FT "A" 0)) (^FT "A" 0)) "ฯ‰.(ฯ‰.A โ†’ A) โ†’ A" "#.(#.A -> A) -> A", testPrettyT [<] [<] (^Arr Any (^FT "A" 0) (^Arr Any (^FT "A" 0) (^FT "A" 0))) "ฯ‰.A โ†’ ฯ‰.A โ†’ A" "#.A -> #.A -> A", testPrettyT [<] [<] (^PiY Zero "P" (^Arr Zero (^FT "A" 0) (^TYPE 0)) (E $ ^App (^BV 0) (^FT "a" 0))) "0.(P : 0.A โ†’ โ˜…โฐ) โ†’ P a" "0.(P : 0.A -> Type 0) -> P a" ], "pair types" :- [ testPrettyT [<] [<] (^And (^FT "A" 0) (^FT "B" 0)) "A ร— B" "A ** B", testPrettyT [<] [<] (^SigY "x" (^FT "A" 0) (E $ ^App (^F "B" 0) (^BVT 0))) "(x : A) ร— B x" "(x : A) ** B x", testPrettyT [<] [<] (^SigY "x" (^FT "A" 0) (^SigY "y" (E $ ^App (^F "B" 0) (^BVT 0)) (E $ ^App (^App (^F "C" 0) (^BVT 1)) (^BVT 0)))) "(x : A) ร— (y : B x) ร— C x y" "(x : A) ** (y : B x) ** C x y", todo "non-dependent, left and right nested" ], "pairs" :- [ testPrettyT1 [<] [<] (^Pair (^FT "A" 0) (^FT "B" 0)) "(A, B)", testPrettyT1 [<] [<] (^Pair (^FT "A" 0) (^Pair (^FT "B" 0) (^FT "C" 0))) "(A, B, C)", testPrettyT1 [<] [<] (^Pair (^Pair (^FT "A" 0) (^FT "B" 0)) (^FT "C" 0)) "((A, B), C)", testPrettyT [<] [<] (^Pair (^LamY "x" (^BVT 0)) (^Arr One (^FT "Bโ‚" 0) (^FT "Bโ‚‚" 0))) "(ฮป x โ‡’ x, 1.Bโ‚ โ†’ Bโ‚‚)" "(fun x => x, 1.Bโ‚ -> Bโ‚‚)" ], "enum types" :- [ testPrettyT1 [<] [<] (^enum []) "{}", testPrettyT1 [<] [<] (^enum ["a"]) "{a}", testPrettyT1 [<] [<] (^enum ["aa", "bb", "cc"]) "{aa, bb, cc}", testPrettyT1 [<] [<] (^enum ["a b c"]) #"{"a b c"}"#, testPrettyT1 [<] [<] (^enum ["\"", ",", "\\"]) #" {"\"", ",", \} "# {label = #"{"\"", ",", \} # ๏ฝข\๏ฝฃ is an identifier"#} ], "tags" :- [ testPrettyT1 [<] [<] (^Tag "a") "'a", testPrettyT1 [<] [<] (^Tag "hello") "'hello", testPrettyT1 [<] [<] (^Tag "qualified.tag") "'qualified.tag", testPrettyT1 [<] [<] (^Tag "non-identifier tag") #"'"non-identifier tag""#, testPrettyT1 [<] [<] (^Tag #"""#) #" '"\"" "# ], todo "equality types", "case" :- [ testPrettyE [<] [<] (^CasePair One (^F "a" 0) (SN $ ^TYPE 1) (SN $ ^TYPE 0)) "case1 a return โ˜…ยน of { (_, _) โ‡’ โ˜…โฐ }" "case1 a return Type 1 of { (_, _) => Type 0 }", testPrettyT [<] [<] (^LamY "u" (E $ ^CaseEnum One (^F "u" 0) (SY [< "x"] $ ^Eq0 (^enum ["tt"]) (^BVT 0) (^Tag "tt")) (fromList [("tt", ^DLamN (^Tag "tt"))]))) "ฮป u โ‡’ case1 u return x โ‡’ x โ‰ก 'tt : {tt} of { 'tt โ‡’ ฮด _ โ‡’ 'tt }" """ fun u => case1 u return x => x == 'tt : {tt} of { 'tt => dfun _ => 'tt } """ ], "type-case" :- [ testPrettyE [<] [<] {label = "type-case โ„• โˆท โ˜…โฐ return โ˜…โฐ of { โ‹ฏ }"} (^TypeCase (^Ann (^Nat) (^TYPE 0)) (^TYPE 0) empty (^Nat)) "type-case โ„• โˆท โ˜…โฐ return โ˜…โฐ of { _ โ‡’ โ„• }" "type-case Nat :: Type 0 return Type 0 of { _ => Nat }" ], "annotations" :- [ testPrettyE [<] [<] (^Ann (^FT "a" 0) (^FT "A" 0)) "a โˆท A" "a :: A", testPrettyE [<] [<] (^Ann (^FT "a" 0) (E $ ^Ann (^FT "A" 0) (^FT "๐€" 0))) "a โˆท A โˆท ๐€" "a :: A :: ๐€", testPrettyE [<] [<] (^Ann (E $ ^Ann (^FT "ฮฑ" 0) (^FT "a" 0)) (^FT "A" 0)) "(ฮฑ โˆท a) โˆท A" "(ฮฑ :: a) :: A", testPrettyE [<] [<] (^Ann (^LamY "x" (^BVT 0)) (^Arr One (^FT "A" 0) (^FT "A" 0))) "(ฮป x โ‡’ x) โˆท 1.A โ†’ A" "(fun x => x) :: 1.A -> A", testPrettyE [<] [<] (^Ann (^Arr One (^FT "A" 0) (^FT "A" 0)) (^TYPE 7)) "(1.A โ†’ A) โˆท โ˜…โท" "(1.A -> A) :: Type 7" ] ]