FileName.hs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. {-# LANGUAGE CPP #-}
  2. {-# LANGUAGE TemplateHaskell #-}
  3. module Internal.Utils.FileName ( tests ) where
  4. import qualified Data.Text as Text
  5. import System.FilePath
  6. import Internal.Helpers
  7. import Agda.Utils.FileName
  8. ------------------------------------------------------------------------
  9. -- Helpers
  10. rootPath :: FilePath
  11. #ifdef mingw32_HOST_OS
  12. rootPath = joinDrive "C:" [pathSeparator]
  13. #else
  14. rootPath = [pathSeparator]
  15. #endif
  16. ------------------------------------------------------------------------
  17. -- Generators
  18. instance Arbitrary AbsolutePath where
  19. arbitrary = mk . take 3 . map (take 2) <$>
  20. listOf (listOf1 (elements "a1"))
  21. where mk ps = mkAbsolute (joinPath $ rootPath : ps)
  22. instance CoArbitrary AbsolutePath where
  23. coarbitrary (AbsolutePath t) = coarbitrary (Text.unpack t)
  24. ------------------------------------------------------------------------
  25. -- Properties
  26. -- | The paths have to be absolute, valid and normalised, without
  27. -- trailing path separators.
  28. prop_absolutePathInvariant :: AbsolutePath -> Bool
  29. prop_absolutePathInvariant x =
  30. isAbsolute f &&
  31. isValid f &&
  32. f == normalise f &&
  33. f == dropTrailingPathSeparator f
  34. where f = filePath x
  35. prop_mkAbsolute :: FilePath -> Property
  36. prop_mkAbsolute f =
  37. let path = rootPath ++ f
  38. in isValid path ==> prop_absolutePathInvariant $ mkAbsolute $ path
  39. ------------------------------------------------------------------------
  40. -- * All tests
  41. ------------------------------------------------------------------------
  42. -- Template Haskell hack to make the following $allProperties work
  43. -- under ghc-7.8.
  44. return [] -- KEEP!
  45. -- | All tests as collected by 'allProperties'.
  46. --
  47. -- Using 'allProperties' is convenient and superior to the manual
  48. -- enumeration of tests, since the name of the property is added
  49. -- automatically.
  50. tests :: TestTree
  51. tests = testProperties "Internal.Utils.FileName" $allProperties