yaml-test-suite icon indicating copy to clipboard operation
yaml-test-suite copied to clipboard

in.json should be converted to canonical format

Open perlpunk opened this issue 7 years ago • 3 comments

To be able to reliably compare JSON the in.json should all be converted to the default jq output. To ensure that also future additions have the correct format, we would need a script that automatically converts in-json in a tml file.

perlpunk avatar Jan 03 '18 19:01 perlpunk

As I mentioned in the #20 review, in-json was not meant to be a raw expected result string (that would be called out-json), but rather a loaded JSON input that would be compared either in memory or by a reserialization into any mature/trusted format.

That said, I support the change if it helps people use the data in other useful ways and does not break any existing testing.

ingydotnet avatar Jan 04 '18 00:01 ingydotnet

  • Why should this change break any existing testing? I will let the test matrix run before merging it to master
  • if we generate in.json half-automatically, a canonical format will guarantee that we only get diffs for real changes

perlpunk avatar Jan 04 '18 11:01 perlpunk

With the changes brought in by PR #20, the in.json files representing streams with multiple documents can no longer be easily parsed in a JS environment. In fact jq might be one of the only tools that can parse their format without complaint.

As is, the files are pretty close to line-delimited JSON, for which tools do exist. Therefore, would it be possible to add a step that would use something like jq -c in their generation?

I encountered this problem while updating the tests of my JS YAML library, which can in fact read the in.json format, but complains about it:

import fs from 'fs'
import YAML from 'yaml'
const src = fs.readFileSync('./U9NS/in.json', 'utf8')
const doc = YAML.parseDocuments(src)[0]

doc.errors
// [ [YAMLSyntaxError: Document is not valid YAML (bad indentation?)] ]

doc.contents[0].toJSON()
// { time: '20:03:20',
//   player: 'Sammy Sosa',
//   action: 'strike (miss)' }

doc.contents[1].toJSON()
// { time: '20:03:47',
//   player: 'Sammy Sosa',
//   action: 'grand slam' }

eemeli avatar Jul 01 '18 13:07 eemeli