X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions src/test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,32 @@ suite('JSON Parser', () => {

assert.strictEqual(semanticErrors!.length, 1);

// Patterns may include Unicode character classes.
semanticErrors = jsonDoc.validate(textDoc, {
type: 'object',
properties: {
"one": {
type: 'string',
pattern: '^[\\p{Letter}]+$',
}
}
});

assert.strictEqual(semanticErrors!.length, 0);

semanticErrors = jsonDoc.validate(textDoc, {
type: 'object',
properties: {
"one": {
type: 'string',
pattern: '(?i)^[\\p{Letter}]+$',
}
}
});

assert.strictEqual(semanticErrors!.length, 0);


const schemaWithURI = {
type: 'object',
properties: {
Expand Down Expand Up @@ -1257,6 +1283,31 @@ suite('JSON Parser', () => {
const semanticErrors = jsonDoc.validate(textDoc, schema);
assert.strictEqual(semanticErrors!.length, 0);
}

// PatternProperties may include Unicode character classes.
schema = {
id: 'test://schemas/main',
patternProperties: {
'^letter\\p{Letter}$': true,
'(?i)^number\\p{Number}$': true,
},
additionalProperties: false,
};
{
const { textDoc, jsonDoc } = toDocument('{"letterZ": [], "NumBer2": [], "number3": []}');
const semanticErrors = jsonDoc.validate(textDoc, schema);
assert.strictEqual(semanticErrors!.length, 0);
}
{
const { textDoc, jsonDoc } = toDocument('{"other": []}');
const semanticErrors = jsonDoc.validate(textDoc, schema);
assert.strictEqual(semanticErrors!.length, 1);
}
{
const { textDoc, jsonDoc } = toDocument('{"letter9": [], "NumberZ": []}');
const semanticErrors = jsonDoc.validate(textDoc, schema);
assert.strictEqual(semanticErrors!.length, 2);
}
});

test('additionalProperties', function () {
Expand Down Expand Up @@ -2018,10 +2069,10 @@ suite('JSON Parser', () => {
assert.strictEqual(res[0].message, 'Comments are not permitted in JSON.');
assert.strictEqual(res[0].severity, DiagnosticSeverity.Error);

res = await ls.doValidation(textDoc, jsonDoc, { comments: 'ignore'});
res = await ls.doValidation(textDoc, jsonDoc, { comments: 'ignore' });
assert.strictEqual(res.length, 0);

res = await ls.doValidation(textDoc, jsonDoc, { comments: 'warning'});
res = await ls.doValidation(textDoc, jsonDoc, { comments: 'warning' });
assert.strictEqual(res.length, 1);
assert.strictEqual(res[0].message, 'Comments are not permitted in JSON.');
assert.strictEqual(res[0].severity, DiagnosticSeverity.Warning);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export function repeat(value: string, count: number) {

export function extendedRegExp(pattern: string): RegExp {
if (startsWith(pattern, '(?i)')) {
return new RegExp(pattern.substring(4), 'i');
return new RegExp(pattern.substring(4), 'iu');
} else {
return new RegExp(pattern);
return new RegExp(pattern, 'u');
}
}
X Tutup