CC-1523: YAML-JSON conversion

This commit is contained in:
David Marshall 2023-04-19 18:59:37 -04:00
parent 1bc88728f0
commit c8e306d4f4
7 changed files with 202 additions and 6 deletions

View file

@ -0,0 +1,36 @@
/**
* JSON to YAML tests.
*
* @author mshwed [m@ttshwed.com]
*
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
const EXPECTED_YAML = "version: 1.0.0\ndependencies:\n yaml: ^1.10.0\npackage:\n exclude:\n - .idea/**\n - .gitignore\n";
TestRegister.addTests([
{
name: "JSON to YAML: no spacing",
input: JSON.stringify({"version":"1.0.0","dependencies":{"yaml":"^1.10.0"},"package":{"exclude":[".idea/**",".gitignore"]}}),
expectedOutput: EXPECTED_YAML,
recipeConfig: [
{
op: "JSON to YAML",
args: []
},
],
},
{
name: "JSON to YAML: with spacing",
input: JSON.stringify({"version":"1.0.0","dependencies":{"yaml":"^1.10.0"},"package":{"exclude":[".idea/**",".gitignore"]}}, null, 4),
expectedOutput: EXPECTED_YAML,
recipeConfig: [
{
op: "JSON to YAML",
args: []
},
],
}
]);

View file

@ -0,0 +1,37 @@
/**
* YAML to JSON tests.
*
* @author mshwed [m@ttshwed.com]
*
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
const EXPECTED_JSON_SINGLE = '{"version":"1.0.0","dependencies":{"yaml":"^1.10.0"},"package":{"exclude":[".idea/**",".gitignore"]}}';
const EXPECTED_JSON_SPACED_SINGLE = '{\n"version": "1.0.0",\n"dependencies": {\n "yaml": "^1.10.0"\n },\n"package": {\n "exclude": [\n ".idea/**",\n ".gitignore"\n ]\n }\n}';
TestRegister.addTests([
{
name: "YAML to JSON: simple",
input: "version: 1.0.0\ndependencies:\n yaml: ^1.10.0\npackage:\n exclude:\n - .idea/**\n - .gitignore\n",
expectedOutput: EXPECTED_JSON_SINGLE,
recipeConfig: [
{
op: "YAML to JSON",
args: [0]
},
],
},
{
name: "YAML to JSON: spacing",
input: "version: 1.0.0\ndependencies:\n yaml: ^1.10.0\npackage:\n exclude:\n - .idea/**\n - .gitignore\n",
expectedOutput: EXPECTED_JSON_SPACED_SINGLE,
recipeConfig: [
{
op: "YAML to JSON",
args: [2]
},
],
}
]);