Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 1d94634

Browse files
committed
Generate User names.
1 parent 25f6f96 commit 1d94634

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

semantic-core/test/Generators.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ import Data.Term
2323
-- The 'prune' call here ensures that we don't spend all our time just generating
2424
-- fresh names for variables, since the length of variable names is not an
2525
-- interesting property as they parse regardless.
26-
name :: MonadGen m => m (Named Name)
27-
name = Gen.prune ((Named . Ignored <*> User) <$> names) where
26+
name :: MonadGen m => m (Named User)
27+
name = Gen.prune ((Named . Ignored <*> id) <$> names) where
2828
names = Gen.text (Range.linear 1 10) Gen.lower
2929

30-
boolean :: MonadGen m => m (Term Core Name)
30+
boolean :: MonadGen m => m (Term Core User)
3131
boolean = bool <$> Gen.bool
3232

33-
variable :: MonadGen m => m (Term Core Name)
33+
variable :: MonadGen m => m (Term Core User)
3434
variable = pure . namedValue <$> name
3535

36-
ifthenelse :: MonadGen m => m (Term Core Name) -> m (Term Core Name)
36+
ifthenelse :: MonadGen m => m (Term Core User) -> m (Term Core User)
3737
ifthenelse bod = Gen.subterm3 boolean bod bod if'
3838

39-
apply :: MonadGen m => m (Term Core Name) -> m (Term Core Name)
39+
apply :: MonadGen m => m (Term Core User) -> m (Term Core User)
4040
apply gen = go where
4141
go = Gen.recursive
4242
Gen.choice
@@ -45,13 +45,13 @@ apply gen = go where
4545
, Gen.subtermM go (\x -> lam <$> name <*> pure x)
4646
]
4747

48-
lambda :: MonadGen m => m (Term Core Name) -> m (Term Core Name)
48+
lambda :: MonadGen m => m (Term Core User) -> m (Term Core User)
4949
lambda bod = do
5050
arg <- name
5151
Gen.subterm bod (lam arg)
5252

53-
atoms :: MonadGen m => [m (Term Core Name)]
53+
atoms :: MonadGen m => [m (Term Core User)]
5454
atoms = [boolean, variable, pure unit, pure frame]
5555

56-
literal :: MonadGen m => m (Term Core Name)
56+
literal :: MonadGen m => m (Term Core User)
5757
literal = Gen.recursive Gen.choice atoms [lambda literal]

semantic-core/test/Spec.hs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{-# LANGUAGE OverloadedStrings #-}
2-
{-# OPTIONS_GHC -fno-warn-orphans #-}
3-
42
module Main (main) where
53

64
import Data.String
@@ -22,19 +20,17 @@ import Data.Term
2220

2321
-- * Helpers
2422

25-
true, false :: Term Core Name
26-
true = Bool True
27-
false = Bool False
28-
29-
instance IsString Name where fromString = User . fromString
23+
true, false :: Term Core User
24+
true = bool True
25+
false = bool False
3026

3127
parseEither :: Trifecta.Parser a -> String -> Either String a
3228
parseEither p = Trifecta.foldResult (Left . show . Trifecta._errDoc) Right . Trifecta.parseString (p <* Trifecta.eof) mempty
3329

3430
-- * Parser roundtripping properties. Note that parsing and prettyprinting is generally
3531
-- not a roundtrip, because the parser inserts 'Ann' nodes itself.
3632

37-
prop_roundtrips :: Gen (Term Core Name) -> Property
33+
prop_roundtrips :: Gen (Term Core User) -> Property
3834
prop_roundtrips gen = property $ do
3935
input <- forAll gen
4036
tripping input showCore (parseEither (Parse.core <* Trifecta.eof))
@@ -49,7 +45,7 @@ parserProps = testGroup "Parsing: roundtripping"
4945

5046
-- * Parser specs
5147

52-
parsesInto :: String -> Term Core Name -> Assertion
48+
parsesInto :: String -> Term Core User -> Assertion
5349
parsesInto str res = case parseEither Parse.core str of
5450
Right x -> x @?= res
5551
Left m -> assertFailure m
@@ -59,35 +55,35 @@ assert_booleans_parse = do
5955
parseEither Parse.core "#true" @?= Right true
6056
parseEither Parse.core "#false" @?= Right false
6157

62-
a, f, g, h :: Term Core Name
63-
(a, f, g, h) = (Var "a", Var "f", Var "g", Var "h")
58+
a, f, g, h :: Term Core User
59+
(a, f, g, h) = (pure "a", pure "f", pure "g", pure "h")
6460

6561
assert_ifthen_parse :: Assertion
66-
assert_ifthen_parse = "if #true then #true else #false" `parsesInto` (If true true false)
62+
assert_ifthen_parse = "if #true then #true else #false" `parsesInto` (if' true true false)
6763

6864
assert_application_parse :: Assertion
69-
assert_application_parse ="f g" `parsesInto` (f :$ g)
65+
assert_application_parse = "f g" `parsesInto` (f $$ g)
7066

7167
assert_application_left_associative :: Assertion
72-
assert_application_left_associative = "f g h" `parsesInto` (f :$ g :$ h)
68+
assert_application_left_associative = "f g h" `parsesInto` (f $$ g $$ h)
7369

7470
assert_push_left_associative :: Assertion
75-
assert_push_left_associative = "f.g.h" `parsesInto` (f :. g :. h)
71+
assert_push_left_associative = "f.g.h" `parsesInto` (f ... g ... h)
7672

7773
assert_ascii_lambda_parse :: Assertion
78-
assert_ascii_lambda_parse = "\\a -> a" `parsesInto` Lam "a" a
74+
assert_ascii_lambda_parse = "\\a -> a" `parsesInto` lam (named' "a") a
7975

8076
assert_unicode_lambda_parse :: Assertion
81-
assert_unicode_lambda_parse = "λa → a" `parsesInto` Lam "a" a
77+
assert_unicode_lambda_parse = "λa → a" `parsesInto` lam (named' "a") a
8278

8379
assert_quoted_name_parse :: Assertion
84-
assert_quoted_name_parse = "#{(NilClass)}" `parsesInto` Var (User "(NilClass)")
80+
assert_quoted_name_parse = "#{(NilClass)}" `parsesInto` pure "(NilClass)"
8581

8682
assert_let_dot_precedence :: Assertion
87-
assert_let_dot_precedence = "let a = f.g.h" `parsesInto` (Let "a" := (f :. g :. h))
83+
assert_let_dot_precedence = "let a = f.g.h" `parsesInto` (let' "a" .= (f ... g ... h))
8884

8985
assert_let_in_push_precedence :: Assertion
90-
assert_let_in_push_precedence = "f.let g = h" `parsesInto` (f :. (Let "g" := h))
86+
assert_let_in_push_precedence = "f.let g = h" `parsesInto` (f ... (let' "g" .= h))
9187

9288
parserSpecs :: TestTree
9389
parserSpecs = testGroup "Parsing: simple specs"
@@ -103,8 +99,8 @@ parserSpecs = testGroup "Parsing: simple specs"
10399
, testCase "let in push" assert_let_in_push_precedence
104100
]
105101

106-
assert_roundtrips :: File (Term Core Name) -> Assertion
107-
assert_roundtrips (File _ core) = parseEither Parse.core (showCore core) @?= Right (stripAnnotations core)
102+
assert_roundtrips :: File (Term Core User) -> Assertion
103+
assert_roundtrips (File _ core) = parseEither Parse.core (showCore core) @?= Right core
108104

109105
parserExamples :: TestTree
110106
parserExamples = testGroup "Parsing: Eval.hs examples"

0 commit comments

Comments
 (0)