mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-25 09:16:17 -04:00
CC-1523: YAML-JSON conversion
This commit is contained in:
parent
1bc88728f0
commit
c8e306d4f4
7 changed files with 202 additions and 6 deletions
36
tests/operations/tests/JSONtoYAML.mjs
Normal file
36
tests/operations/tests/JSONtoYAML.mjs
Normal 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: []
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
37
tests/operations/tests/YAMLtoJSON.mjs
Normal file
37
tests/operations/tests/YAMLtoJSON.mjs
Normal 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]
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
Loading…
Add table
Add a link
Reference in a new issue