Name.hs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. module Internal.Syntax.Concrete.Name () where
  2. import Agda.Syntax.Concrete.Name
  3. import Agda.Utils.Function ( applyWhen )
  4. import Agda.Utils.List1 ( (<|) )
  5. import qualified Agda.Utils.List1 as List1
  6. import Internal.Helpers
  7. import Internal.Syntax.Common ()
  8. import Internal.Syntax.Position ()
  9. import Test.QuickCheck
  10. ------------------------------------------------------------------------
  11. -- * QuickCheck instances
  12. ------------------------------------------------------------------------
  13. instance Arbitrary TopLevelModuleName where
  14. arbitrary = TopLevelModuleName <$> arbitrary <*> list1Of (listOf1 $ elements "AB")
  15. instance CoArbitrary TopLevelModuleName where
  16. coarbitrary (TopLevelModuleName _ m) = coarbitrary m
  17. instance Arbitrary Name where
  18. arbitrary = oneof
  19. [ Name <$> arbitrary <*> pure InScope <*> parts
  20. , NoName <$> arbitrary <*> arbitrary
  21. ]
  22. where
  23. parts = do
  24. parts <- list1Of $ elements ["x", "y", "z"]
  25. startWithHole <- arbitrary
  26. endWithHole <- arbitrary
  27. return $
  28. applyWhen startWithHole (Hole <|) $
  29. applyWhen endWithHole (`List1.appendList` [Hole]) $
  30. List1.intersperse Hole $ fmap Id parts
  31. instance CoArbitrary NamePart
  32. instance CoArbitrary Name where
  33. coarbitrary (Name _ _ ns) = variant 0 . coarbitrary ns
  34. coarbitrary (NoName _ i) = variant 1 . coarbitrary i