-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add golden tests for pretty printer (#103)
* Add golden tests for pretty printer * Rework example TOML in tests using EDSL, export defaultOptions
- Loading branch information
Showing
9 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.golden -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
module Toml.PrefixTree | ||
( PrefixTree (..) | ||
, (<|) | ||
, singleT | ||
, insertT | ||
, lookupT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
-- | This module contains golden tests for @Toml.Printer@. | ||
|
||
module Test.Toml.Printer.Golden | ||
( test_prettyGolden | ||
) where | ||
|
||
import Test.Tasty (TestTree, testGroup) | ||
import Test.Tasty.Silver (goldenVsAction) | ||
import Toml (TOML) | ||
import Toml.Edsl ((=:), mkToml, table) | ||
import Toml.PrefixTree ((<|)) | ||
import Toml.Printer (PrintOptions (..), defaultOptions, prettyOptions) | ||
|
||
example :: TOML | ||
example = mkToml $ do | ||
"b" =: "bb" | ||
"a" =: "a" | ||
"d" =: "ddd" | ||
"c" =: "cccc" | ||
table ("qux" <| "doo") $ do | ||
"spam" =: "!" | ||
"egg" =: "?" | ||
table "foo" $ pure () | ||
table "doo" $ pure () | ||
table "baz" $ pure () | ||
|
||
noFormatting :: PrintOptions | ||
noFormatting = PrintOptions | ||
{ shouldSort = False | ||
, indent = 0 | ||
} | ||
|
||
test_prettyGolden :: TestTree | ||
test_prettyGolden = | ||
testGroup "Toml.Printer" | ||
[ test "pretty_default" defaultOptions | ||
, test "pretty_sorted_only" noFormatting{ shouldSort = True} | ||
, test "pretty_indented_only" noFormatting{ indent = 4 } | ||
, test "pretty_unformatted" noFormatting | ||
] | ||
where | ||
test name options = | ||
goldenVsAction name ("test/golden/" ++ name ++ ".golden") | ||
(pure $ prettyOptions options example) id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
a = "a" | ||
b = "bb" | ||
c = "cccc" | ||
d = "ddd" | ||
|
||
[baz] | ||
|
||
[doo] | ||
|
||
[foo] | ||
|
||
[qux.doo] | ||
egg = "?" | ||
spam = "!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
a = "a" | ||
c = "cccc" | ||
d = "ddd" | ||
b = "bb" | ||
|
||
[doo] | ||
|
||
[foo] | ||
|
||
[baz] | ||
|
||
[qux.doo] | ||
egg = "?" | ||
spam = "!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
a = "a" | ||
b = "bb" | ||
c = "cccc" | ||
d = "ddd" | ||
|
||
[baz] | ||
|
||
[doo] | ||
|
||
[foo] | ||
|
||
[qux.doo] | ||
egg = "?" | ||
spam = "!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
a = "a" | ||
c = "cccc" | ||
d = "ddd" | ||
b = "bb" | ||
|
||
[doo] | ||
|
||
[foo] | ||
|
||
[baz] | ||
|
||
[qux.doo] | ||
egg = "?" | ||
spam = "!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters