@@ -19,6 +19,7 @@ import Dhall.Core
19
19
)
20
20
import qualified Dhall.Map as Map
21
21
import Dhall.Package
22
+ import Dhall.Pretty (CharacterSet (ASCII ))
22
23
import System.FilePath ((</>) )
23
24
import Test.Tasty
24
25
import Test.Tasty.HUnit
@@ -31,6 +32,7 @@ tests = testGroup "Package"
31
32
, packageEmptyDirectory
32
33
, packageSingleDirectory
33
34
, packageNested
35
+ , packageRecursive
34
36
, packageMissingFile
35
37
, packageFilesDifferentDirs
36
38
, packageIncompatibleFiles
@@ -43,7 +45,7 @@ packagePackageFile = testCase "package file" $ do
43
45
let package :: Expr Void Import
44
46
package = RecordLit Map. empty
45
47
46
- (output, expr) <- getPackagePathAndContent Nothing (" ./tests/package/package.dhall" :| [] )
48
+ (output, expr) <- getPackagePathAndContent ASCII Exact Nothing (" ./tests/package/package.dhall" :| [] )
47
49
assertEqual " path" path output
48
50
assertEqual " content" package expr
49
51
@@ -55,7 +57,7 @@ packageCustomPackageFile = testCase "custom package file" $ do
55
57
package = RecordLit $
56
58
Map. singleton " package" $ makeRecordField $ Embed packageDhall
57
59
58
- (output, expr) <- getPackagePathAndContent (Just " custom.dhall" ) (" ./tests/package/package.dhall" :| [] )
60
+ (output, expr) <- getPackagePathAndContent ASCII Exact (Just " custom.dhall" ) (" ./tests/package/package.dhall" :| [] )
59
61
assertEqual " path" path output
60
62
assertEqual " content" package expr
61
63
@@ -67,7 +69,7 @@ packageSingleFile = testCase "single file" $ do
67
69
package = RecordLit $
68
70
Map. singleton " test" $ makeRecordField $ Embed testDhall
69
71
70
- (output, expr) <- getPackagePathAndContent Nothing (" ./tests/package/dir/test.dhall" :| [] )
72
+ (output, expr) <- getPackagePathAndContent ASCII Exact Nothing (" ./tests/package/dir/test.dhall" :| [] )
71
73
assertEqual " path" path output
72
74
assertEqual " content" package expr
73
75
@@ -78,7 +80,7 @@ packageEmptyDirectory = testCase "empty directory" $ do
78
80
let package :: Expr Void Import
79
81
package = RecordLit Map. empty
80
82
81
- (output, expr) <- getPackagePathAndContent Nothing (" ./tests/package/empty" :| [] )
83
+ (output, expr) <- getPackagePathAndContent ASCII Exact Nothing (" ./tests/package/empty" :| [] )
82
84
assertEqual " path" path output
83
85
assertEqual " content" package expr
84
86
@@ -90,7 +92,7 @@ packageSingleDirectory = testCase "single directory" $ do
90
92
package = RecordLit $ Map. singleton " test" $
91
93
makeRecordField $ Embed testDhall
92
94
93
- (output, expr) <- getPackagePathAndContent Nothing (" ./tests/package/dir" :| [] )
95
+ (output, expr) <- getPackagePathAndContent ASCII Exact Nothing (" ./tests/package/dir" :| [] )
94
96
assertEqual " path" path output
95
97
assertEqual " content" package expr
96
98
@@ -108,18 +110,34 @@ packageNested = testCase "nested files" $ do
108
110
, (" test" , makeRecordField $ Embed testDhall)
109
111
]
110
112
111
- (output, expr) <- getPackagePathAndContent Nothing
113
+ (output, expr) <- getPackagePathAndContent ASCII Exact Nothing
112
114
( " ./tests/package/test.dhall" :|
113
115
[ " ./tests/package/dir/test.dhall"
114
116
, " ./tests/package/other/package.dhall"
115
117
])
116
118
assertEqual " path" path output
117
119
assertEqual " content" package expr
118
120
121
+ packageRecursive :: TestTree
122
+ packageRecursive = testCase " recursively create subpackages" $ do
123
+ let path = " ./tests/package/dir" </> " package.dhall"
124
+
125
+ let package :: Expr Void Import
126
+ package = RecordLit $ Map. fromList
127
+ [ (" subdirectory1" , makeRecordField $ Embed subdirectoryPackageDhall1)
128
+ , (" subdirectory2" , makeRecordField $ Embed subdirectoryPackageDhall2)
129
+ , (" test" , makeRecordField $ Embed testDhall)
130
+ ]
131
+
132
+ (output, expr) <- getPackagePathAndContent ASCII Recurse Nothing
133
+ ( " ./tests/package/dir" :| [] )
134
+ assertEqual " path" path output
135
+ assertEqual " content" package expr
136
+
119
137
packageMissingFile :: TestTree
120
138
packageMissingFile = testCase " missing file" $ do
121
139
let action :: IO (FilePath , Expr Void Import )
122
- action = getPackagePathAndContent Nothing (" ./tests/package/missing.dhall" :| [] )
140
+ action = getPackagePathAndContent ASCII Exact Nothing (" ./tests/package/missing.dhall" :| [] )
123
141
124
142
assertThrow action $ \ case
125
143
InvalidPath " ./tests/package/missing.dhall" -> True
@@ -128,7 +146,7 @@ packageMissingFile = testCase "missing file" $ do
128
146
packageFilesDifferentDirs :: TestTree
129
147
packageFilesDifferentDirs = testCase " files from different directories" $ do
130
148
let action :: IO (FilePath , Expr Void Import )
131
- action = getPackagePathAndContent Nothing (" ./tests/package/dir/test.dhall" :| [" ./tests/package/test/test.dhall" ])
149
+ action = getPackagePathAndContent ASCII Exact Nothing (" ./tests/package/dir/test.dhall" :| [" ./tests/package/test/test.dhall" ])
132
150
133
151
assertThrow action $ \ case
134
152
AmbiguousOutputDirectory " ./tests/package/dir" " ./tests/package/test" -> True
@@ -137,7 +155,7 @@ packageFilesDifferentDirs = testCase "files from different directories" $ do
137
155
packageIncompatibleFiles :: TestTree
138
156
packageIncompatibleFiles = testCase " files that are incompatible" $ do
139
157
let action :: IO (FilePath , Expr Void Import )
140
- action = getPackagePathAndContent Nothing (" ./tests/package/test.dhall" :| [" ./tests/package/test/test.dhall" ])
158
+ action = getPackagePathAndContent ASCII Exact Nothing (" ./tests/package/test.dhall" :| [" ./tests/package/test/test.dhall" ])
141
159
142
160
assertThrow action $ \ case
143
161
IncompatiblePaths xs -> xs == [ testDhall , testTestDhall ]
@@ -191,6 +209,28 @@ otherPackageDhall = Import
191
209
, importMode = Code
192
210
}
193
211
212
+ subdirectoryPackageDhall1 :: Import
213
+ subdirectoryPackageDhall1 = Import
214
+ { importHashed = ImportHashed
215
+ { hash = Nothing
216
+ , importType = Local Here $ File
217
+ { directory = Directory {components = [" subdirectory1" ]}
218
+ , file = " package.dhall" }
219
+ }
220
+ , importMode = Code
221
+ }
222
+
223
+ subdirectoryPackageDhall2 :: Import
224
+ subdirectoryPackageDhall2 = Import
225
+ { importHashed = ImportHashed
226
+ { hash = Nothing
227
+ , importType = Local Here $ File
228
+ { directory = Directory {components = [" subdirectory2" ]}
229
+ , file = " package.dhall" }
230
+ }
231
+ , importMode = Code
232
+ }
233
+
194
234
testTestDhall :: Import
195
235
testTestDhall = Import
196
236
{ importHashed = ImportHashed
0 commit comments