@@ -13,6 +13,7 @@ import Data.Text (Text)
1313import Data.Text qualified as Text
1414import Data.Typeable (typeRep )
1515import KDL.Arrow qualified as KDL
16+ import KDL.TestUtils.AST (scrubFormat )
1617import KDL.TestUtils.Error (decodeErrorMsg )
1718import KDL.Types (
1819 Entry (.. ),
@@ -38,7 +39,7 @@ apiSpec = do
3839 it " decodes a node" $ do
3940 let config = " foo 1.0"
4041 decoder = KDL. document $ proc () -> do
41- KDL. node " foo" -< ()
42+ scrubFormat <$> KDL. node " foo" -< ()
4243 expected =
4344 Node
4445 { ann = Nothing
@@ -50,48 +51,48 @@ apiSpec = do
5051 , format = Nothing
5152 }
5253 ]
53- , children = Just NodeList {nodes = [] , format = Nothing }
54+ , children = Nothing
5455 , format = Nothing
5556 }
5657 KDL. decodeWith decoder config `shouldBe` Right expected
5758
5859 it " decodes multiple nodes" $ do
5960 let config = " foo; foo"
6061 decoder = KDL. document $ proc () -> do
61- KDL. many $ KDL. node " foo" -< ()
62+ fmap ( map scrubFormat) . KDL. many $ KDL. node " foo" -< ()
6263 expected = [fooNode, fooNode]
6364 fooNode =
6465 Node
6566 { ann = Nothing
6667 , name = Identifier {value = " foo" , format = Nothing }
6768 , entries = []
68- , children = Just NodeList {nodes = [] , format = Nothing }
69+ , children = Nothing
6970 , format = Nothing
7071 }
7172 KDL. decodeWith decoder config `shouldBe` Right expected
7273
7374 it " decodes nodes in any order" $ do
7475 let config = " foo; bar"
7576 decoder = KDL. document $ proc () -> do
76- bar <- KDL. node " bar" -< ()
77- foo <- KDL. node " foo" -< ()
77+ bar <- scrubFormat <$> KDL. node " bar" -< ()
78+ foo <- scrubFormat <$> KDL. node " foo" -< ()
7879 returnA -< (bar, foo)
7980 expected = (node " bar" , node " foo" )
8081 node name =
8182 Node
8283 { ann = Nothing
8384 , name = Identifier {value = name, format = Nothing }
8485 , entries = []
85- , children = Just NodeList {nodes = [] , format = Nothing }
86+ , children = Nothing
8687 , format = Nothing
8788 }
8889 KDL. decodeWith decoder config `shouldBe` Right expected
8990
9091 it " fails when not enough nodes" $ do
9192 let config = " foo"
9293 decoder = KDL. document $ proc () -> do
93- foo1 <- KDL. node @ Node " foo" -< ()
94- foo2 <- KDL. node @ Node " foo" -< ()
94+ foo1 <- scrubFormat <$> KDL. node @ Node " foo" -< ()
95+ foo2 <- scrubFormat <$> KDL. node @ Node " foo" -< ()
9596 returnA -< (foo1, foo2)
9697 KDL. decodeWith decoder config
9798 `shouldSatisfy` decodeErrorMsg
@@ -102,7 +103,7 @@ apiSpec = do
102103 -- Most behaviors tested with `node`
103104 describe " nodeWith" $ do
104105 it " decodes a node" $ do
105- let config = " foo 1.0 { hello \" world\" ; }"
106+ let config = " foo 1.0 { hello world; }"
106107 decodeFoo = proc () -> do
107108 arg <- KDL. arg @ Int -< ()
108109 child <- KDL. children $ KDL. argAt @ Text " hello" -< ()
@@ -164,7 +165,7 @@ apiSpec = do
164165 let config = " foo 1.0; foo 2.0; bar"
165166 decoder = KDL. document $ proc () -> do
166167 _ <- KDL. node @ Node " foo" -< ()
167- KDL. remainingNodes -< ()
168+ fmap ( map scrubFormat) <$> KDL. remainingNodes -< ()
168169 expected =
169170 Map. fromList
170171 [ (" foo" , [fooNode2])
@@ -181,15 +182,15 @@ apiSpec = do
181182 , format = Nothing
182183 }
183184 ]
184- , children = Just NodeList {nodes = [] , format = Nothing }
185+ , children = Nothing
185186 , format = Nothing
186187 }
187188 barNode =
188189 Node
189190 { ann = Nothing
190191 , name = Identifier {value = " bar" , format = Nothing }
191192 , entries = []
192- , children = Just NodeList {nodes = [] , format = Nothing }
193+ , children = Nothing
193194 , format = Nothing
194195 }
195196 KDL. decodeWith decoder config `shouldBe` Right expected
@@ -211,7 +212,7 @@ apiSpec = do
211212 KDL. decodeWith decoder config `shouldBe` Right expected
212213
213214 it " fails when node fails to parse" $ do
214- let config = " foo 1; bar 1; bar \" hello\" "
215+ let config = " foo 1; bar 1; bar hello"
215216 decodeNode = proc () -> do
216217 KDL. arg @ Int -< ()
217218 decoder = KDL. document $ proc () -> do
@@ -262,7 +263,7 @@ apiSpec = do
262263
263264 describe " argAt" $ do
264265 it " gets argument at a node" $ do
265- let config = " foo \" bar\" ; hello \" world\" "
266+ let config = " foo bar; hello world"
266267 decoder = KDL. document $ proc () -> do
267268 hello <- KDL. argAt @ Text " hello" -< ()
268269 foo <- KDL. argAt @ Text " foo" -< ()
@@ -363,7 +364,7 @@ apiSpec = do
363364 KDL. decodeWith decoder config `shouldBe` Right []
364365
365366 it " fails if any arg fails to parse" $ do
366- let config = " foo 1 \" asdf\" "
367+ let config = " foo 1 asdf"
367368 decoder = KDL. document $ proc () -> do
368369 KDL. argsAt @ Int " foo" -< ()
369370 KDL. decodeWith decoder config
@@ -456,7 +457,7 @@ apiSpec = do
456457 ]
457458
458459 it " fails if any child fails to parse" $ do
459- let config = " foo { - 1; - \" asdf\" ; }"
460+ let config = " foo { - 1; - asdf; }"
460461 decoder = KDL. document $ proc () -> do
461462 KDL. dashChildrenAt @ Int " foo" -< ()
462463 KDL. decodeWith decoder config
@@ -513,14 +514,17 @@ apiSpec = do
513514 it " gets dash nodes at a node" $ do
514515 let config = " foo { - { bar; }; - { baz; }; }"
515516 decoder = KDL. document $ proc () -> do
516- KDL. dashNodesAt " foo" -< ()
517+ map scrubFormat <$> KDL. dashNodesAt " foo" -< ()
517518 expected = [node " -" [node " bar" [] ], node " -" [node " baz" [] ]]
518519 node name children =
519520 Node
520521 { ann = Nothing
521522 , name = Identifier {value = name, format = Nothing }
522523 , entries = []
523- , children = Just NodeList {nodes = children, format = Nothing }
524+ , children =
525+ if null children
526+ then Nothing
527+ else Just NodeList {nodes = children, format = Nothing }
524528 , format = Nothing
525529 }
526530 KDL. decodeWith decoder config `shouldBe` Right expected
@@ -550,7 +554,7 @@ apiSpec = do
550554 -- Most behaviors tested with `dashNodesAt`
551555 describe " dashNodesAtWith" $ do
552556 it " gets dash nodes at a node" $ do
553- let config = " foo { - 1 { bar \" hello\" ; }; - 2 { bar \" world\" ; }; }"
557+ let config = " foo { - 1 { bar hello; }; - 2 { bar world; }; }"
554558 decodeChild = proc () -> do
555559 arg <- KDL. arg @ Int -< ()
556560 child <- KDL. children $ KDL. nodeWith " bar" $ KDL. arg @ Text -< ()
@@ -560,7 +564,7 @@ apiSpec = do
560564 KDL. decodeWith decoder config `shouldBe` Right [(1 , " hello" ), (2 , " world" )]
561565
562566 it " fails if any child fails to parse" $ do
563- let config = " foo { - { bar 1; }; - { bar \" test\" ; }; }"
567+ let config = " foo { - { bar 1; }; - { bar test; }; }"
564568 decoder = KDL. document $ proc () -> do
565569 KDL. dashNodesAtWith " foo" $ KDL. children $ KDL. argAt @ Int " bar" -< ()
566570 KDL. decodeWith decoder config
@@ -579,7 +583,7 @@ apiSpec = do
579583
580584 describe " arg" $ do
581585 it " decodes an argument" $ do
582- let config = " foo 1 \" bar\" "
586+ let config = " foo 1 bar"
583587 decoder = proc () -> do
584588 arg1 <- KDL. arg @ Int -< ()
585589 arg2 <- KDL. arg @ Text -< ()
@@ -603,7 +607,7 @@ apiSpec = do
603607 ]
604608
605609 it " fails if argument fails to parse" $ do
606- let config = " foo \" test\" "
610+ let config = " foo test"
607611 decoder = proc () -> do
608612 KDL. arg @ Int -< ()
609613 decodeNode " foo" decoder config
@@ -625,7 +629,7 @@ apiSpec = do
625629 -- Most behaviors tested with `arg`
626630 describe " argWith" $ do
627631 it " decodes an argument" $ do
628- let config = " foo \" bar\" "
632+ let config = " foo bar"
629633 decoder = proc () -> do
630634 KDL. argWith KDL. text -< ()
631635 decodeNode " foo" decoder config `shouldBe` Right " bar"
@@ -668,7 +672,7 @@ apiSpec = do
668672
669673 describe " prop" $ do
670674 it " decodes a prop" $ do
671- let config = " foo test1=1 test2=\" hello\" "
675+ let config = " foo test1=1 test2=hello"
672676 decoder = proc () -> do
673677 prop1 <- KDL. prop @ Text " test2" -< ()
674678 prop2 <- KDL. prop @ Int " test1" -< ()
@@ -842,7 +846,7 @@ apiSpec = do
842846 it " decodes children" $ do
843847 let config = " foo { bar test; }"
844848 decoder = proc () -> do
845- KDL. children $ KDL. node @ Node " bar" -< ()
849+ fmap scrubFormat . KDL. children $ KDL. node @ Node " bar" -< ()
846850 expected =
847851 Node
848852 { ann = Nothing
@@ -854,7 +858,7 @@ apiSpec = do
854858 , format = Nothing
855859 }
856860 ]
857- , children = Just NodeList {nodes = [] , format = Nothing }
861+ , children = Nothing
858862 , format = Nothing
859863 }
860864 decodeNode " foo" decoder config `shouldBe` Right expected
@@ -882,7 +886,7 @@ apiSpec = do
882886 it " decodes any value" $ do
883887 let config = " foo 1.0 asdf #true"
884888 decoder = KDL. document $ proc () -> do
885- KDL. argsAtWith " foo" KDL. any -< ()
889+ map scrubFormat <$> KDL. argsAtWith " foo" KDL. any -< ()
886890 val data_ =
887891 Value
888892 { ann = Nothing
0 commit comments