Skip to content

Commit 3616396

Browse files
committed
Purely rely on e2e tests for exercising the generator
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 72bc6cf commit 3616396

15 files changed

Lines changed: 293 additions & 1288 deletions

File tree

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ if(CODEGEN_TESTS)
7777
endif()
7878

7979
if(CODEGEN_GENERATOR)
80-
add_subdirectory(test/generator)
8180
add_subdirectory(test/e2e/typescript)
8281
endif()
8382

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export type SchemaSimpleEnum = "foo" | "bar" | "baz";
2+
3+
export type SchemaMixedEnum = "active" | 42 | true | null;
4+
5+
export type SchemaEnumWithObject = "simple" | {
6+
"type": "complex",
7+
"value": 123
8+
};
9+
10+
export type SchemaEnumWithArray = 1 | [ 1, 2, 3 ];
11+
12+
export type SchemaAdditionalProperties = never;
13+
14+
export interface Schema {
15+
"simpleEnum"?: SchemaSimpleEnum;
16+
"mixedEnum"?: SchemaMixedEnum;
17+
"enumWithObject"?: SchemaEnumWithObject;
18+
"enumWithArray"?: SchemaEnumWithArray;
19+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"defaultPrefix": "Schema"
3+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"type": "object",
4+
"properties": {
5+
"simpleEnum": {
6+
"enum": [ "foo", "bar", "baz" ]
7+
},
8+
"mixedEnum": {
9+
"enum": [ "active", 42, true, null ]
10+
},
11+
"enumWithObject": {
12+
"enum": [ "simple", { "type": "complex", "value": 123 } ]
13+
},
14+
"enumWithArray": {
15+
"enum": [ 1, [ 1, 2, 3 ] ]
16+
}
17+
},
18+
"additionalProperties": false
19+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import {
2+
Schema,
3+
SchemaSimpleEnum,
4+
SchemaMixedEnum,
5+
SchemaEnumWithObject,
6+
SchemaEnumWithArray
7+
} from "./expected";
8+
9+
10+
// Valid: simple string enum values
11+
const simple1: SchemaSimpleEnum = "foo";
12+
const simple2: SchemaSimpleEnum = "bar";
13+
const simple3: SchemaSimpleEnum = "baz";
14+
15+
// Invalid: wrong string for simple enum
16+
// @ts-expect-error - must be "foo" | "bar" | "baz"
17+
const simpleInvalid: SchemaSimpleEnum = "invalid";
18+
19+
// Valid: mixed enum values
20+
const mixed1: SchemaMixedEnum = "active";
21+
const mixed2: SchemaMixedEnum = 42;
22+
const mixed3: SchemaMixedEnum = true;
23+
const mixed4: SchemaMixedEnum = null;
24+
25+
// Invalid: wrong value for mixed enum
26+
// @ts-expect-error - must be "active" | 42 | true | null
27+
const mixedInvalid: SchemaMixedEnum = "inactive";
28+
29+
// Valid: enum with object value
30+
const withObj1: SchemaEnumWithObject = "simple";
31+
const withObj2: SchemaEnumWithObject = { type: "complex", value: 123 };
32+
33+
// Invalid: completely wrong type for enum with object
34+
// @ts-expect-error - must be "simple" or the exact object literal
35+
const withObjInvalid: SchemaEnumWithObject = "wrong";
36+
37+
// Valid: enum with array value
38+
const withArr1: SchemaEnumWithArray = 1;
39+
const withArr2: SchemaEnumWithArray = [ 1, 2, 3 ];
40+
41+
// Invalid: wrong array
42+
// @ts-expect-error - must be exactly [1, 2, 3]
43+
const withArrInvalid: SchemaEnumWithArray = [ 1, 2 ];
44+
45+
// Valid: full schema object
46+
const fullSchema: Schema = {
47+
simpleEnum: "foo",
48+
mixedEnum: 42,
49+
enumWithObject: { type: "complex", value: 123 },
50+
enumWithArray: [ 1, 2, 3 ]
51+
};
52+
53+
// Valid: partial schema
54+
const partialSchema: Schema = {
55+
simpleEnum: "bar"
56+
};
57+
58+
// Valid: empty schema (all optional)
59+
const emptySchema: Schema = {};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export type TreeNodeParent = TreeNode;
2+
3+
export type TreeNodeName = string;
4+
5+
export type TreeNodeChildrenItems = TreeNode;
6+
7+
export type TreeNodeChildren = TreeNodeChildrenItems[];
8+
9+
export type TreeNodeAdditionalProperties = never;
10+
11+
export interface TreeNode {
12+
"name": TreeNodeName;
13+
"children"?: TreeNodeChildren;
14+
"parent"?: TreeNodeParent;
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"defaultPrefix": "TreeNode"
3+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"type": "object",
4+
"required": [ "name" ],
5+
"properties": {
6+
"name": { "type": "string" },
7+
"children": {
8+
"type": "array",
9+
"items": { "$ref": "#" }
10+
},
11+
"parent": { "$ref": "#" }
12+
},
13+
"additionalProperties": false
14+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { TreeNode } from "./expected";
2+
3+
4+
// Valid: minimal node with just name
5+
const leaf: TreeNode = {
6+
name: "leaf"
7+
};
8+
9+
// Valid: node with children
10+
const parent: TreeNode = {
11+
name: "parent",
12+
children: [
13+
{ name: "child1" },
14+
{ name: "child2" }
15+
]
16+
};
17+
18+
// Valid: deeply nested structure
19+
const root: TreeNode = {
20+
name: "root",
21+
children: [
22+
{
23+
name: "branch1",
24+
children: [
25+
{ name: "leaf1" },
26+
{ name: "leaf2" }
27+
]
28+
},
29+
{
30+
name: "branch2",
31+
children: []
32+
}
33+
]
34+
};
35+
36+
// Valid: node with parent reference
37+
const childWithParent: TreeNode = {
38+
name: "child",
39+
parent: { name: "myParent" }
40+
};
41+
42+
// Valid: complex tree with parent references
43+
const complexTree: TreeNode = {
44+
name: "root",
45+
children: [
46+
{
47+
name: "child",
48+
parent: { name: "root" },
49+
children: [
50+
{ name: "grandchild" }
51+
]
52+
}
53+
]
54+
};
55+
56+
// Invalid: missing required name
57+
// @ts-expect-error - name is required
58+
const missingName: TreeNode = {
59+
children: []
60+
};
61+
62+
// Invalid: wrong type for name
63+
const wrongNameType: TreeNode = {
64+
// @ts-expect-error - name must be string
65+
name: 123
66+
};
67+
68+
// Invalid: children must be array of TreeNode
69+
const wrongChildrenType: TreeNode = {
70+
name: "node",
71+
// @ts-expect-error - children must be array of TreeNode
72+
children: "not an array"
73+
};
74+
75+
// Invalid: extra property (additionalProperties: false)
76+
const extraProperty: TreeNode = {
77+
name: "node",
78+
// @ts-expect-error - extra property not allowed
79+
extra: "not allowed"
80+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export type SchemaSayhello = string;
2+
3+
export type SchemaPathtofile = string;
4+
5+
export type SchemaMypropertyname = string;
6+
7+
export type SchemaLine1line2 = string;
8+
9+
export type SchemaCol1col2 = string;
10+
11+
export type SchemaClass = string;
12+
13+
export type Schema_123abc = string;
14+
15+
export type Schema$specialchars = string;
16+
17+
export type SchemaAdditionalProperties = never;
18+
19+
export interface Schema {
20+
"say \"hello\""?: SchemaSayhello;
21+
"path\\to\\file"?: SchemaPathtofile;
22+
"line1\nline2"?: SchemaLine1line2;
23+
"col1\tcol2"?: SchemaCol1col2;
24+
"$special@chars"?: Schema$specialchars;
25+
"my property name"?: SchemaMypropertyname;
26+
"123abc"?: Schema_123abc;
27+
"class"?: SchemaClass;
28+
}

0 commit comments

Comments
 (0)