@@ -30,27 +30,52 @@ testExtraIncludesForFile = TestCase (
30
30
31
31
ch <- liftIO newTChanIO
32
32
33
- extraOpening1 <- extraIncludesForFile (defaultOpts tmpdir) ch accountInclude [" opening.journal" ] []
33
+ extraOpening1 <- extraIncludesForFile (defaultOpts tmpdir) ch accountInclude [" opening.journal" ] [] []
34
34
liftIO $ assertEqual " The opening journal should not be included when it is not on disk" expectedEmpty extraOpening1
35
35
36
- extraClosing1 <- extraIncludesForFile (defaultOpts tmpdir) ch accountInclude [" closing.journal" ] []
36
+ extraClosing1 <- extraIncludesForFile (defaultOpts tmpdir) ch accountInclude [" closing.journal" ] [] []
37
37
liftIO $ assertEqual " The closing journal should not be included when it is not on disk" expectedEmpty extraClosing1
38
38
39
39
touchAll [opening, closing]
40
40
41
- extraOpening2 <- extraIncludesForFile (defaultOpts tmpdir) ch accountInclude [" opening.journal" ] []
41
+ extraOpening2 <- extraIncludesForFile (defaultOpts tmpdir) ch accountInclude [" opening.journal" ] [] []
42
42
liftIO $ assertEqual " The opening journal should be included when it is on disk" [(accountInclude, [opening])] extraOpening2
43
43
44
- extraClosing2 <- extraIncludesForFile (defaultOpts tmpdir) ch accountInclude [" closing.journal" ] []
44
+ extraClosing2 <- extraIncludesForFile (defaultOpts tmpdir) ch accountInclude [" closing.journal" ] [] []
45
45
liftIO $ assertEqual " The closing journal should be included when it is on disk" [(accountInclude, [closing])] extraClosing2
46
46
))
47
47
48
+ testExtraIncludesPrices :: Test
49
+ testExtraIncludesPrices = TestCase (
50
+ sh (
51
+ do
52
+ tmpdir <- using (mktempdir " ." " hlflow" )
53
+ let importedJournals = map (tmpdir </> ) journalFiles :: [FilePath ]
54
+ touchAll $ importedJournals
55
+
56
+ let priceFile = " prices" </> " 2020" </> " prices.journal"
57
+
58
+ let includeFile = tmpdir </> " import" </> " 2020-include.journal"
59
+ let expectedEmpty = [(includeFile, [] )]
60
+
61
+ ch <- liftIO newTChanIO
62
+
63
+ price1 <- extraIncludesForFile (defaultOpts tmpdir) ch includeFile [] [] [" prices.journal" ]
64
+ liftIO $ assertEqual " The price file should not be included when it is not on disk" expectedEmpty price1
65
+
66
+ touchAll [tmpdir </> priceFile]
67
+ let expectedPricePath = tmpdir </> " import" </> " .." </> priceFile
68
+
69
+ price2 <- extraIncludesForFile (defaultOpts tmpdir) ch includeFile [] [] [" prices.journal" ]
70
+ liftIO $ assertEqual " The price file should be included when it is on disk" [(includeFile, [expectedPricePath])] price2
71
+ ))
72
+
48
73
testIncludesPrePost :: Test
49
74
testIncludesPrePost = TestCase (
50
75
sh (
51
76
do
52
77
tmpdir <- using (mktempdir " ." " hlflow" )
53
- let ownerDir = tmpdir </> " import/ john"
78
+ let ownerDir = tmpdir </> " import" </> " john"
54
79
let includeFile = ownerDir </> " 2019-include.journal"
55
80
let pre = ownerDir </> " _manual_" </> " 2019" </> " pre-import.journal"
56
81
let post = ownerDir </> " _manual_" </> " 2019" </> " post-import.journal"
@@ -91,7 +116,32 @@ testIncludesOpeningClosing = TestCase (
91
116
<> " !include 3-journal/2019/2019-01-30.journal\n "
92
117
<> " !include 2019-closing.journal\n "
93
118
let expectedMap = Map. singleton includeFile expectedText
94
- liftIO $ assertEqual " All pre/post files on disk should be included" expectedMap fileMap
119
+ liftIO $ assertEqual " All opening/closing files on disk should be included" expectedMap fileMap
120
+ ))
121
+
122
+ testIncludesPrices :: Test
123
+ testIncludesPrices = TestCase (
124
+ sh (
125
+ do
126
+ tmpdir <- using (mktempdir " ." " hlflow" )
127
+ let importDir = tmpdir </> " import"
128
+ let includeFile = importDir </> " 2020-include.journal"
129
+ let prices = tmpdir </> " prices" </> " 2020" </> " prices.journal"
130
+ let pre = importDir </> " _manual_" </> " 2020" </> " pre-import.journal"
131
+ let post = importDir </> " _manual_" </> " 2020" </> " post-import.journal"
132
+ touchAll [prices, pre, post]
133
+
134
+ let includeMap = Map. singleton includeFile [importDir </> " john" </> " 2020-include.journal" ]
135
+
136
+ ch <- liftIO newTChanIO
137
+ fileMap <- toIncludeFiles (defaultOpts tmpdir) ch includeMap
138
+ let expectedText = includePreamble <> " \n "
139
+ <> " !include _manual_/2020/pre-import.journal\n "
140
+ <> " !include john/2020-include.journal\n "
141
+ <> " !include ../prices/2020/prices.journal\n "
142
+ <> " !include _manual_/2020/post-import.journal\n "
143
+ let expectedMap = Map. singleton includeFile expectedText
144
+ liftIO $ assertEqual " The price file should be included together with any pre/post files" expectedMap fileMap
95
145
))
96
146
97
147
testWriteIncludeFiles :: Test
@@ -174,4 +224,4 @@ testWriteIncludeFiles = TestCase (
174
224
)
175
225
176
226
tests :: Test
177
- tests = TestList [testExtraIncludesForFile, testIncludesPrePost, testIncludesOpeningClosing, testWriteIncludeFiles]
227
+ tests = TestList [testExtraIncludesForFile, testExtraIncludesPrices, testIncludesPrePost, testIncludesOpeningClosing, testIncludesPrices , testWriteIncludeFiles]
0 commit comments