Skip to content

Commit 9328565

Browse files
committed
chore: add stringifier test cases
1 parent fc7d16a commit 9328565

20 files changed

+1160
-505
lines changed

.vscode/settings.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"Parser.ts": "i18n",
44
"Tokenizer.ts": "i18n"
55
},
6-
"material-icon-theme.folders.associations": {}
6+
"material-icon-theme.folders.associations": {},
7+
"editor.insertSpaces": false,
8+
"editor.detectIndentation": false,
9+
"editor.trimAutoWhitespace": false
710
}

packages/language/src/__tests__/capitalized-syntax.test.ts

+23-27
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,33 @@ import parser, { defineForm } from "../";
22

33
describe("Used with Capitalized syntax", () => {
44
it("should parse the form syntax correctly", () => {
5-
const syntax = `Formkl {
5+
const result = parser.parse(`Formkl {
66
Includes {
77
Text;
88
"Another" Text;
99
}
10-
}`
10+
}`);
1111

12-
const expected = defineForm({
13-
model: "base",
14-
sections: [
15-
{
16-
fields: [
17-
{
18-
type: "text",
19-
label: "Text",
20-
key: "text",
21-
},
22-
{
23-
type: "text",
24-
label: "Another",
25-
key: "another",
26-
},
27-
],
28-
},
29-
],
30-
})
31-
32-
console.log(parser.stringfify(expected))
33-
34-
const result = parser.parse(syntax);
35-
36-
expect(result).toStrictEqual(expected);
12+
expect(result).toStrictEqual(
13+
defineForm({
14+
model: "base",
15+
sections: [
16+
{
17+
fields: [
18+
{
19+
type: "text",
20+
label: "Text",
21+
key: "text",
22+
},
23+
{
24+
type: "text",
25+
label: "Another",
26+
key: "another",
27+
},
28+
],
29+
},
30+
],
31+
}),
32+
);
3733
});
3834
});

packages/language/src/__tests__/field-multiple-responses.test.ts

+82-47
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@ describe("Field with multiple responses support", () => {
88
}
99
}`);
1010

11-
expect(result).toStrictEqual(defineForm({
12-
model: "base",
13-
sections: [
14-
{
15-
fields: [
16-
{
17-
type: "text",
18-
label: "Text",
19-
key: "text",
20-
multiple: true,
21-
},
22-
],
23-
},
24-
],
25-
}));
11+
expect(result).toStrictEqual(
12+
defineForm({
13+
model: "base",
14+
sections: [
15+
{
16+
fields: [
17+
{
18+
type: "text",
19+
label: "Text",
20+
key: "text",
21+
multiple: true,
22+
},
23+
],
24+
},
25+
],
26+
}),
27+
);
2628
});
2729

2830
it("should parse the form syntax correctly with multiple required fields", () => {
@@ -32,22 +34,24 @@ describe("Field with multiple responses support", () => {
3234
}
3335
}`);
3436

35-
expect(result).toStrictEqual(defineForm({
36-
model: "base",
37-
sections: [
38-
{
39-
fields: [
40-
{
41-
type: "text",
42-
label: "Text",
43-
key: "text",
44-
required: true,
45-
multiple: true,
46-
},
47-
],
48-
},
49-
],
50-
}));
37+
expect(result).toStrictEqual(
38+
defineForm({
39+
model: "base",
40+
sections: [
41+
{
42+
fields: [
43+
{
44+
type: "text",
45+
label: "Text",
46+
key: "text",
47+
required: true,
48+
multiple: true,
49+
},
50+
],
51+
},
52+
],
53+
}),
54+
);
5155
});
5256

5357
it("should parse the form syntax correctly with multiple required fields", () => {
@@ -57,21 +61,52 @@ describe("Field with multiple responses support", () => {
5761
}
5862
}`);
5963

60-
expect(result).toStrictEqual(defineForm({
61-
model: "base",
62-
sections: [
63-
{
64-
fields: [
65-
{
66-
type: "text",
67-
label: "Text",
68-
key: "text",
69-
required: true,
70-
multiple: true,
71-
},
72-
],
73-
},
74-
],
75-
}));
64+
expect(result).toStrictEqual(
65+
defineForm({
66+
model: "base",
67+
sections: [
68+
{
69+
fields: [
70+
{
71+
type: "text",
72+
label: "Text",
73+
key: "text",
74+
required: true,
75+
multiple: true,
76+
},
77+
],
78+
},
79+
],
80+
}),
81+
);
82+
});
83+
84+
it("should stringify the formkl object correctly", () => {
85+
const result = parser.stringify(
86+
defineForm({
87+
model: "base",
88+
sections: [
89+
{
90+
fields: [
91+
{
92+
type: "text",
93+
label: "Text",
94+
key: "text",
95+
required: true,
96+
multiple: true,
97+
},
98+
],
99+
},
100+
],
101+
}),
102+
);
103+
104+
expect(result).toBe(
105+
`formkl {
106+
includes {
107+
require multiple text;
108+
}
109+
}`,
110+
);
76111
});
77112
});

packages/language/src/__tests__/field-required.test.ts

+54-20
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,59 @@ describe("Required field", () => {
99
}
1010
}`);
1111

12-
expect(result).toStrictEqual(defineForm({
13-
model: "base",
14-
sections: [
15-
{
16-
fields: [
17-
{
18-
type: "text",
19-
label: "Text",
20-
key: "text",
21-
required: true,
22-
},
23-
{
24-
type: "text",
25-
label: "Not required",
26-
key: "not-required",
27-
},
28-
],
29-
},
30-
],
31-
}));
12+
expect(result).toStrictEqual(
13+
defineForm({
14+
model: "base",
15+
sections: [
16+
{
17+
fields: [
18+
{
19+
type: "text",
20+
label: "Text",
21+
key: "text",
22+
required: true,
23+
},
24+
{
25+
type: "text",
26+
label: "Not required",
27+
key: "not-required",
28+
},
29+
],
30+
},
31+
],
32+
}),
33+
);
34+
});
35+
36+
it("should stringify the form syntax correctly", () => {
37+
const result = parser.stringify(
38+
defineForm({
39+
model: "base",
40+
sections: [
41+
{
42+
fields: [
43+
{
44+
type: "text",
45+
label: "Text",
46+
key: "text",
47+
required: true,
48+
},
49+
{
50+
type: "text",
51+
label: "Not required",
52+
key: "not-required",
53+
},
54+
],
55+
},
56+
],
57+
}),
58+
);
59+
60+
expect(result).toBe(`formkl {
61+
includes {
62+
require text;
63+
"Not required" text;
64+
}
65+
}`);
3266
});
3367
});

0 commit comments

Comments
 (0)