test pass

This commit is contained in:
wangkechun 2024-01-29 17:28:50 +08:00
parent 5c4f8e5d87
commit 7f2355b782
5 changed files with 78 additions and 11 deletions

View file

@ -59,6 +59,7 @@ import "./tests/Jump.mjs";
import "./tests/JSONBeautify.mjs";
import "./tests/JSONMinify.mjs";
import "./tests/JSONtoCSV.mjs";
import "./tests/JSONToGoStruct.mjs";
import "./tests/JWTDecode.mjs";
import "./tests/JWTSign.mjs";
import "./tests/JWTVerify.mjs";

View file

@ -0,0 +1,62 @@
/**
* JSON to Go Struct tests.
*
* @author wangkechun [hi@hi-hi.cn]
*
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "JSON to Go Struct: simple",
input: JSON.stringify({ a: "1", b: "2", c: "3" }),
expectedOutput: `type AutoGenerated struct {
A string \`json:"a"\`
B string \`json:"b"\`
C string \`json:"c"\`
}`.replaceAll(" ", "\t"),
recipeConfig: [
{
op: "JSON to Go Struct",
args: ["AutoGenerated", true, false],
},
],
},
{
name: "JSON to Go Struct: flatten",
input: JSON.stringify({ a: "1", b: "2", c: { d: "e" } }),
expectedOutput: `type AutoGenerated struct {
A string \`json:"a"\`
B string \`json:"b"\`
C C \`json:"c"\`
}
type C struct {
D string \`json:"d"\`
}`.replaceAll(" ", "\t"),
recipeConfig: [
{
op: "JSON to Go Struct",
args: ["AutoGenerated", true, false],
},
],
},
{
name: "JSON to Go Struct: nest",
input: JSON.stringify({ a: "1", b: "2", c: { d: "e" } }),
expectedOutput: `type AutoGenerated struct {
A string \`json:"a"\`
B string \`json:"b"\`
C struct {
D string \`json:"d"\`
} \`json:"c"\`
}`.replaceAll(" ", "\t"),
recipeConfig: [
{
op: "JSON to Go Struct",
args: ["AutoGenerated", false, false],
},
],
},
]);