Skip to content

Commit 5fcf5ad

Browse files
committed
add more completion tests
1 parent 48b8120 commit 5fcf5ad

File tree

2 files changed

+167
-0
lines changed

2 files changed

+167
-0
lines changed

src/__tests__/__fixtures__/schemas.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,43 @@ export const testSchema2 = {
3535
oneOfEg2: {
3636
oneOf: [{ type: "string" }, { type: "array" }],
3737
},
38+
oneOfObject: {
39+
oneOf: [
40+
{ $ref: "#/definitions/fancyObject" },
41+
{ $ref: "#/definitions/fancyObject2" },
42+
],
43+
},
44+
enum1: {
45+
description: "an example enum with default bar",
46+
enum: ["foo", "bar"],
47+
default: "bar",
48+
},
49+
enum2: {
50+
description: "an example enum without default",
51+
enum: ["foo", "bar"],
52+
},
53+
booleanWithDefault: {
54+
description: "an example boolean with default",
55+
default: true,
56+
type: "boolean",
57+
},
3858
},
3959
required: ["foo", "object.foo"],
4060
additionalProperties: false,
61+
definitions: {
62+
fancyObject: {
63+
type: "object",
64+
properties: {
65+
foo: { type: "string" },
66+
bar: { type: "number" },
67+
},
68+
},
69+
fancyObject2: {
70+
type: "object",
71+
properties: {
72+
apple: { type: "string" },
73+
banana: { type: "number" },
74+
},
75+
},
76+
},
4177
} as JSONSchema7;

src/__tests__/json-completion.spec.ts

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,137 @@ describe("jsonCompletion", () => {
3030
info: "",
3131
template: '"oneOfEg2": ',
3232
},
33+
{
34+
detail: "",
35+
info: "",
36+
label: "oneOfObject",
37+
template: '"oneOfObject": ',
38+
type: "property",
39+
},
40+
]);
41+
});
42+
it("should include defaults for enum when available", async () => {
43+
await expectCompletion('{ "en| }', [
44+
{
45+
label: "enum1",
46+
type: "property",
47+
detail: "",
48+
info: "an example enum with default bar",
49+
// TODO: should this not autocomplete to default "bar"?
50+
// template: '"enum1": "${bar}"',
51+
template: '"enum1": #{}',
52+
},
53+
{
54+
label: "enum2",
55+
type: "property",
56+
detail: "",
57+
info: "an example enum without default",
58+
template: '"enum2": #{}',
59+
},
60+
]);
61+
});
62+
it("should include value completions for enum", async () => {
63+
await expectCompletion('{ "enum1": "|" }', [
64+
{
65+
label: '"foo"',
66+
info: "an example enum with default bar",
67+
},
68+
{
69+
label: '"bar"',
70+
detail: "Default value",
71+
},
72+
]);
73+
});
74+
it("should include defaults for boolean when available", async () => {
75+
await expectCompletion('{ "booleanW| }', [
76+
{
77+
type: "property",
78+
detail: "boolean",
79+
info: "an example boolean with default",
80+
label: "booleanWithDefault",
81+
template: '"booleanWithDefault": ${true}',
82+
},
83+
]);
84+
});
85+
// TODO: should provide true/false completions
86+
it("should include value completions for boolean", async () => {
87+
await expectCompletion('{ "booleanWithDefault": | }', []);
88+
});
89+
it("should include insert text for objects", async () => {
90+
await expectCompletion('{ "ob| }', [
91+
{
92+
type: "property",
93+
detail: "object",
94+
info: "",
95+
label: "object",
96+
template: '"object": {#{}}',
97+
},
98+
]);
99+
});
100+
// this has regressed for json4 only for some reason
101+
it("should include insert text for nested object properties", async () => {
102+
await expectCompletion('{ "object": { "|" } }', [
103+
{
104+
detail: "string",
105+
info: "an elegant string",
106+
label: "foo",
107+
template: '"foo": "#{}"',
108+
type: "property",
109+
},
110+
]);
111+
});
112+
it("should include insert text for nested object properties with filter", async () => {
113+
await expectCompletion('{ "object": { "f|" } }', [
114+
{
115+
detail: "string",
116+
info: "an elegant string",
117+
label: "foo",
118+
template: '"foo": "#{}"',
119+
type: "property",
120+
},
121+
]);
122+
});
123+
it("should autocomplete for oneOf with nested definitions and filter", async () => {
124+
await expectCompletion('{ "oneOfObject": { "f|" } }', [
125+
{
126+
detail: "string",
127+
info: "",
128+
label: "foo",
129+
template: '"foo": "#{}"',
130+
type: "property",
131+
},
132+
]);
133+
});
134+
it("should autocomplete for oneOf with nested definitions", async () => {
135+
await expectCompletion('{ "oneOfObject": { "|" } }', [
136+
{
137+
detail: "string",
138+
info: "",
139+
label: "foo",
140+
template: '"foo": "#{}"',
141+
type: "property",
142+
},
143+
{
144+
detail: "number",
145+
info: "",
146+
label: "bar",
147+
template: '"bar": #{0}',
148+
type: "property",
149+
},
150+
{
151+
detail: "string",
152+
info: "",
153+
label: "apple",
154+
template: '"apple": "#{}"',
155+
type: "property",
156+
},
157+
{
158+
detail: "number",
159+
info: "",
160+
label: "banana",
161+
template: '"banana": #{0}',
162+
type: "property",
163+
},
33164
]);
34165
});
35166
});

0 commit comments

Comments
 (0)