kowainik / tomland

🏝 Bidirectional TOML serialization
https://kowainik.github.io/posts/2019-01-14-tomland
Mozilla Public License 2.0
120 stars 39 forks source link

Fix roundtrip test for Key #318

Closed chshersh closed 4 years ago

chshersh commented 4 years ago

The error message:

  1) Toml.Type tests, TOML Key, Key printing: fromString . prettyKey ≡ id
         ✗ <interactive> failed at test/Test/Toml/Type/Key.hs:25:5
           after 58 tests and 16 shrinks.

              ┏━━ test/Test/Toml/Type/Key.hs ━━━
           22 ┃ keyRoundtripSpec :: SpecWith (Arg Expectation)
           23 ┃ keyRoundtripSpec = it "Key printing: fromString . prettyKey ≡ id" $ hedgehog $ do
           24 ┃     key <- forAll genKey
              ┃     │ "\".\"" :| []
           25 ┃     tripping key Printer.prettyKey (Just . fromString . Text.unpack)
              ┃     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
              ┃     │ ━━━ Intermediate ━━━
              ┃     │ "\".\""
              ┃     │ ━━━ - Original) (+ Roundtrip ━━━
              ┃     │ - Just ("\".\"" :| [])
              ┃     │ + Just ("\"" :| [ "\"" ])

           This failure can be reproduced by running:
           > recheck (Size 57) (Seed 17425816728057331764 12418219576093727649) <property>

There's nothing wrong with how we print or parse Keys. The test simply uses the fromString function which doesn't always work (and this behaviour is documented). We need to use a proper parsing function in tests. We can even add this case as a separate unit test :slightly_smiling_face:

The parsing function is implemented here:

https://github.com/kowainik/tomland/blob/1356f6b46e13bcd1de42eedd6aed9c9f804b0fb2/src/Toml/Codec/BiMap/Conversion.hs#L592

(but it can be moved to a different module)