kowainik/tomland

Fix roundtrip test for Key

chshersh opened this issue · 0 comments

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 🙂

The parsing function is implemented here:

textToKey :: Text -> Either TomlBiMapError Key

(but it can be moved to a different module)