This commit is contained in:
Alex Dima 2022-03-23 17:27:13 +01:00
Родитель 677f741f5b
Коммит a22e778360
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 39563C1504FDD0C9
8 изменённых файлов: 2789 добавлений и 690 удалений

7
.vscode/launch.json поставляемый
Просмотреть файл

@ -6,9 +6,9 @@
"name": "Launch tests",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/tape/bin/tape",
"program": "${workspaceRoot}/node_modules/mocha/bin/mocha",
"stopOnEntry": false,
"args": [ "-r", "out/tests/*.test.js", "-g" , "OnigLib"],
"args": [ "--ui=tdd", "./out/tests/all.test.js"],
"cwd": "${workspaceRoot}",
"runtimeExecutable": null,
"runtimeArgs": ["--nolazy"],
@ -17,8 +17,7 @@
},
"console": "internalConsole",
"sourceMaps": true,
"outFiles": [ "out/**" ],
"preLaunchTask": "compile"
"outFiles": [ "out/**" ]
},
{
"type": "node",

3110
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -18,7 +18,7 @@
"scripts": {
"watch": "tsc --watch",
"compile": "tsc",
"test": "tape -r ./out/tests/all.test.js",
"test": "mocha --ui=tdd ./out/tests/all.test.js",
"benchmark": "node benchmark/benchmark.js",
"inspect": "node out/tests/inspect.js",
"tmconvert": "node scripts/tmconvert.js",
@ -28,8 +28,8 @@
},
"devDependencies": {
"@types/node": "^16.6.1",
"@types/tape": "^4.13.2",
"tape": "^5.3.1",
"@types/mocha": "^9.1.0",
"mocha": "^9.2.2",
"typescript": "^4.3.5",
"vscode-oniguruma": "^1.5.1",
"webpack": "^5.50.0",

Просмотреть файл

@ -2,12 +2,12 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import * as tape from 'tape';
import * as assert from 'assert';
import { StandardTokenType } from '../main';
import { StackElementMetadata, TemporaryStandardTokenType } from '../grammar';
import { FontStyle } from '../theme';
function assertEquals(t: tape.Test, metadata: number, languageId: number, tokenType: StandardTokenType, fontStyle: FontStyle, foreground: number, background: number): void {
function assertEquals(metadata: number, languageId: number, tokenType: StandardTokenType, fontStyle: FontStyle, foreground: number, background: number): void {
let actual = {
languageId: StackElementMetadata.getLanguageId(metadata),
tokenType: StackElementMetadata.getTokenType(metadata),
@ -24,70 +24,63 @@ function assertEquals(t: tape.Test, metadata: number, languageId: number, tokenT
background: background,
};
t.deepEqual(actual, expected, 'equals for ' + StackElementMetadata.toBinaryStr(metadata));
assert.deepStrictEqual(actual, expected, 'equals for ' + StackElementMetadata.toBinaryStr(metadata));
}
tape('StackElementMetadata works', (t: tape.Test) => {
test('StackElementMetadata works', () => {
let value = StackElementMetadata.set(0, 1, TemporaryStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
assertEquals(t, value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
t.end();
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
});
tape('StackElementMetadata can overwrite languageId', (t: tape.Test) => {
test('StackElementMetadata can overwrite languageId', () => {
let value = StackElementMetadata.set(0, 1, TemporaryStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
assertEquals(t, value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
value = StackElementMetadata.set(value, 2, TemporaryStandardTokenType.Other, FontStyle.NotSet, 0, 0);
assertEquals(t, value, 2, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
t.end();
assertEquals(value, 2, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
});
tape('StackElementMetadata can overwrite tokenType', (t: tape.Test) => {
test('StackElementMetadata can overwrite tokenType', () => {
let value = StackElementMetadata.set(0, 1, TemporaryStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
assertEquals(t, value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
value = StackElementMetadata.set(value, 0, TemporaryStandardTokenType.Comment, FontStyle.NotSet, 0, 0);
assertEquals(t, value, 1, StandardTokenType.Comment, FontStyle.Underline | FontStyle.Bold, 101, 102);
t.end();
assertEquals(value, 1, StandardTokenType.Comment, FontStyle.Underline | FontStyle.Bold, 101, 102);
});
tape('StackElementMetadata can overwrite font style', (t: tape.Test) => {
test('StackElementMetadata can overwrite font style', () => {
let value = StackElementMetadata.set(0, 1, TemporaryStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
assertEquals(t, value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
value = StackElementMetadata.set(value, 0, TemporaryStandardTokenType.Other, FontStyle.None, 0, 0);
assertEquals(t, value, 1, StandardTokenType.RegEx, FontStyle.None, 101, 102);
t.end();
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.None, 101, 102);
});
tape('StackElementMetadata can overwrite font style with strikethrough', (t: tape.Test) => {
test('StackElementMetadata can overwrite font style with strikethrough', () => {
let value = StackElementMetadata.set(0, 1, TemporaryStandardTokenType.RegEx, FontStyle.Strikethrough, 101, 102);
assertEquals(t, value, 1, StandardTokenType.RegEx, FontStyle.Strikethrough, 101, 102);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Strikethrough, 101, 102);
value = StackElementMetadata.set(value, 0, TemporaryStandardTokenType.Other, FontStyle.None, 0, 0);
assertEquals(t, value, 1, StandardTokenType.RegEx, FontStyle.None, 101, 102);
t.end();
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.None, 101, 102);
});
tape('StackElementMetadata can overwrite foreground', (t: tape.Test) => {
test('StackElementMetadata can overwrite foreground', () => {
let value = StackElementMetadata.set(0, 1, TemporaryStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
assertEquals(t, value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
value = StackElementMetadata.set(value, 0, TemporaryStandardTokenType.Other, FontStyle.NotSet, 5, 0);
assertEquals(t, value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 5, 102);
t.end();
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 5, 102);
});
tape('StackElementMetadata can overwrite background', (t: tape.Test) => {
test('StackElementMetadata can overwrite background', () => {
let value = StackElementMetadata.set(0, 1, TemporaryStandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
assertEquals(t, value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102);
value = StackElementMetadata.set(value, 0, TemporaryStandardTokenType.Other, FontStyle.NotSet, 0, 7);
assertEquals(t, value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 7);
t.end();
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 7);
});
tape('StackElementMetadata can work at max values', (t: tape.Test) => {
test('StackElementMetadata can work at max values', () => {
const maxLangId = 255;
const maxTokenType = StandardTokenType.Comment | StandardTokenType.Other | StandardTokenType.RegEx | StandardTokenType.String;
const maxFontStyle = FontStyle.Bold | FontStyle.Italic | FontStyle.Underline;
@ -95,6 +88,5 @@ tape('StackElementMetadata can work at max values', (t: tape.Test) => {
const maxBackground = 511;
let value = StackElementMetadata.set(0, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground);
assertEquals(t, value, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground);
t.end();
assertEquals(value, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground);
});

Просмотреть файл

@ -2,113 +2,106 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import * as tape from 'tape';
import * as assert from 'assert';
import { parse as JSONparse } from '../json';
function isValid(t: tape.Test, json: string): void {
function isValid(json: string): void {
let expected = JSON.parse(json);
let actual = JSONparse(json, null, false);
t.deepEqual(actual, expected);
assert.deepStrictEqual(actual, expected);
// let actual2 = JSONparse(json, true);
// assert.deepEqual(actual2, expected);
}
function isInvalid(t: tape.Test, json: string): void {
function isInvalid(json: string): void {
let hadErr = false;
try {
JSONparse(json, null, false);
} catch (err) {
hadErr = true;
}
t.equal(hadErr, true, 'expected invalid: ' + json);
assert.strictEqual(hadErr, true, 'expected invalid: ' + json);
}
tape('JSON Invalid body', function (t: tape.Test) {
isInvalid(t, '{}[]');
isInvalid(t, '*');
t.end();
test('JSON Invalid body', function () {
isInvalid('{}[]');
isInvalid('*');
});
tape('JSON Trailing Whitespace', function (t: tape.Test) {
isValid(t, '{}\n\n');
t.end();
test('JSON Trailing Whitespace', function () {
isValid('{}\n\n');
});
tape('JSON Objects', function (t: tape.Test) {
isValid(t, '{}');
isValid(t, '{"key": "value"}');
isValid(t, '{"key1": true, "key2": 3, "key3": [null], "key4": { "nested": {}}}');
isValid(t, '{"constructor": true }');
test('JSON Objects', function () {
isValid('{}');
isValid('{"key": "value"}');
isValid('{"key1": true, "key2": 3, "key3": [null], "key4": { "nested": {}}}');
isValid('{"constructor": true }');
isInvalid(t, '{');
isInvalid(t, '{3:3}');
isInvalid(t, '{\'key\': 3}');
isInvalid(t, '{"key" 3}');
isInvalid(t, '{"key":3 "key2": 4}');
isInvalid(t, '{"key":42, }');
isInvalid(t, '{"key:42');
t.end();
isInvalid('{');
isInvalid('{3:3}');
isInvalid('{\'key\': 3}');
isInvalid('{"key" 3}');
isInvalid('{"key":3 "key2": 4}');
isInvalid('{"key":42, }');
isInvalid('{"key:42');
});
tape('JSON Arrays', function (t: tape.Test) {
isValid(t, '[]');
isValid(t, '[1, 2]');
isValid(t, '[1, "string", false, {}, [null]]');
test('JSON Arrays', function () {
isValid('[]');
isValid('[1, 2]');
isValid('[1, "string", false, {}, [null]]');
isInvalid(t, '[');
isInvalid(t, '[,]');
isInvalid(t, '[1 2]');
isInvalid(t, '[true false]');
isInvalid(t, '[1, ]');
isInvalid(t, '[[]');
isInvalid(t, '["something"');
isInvalid(t, '[magic]');
t.end();
isInvalid('[');
isInvalid('[,]');
isInvalid('[1 2]');
isInvalid('[true false]');
isInvalid('[1, ]');
isInvalid('[[]');
isInvalid('["something"');
isInvalid('[magic]');
});
tape('JSON Strings', function (t: tape.Test) {
isValid(t, '["string"]');
isValid(t, '["\\"\\\\\\/\\b\\f\\n\\r\\t\\u1234\\u12AB"]');
isValid(t, '["\\\\"]');
test('JSON Strings', function () {
isValid('["string"]');
isValid('["\\"\\\\\\/\\b\\f\\n\\r\\t\\u1234\\u12AB"]');
isValid('["\\\\"]');
isInvalid(t, '["');
isInvalid(t, '["]');
isInvalid(t, '["\\z"]');
isInvalid(t, '["\\u"]');
isInvalid(t, '["\\u123"]');
isInvalid(t, '["\\u123Z"]');
isInvalid(t, '[\'string\']');
t.end();
isInvalid('["');
isInvalid('["]');
isInvalid('["\\z"]');
isInvalid('["\\u"]');
isInvalid('["\\u123"]');
isInvalid('["\\u123Z"]');
isInvalid('[\'string\']');
});
tape('Numbers', function (t: tape.Test) {
isValid(t, '[0, -1, 186.1, 0.123, -1.583e+4, 1.583E-4, 5e8]');
test('Numbers', function () {
isValid('[0, -1, 186.1, 0.123, -1.583e+4, 1.583E-4, 5e8]');
// isInvalid(t, '[+1]');
// isInvalid(t, '[01]');
// isInvalid(t, '[1.]');
// isInvalid(t, '[1.1+3]');
// isInvalid(t, '[1.4e]');
// isInvalid(t, '[-A]');
t.end();
// isInvalid('[+1]');
// isInvalid('[01]');
// isInvalid('[1.]');
// isInvalid('[1.1+3]');
// isInvalid('[1.4e]');
// isInvalid('[-A]');
});
tape('JSON misc', function (t: tape.Test) {
isValid(t, '{}');
isValid(t, '[null]');
isValid(t, '{"a":true}');
isValid(t, '{\n\t"key" : {\n\t"key2": 42\n\t}\n}');
isValid(t, '{"key":[{"key2":42}]}');
isValid(t, '{\n\t\n}');
isValid(t, '{\n"first":true\n\n}');
isValid(t, '{\n"key":32,\n\n"key2":45}');
isValid(t, '{"a": 1,\n\n"d": 2}');
isValid(t, '{"a": 1, "a": 2}');
isValid(t, '{"a": { "a": 2, "a": 3}}');
isValid(t, '[{ "a": 2, "a": 3}]');
isValid(t, '{"key1":"first string", "key2":["second string"]}');
test('JSON misc', function () {
isValid('{}');
isValid('[null]');
isValid('{"a":true}');
isValid('{\n\t"key" : {\n\t"key2": 42\n\t}\n}');
isValid('{"key":[{"key2":42}]}');
isValid('{\n\t\n}');
isValid('{\n"first":true\n\n}');
isValid('{\n"key":32,\n\n"key2":45}');
isValid('{"a": 1,\n\n"d": 2}');
isValid('{"a": 1, "a": 2}');
isValid('{"a": { "a": 2, "a": 3}}');
isValid('[{ "a": 2, "a": 3}]');
isValid('{"key1":"first string", "key2":["second string"]}');
isInvalid(t, '{\n"key":32,\nerror\n}');
t.end();
isInvalid('{\n"key":32,\nerror\n}');
});

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import * as tape from 'tape';
import * as assert from 'assert';
import { createMatchers } from '../matcher';
let tests = [
@ -48,11 +48,10 @@ let nameMatcher = (identifers: string[], stackElements: string[]) => {
});
};
tests.forEach((test, index) => {
tape('Matcher Test #' + index, (t: tape.Test) => {
let matchers = createMatchers(test.expression, nameMatcher);
let result = matchers.some(m => m.matcher(test.input));
t.equal(result, test.result);
t.end();
tests.forEach((tst, index) => {
test('Matcher Test #' + index, () => {
let matchers = createMatchers(tst.expression, nameMatcher);
let result = matchers.some(m => m.matcher(tst.input));
assert.strictEqual(result, tst.result);
});
});

Просмотреть файл

@ -4,7 +4,7 @@
import * as fs from 'fs';
import * as path from 'path';
import * as tape from 'tape';
import * as assert from 'assert';
import { Registry, IRawTheme } from '../main';
import { ScopeListElement, ScopeMetadata, StackElementMetadata } from '../grammar';
import {
@ -103,13 +103,14 @@ class ThemeInfo {
testFiles = testFiles.filter(testFile => !/\.diff.html$/.test(testFile));
for (let testFile of testFiles) {
let test = new ThemeTest(THEMES_TEST_PATH, testFile, _themeData, _resolver);
tape(test.testName, { timeout: 20000 }, async (t: tape.Test) => {
let tst = new ThemeTest(THEMES_TEST_PATH, testFile, _themeData, _resolver);
test(tst.testName, async function () {
this.timeout(20000);
try {
await test.evaluate();
t.deepEqual(test.actual, test.expected);
await tst.evaluate();
assert.deepStrictEqual(tst.actual, tst.expected);
} catch(err) {
test.writeExpected();
tst.writeExpected();
throw err;
}
});
@ -117,7 +118,7 @@ class ThemeInfo {
})();
tape('Theme matching gives higher priority to deeper matches', (t: tape.Test) => {
test('Theme matching gives higher priority to deeper matches', () => {
let theme = Theme.createFromRawTheme({
settings: [
{ settings: { foreground: '#100000', background: '#200000' } },
@ -137,14 +138,13 @@ tape('Theme matching gives higher priority to deeper matches', (t: tape.Test) =>
let actual = theme.match('punctuation.definition.string.begin.html');
// console.log(actual); process.exit(0);
t.deepEqual(actual, [
assert.deepStrictEqual(actual, [
new ThemeTrieElementRule(5, null, FontStyle.NotSet, _D, _NOT_SET),
new ThemeTrieElementRule(3, ['meta.tag'], FontStyle.NotSet, _C, _NOT_SET),
]);
t.end();
});
tape('Theme matching gives higher priority to parent matches 1', (t: tape.Test) => {
test('Theme matching gives higher priority to parent matches 1', () => {
let theme = Theme.createFromRawTheme({
settings: [
{ settings: { foreground: '#100000', background: '#200000' } },
@ -164,15 +164,14 @@ tape('Theme matching gives higher priority to parent matches 1', (t: tape.Test)
let actual = theme.match('a.b');
t.deepEqual(actual, [
assert.deepStrictEqual(actual, [
new ThemeTrieElementRule(2, ['d'], FontStyle.NotSet, _E, _NOT_SET),
new ThemeTrieElementRule(1, ['c'], FontStyle.NotSet, _D, _NOT_SET),
new ThemeTrieElementRule(1, null, FontStyle.NotSet, _C, _NOT_SET),
]);
t.end();
});
tape('Theme matching gives higher priority to parent matches 2', (t: tape.Test) => {
test('Theme matching gives higher priority to parent matches 2', () => {
let theme = Theme.createFromRawTheme({
settings: [
{ settings: { foreground: '#100000', background: '#200000' } },
@ -186,11 +185,10 @@ tape('Theme matching gives higher priority to parent matches 2', (t: tape.Test)
let parent = new ScopeListElement(root, 'meta.tag.structure.any.html', 0);
let r = ScopeListElement.mergeMetadata(0, parent, new ScopeMetadata('entity.name.tag.structure.any.html', 0, 0, theme.match('entity.name.tag.structure.any.html')));
let colorMap = theme.getColorMap();
t.equal(colorMap[StackElementMetadata.getForeground(r)], '#300000');
t.end();
assert.strictEqual(colorMap[StackElementMetadata.getForeground(r)], '#300000');
});
tape('Theme matching can match', (t: tape.Test) => {
test('Theme matching can match', () => {
let theme = Theme.createFromRawTheme({
settings: [
{ settings: { foreground: '#F8F8F2', background: '#272822' } },
@ -219,7 +217,7 @@ tape('Theme matching can match', (t: tape.Test) => {
function assertMatch(scopeName: string, expected: ThemeTrieElementRule[]): void {
let actual = theme.match(scopeName);
t.deepEqual(actual, expected, 'when matching <<' + scopeName + '>>');
assert.deepStrictEqual(actual, expected, 'when matching <<' + scopeName + '>>');
}
function assertSimpleMatch(scopeName: string, scopeDepth: number, fontStyle: FontStyle, foreground: number, background: number): void {
@ -289,10 +287,9 @@ tape('Theme matching can match', (t: tape.Test) => {
new ThemeTrieElementRule(1, ['selector', 'source.css'], FontStyle.Bold, _NOT_SET, _C),
new ThemeTrieElementRule(1, null, FontStyle.NotSet, _NOT_SET, _C),
]);
t.end();
});
tape('Theme matching Microsoft/vscode#23460', (t: tape.Test) => {
test('Theme matching Microsoft/vscode#23460', () => {
let theme = Theme.createFromRawTheme({
settings: [
{
@ -330,7 +327,7 @@ tape('Theme matching Microsoft/vscode#23460', (t: tape.Test) => {
function assertMatch(scopeName: string, expected: ThemeTrieElementRule[]): void {
let actual = theme.match(scopeName);
t.deepEqual(actual, expected, 'when matching <<' + scopeName + '>>');
assert.deepStrictEqual(actual, expected, 'when matching <<' + scopeName + '>>');
}
// string.quoted.double.json
@ -353,11 +350,10 @@ tape('Theme matching Microsoft/vscode#23460', (t: tape.Test) => {
new ScopeMetadata('string.quoted.double.json', 0, 0, theme.match('string.quoted.double.json'))
);
let colorMap2 = theme.getColorMap();
t.equal(colorMap2[StackElementMetadata.getForeground(r)], '#FF410D');
t.end();
assert.strictEqual(colorMap2[StackElementMetadata.getForeground(r)], '#FF410D');
});
tape('Theme parsing can parse', (t: tape.Test) => {
test('Theme parsing can parse', () => {
let actual = parseTheme({
settings: [
@ -391,21 +387,19 @@ tape('Theme parsing can parse', (t: tape.Test) => {
new ParsedThemeRule('foo', null, 10, FontStyle.None, '#CFA', null),
];
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving strcmp works', (t: tape.Test) => {
test('Theme resolving strcmp works', () => {
let actual = ['bar', 'z', 'zu', 'a', 'ab', ''].sort(strcmp);
let expected = ['', 'a', 'ab', 'bar', 'z', 'zu'];
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving strArrCmp works', (t: tape.Test) => {
test('Theme resolving strArrCmp works', () => {
function assertStrArrCmp(testCase: string, a: string[] | null, b: string[] | null, expected: number): void {
t.equal(strArrCmp(a, b), expected, testCase);
assert.strictEqual(strArrCmp(a, b), expected, testCase);
}
assertStrArrCmp('001', null, null, 0);
@ -422,10 +416,9 @@ tape('Theme resolving strArrCmp works', (t: tape.Test) => {
assertStrArrCmp('012', ['a', 'b'], ['a', 'b'], 0);
assertStrArrCmp('013', ['a', 'b'], ['a', 'c'], -1);
assertStrArrCmp('014', ['a', 'c'], ['a', 'b'], 1);
t.end();
});
tape('Theme resolving always has defaults', (t: tape.Test) => {
test('Theme resolving always has defaults', () => {
let actual = Theme.createFromParsedTheme([]);
let colorMap = new ColorMap();
const _NOT_SET = 0;
@ -436,11 +429,10 @@ tape('Theme resolving always has defaults', (t: tape.Test) => {
new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET))
);
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving respects incoming defaults 1', (t: tape.Test) => {
test('Theme resolving respects incoming defaults 1', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', null, -1, FontStyle.NotSet, null, null)
]);
@ -453,11 +445,10 @@ tape('Theme resolving respects incoming defaults 1', (t: tape.Test) => {
new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET))
);
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving respects incoming defaults 2', (t: tape.Test) => {
test('Theme resolving respects incoming defaults 2', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', null, -1, FontStyle.None, null, null)
]);
@ -470,11 +461,10 @@ tape('Theme resolving respects incoming defaults 2', (t: tape.Test) => {
new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET))
);
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving respects incoming defaults 3', (t: tape.Test) => {
test('Theme resolving respects incoming defaults 3', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', null, -1, FontStyle.Bold, null, null)
]);
@ -487,11 +477,10 @@ tape('Theme resolving respects incoming defaults 3', (t: tape.Test) => {
new ThemeTrieElementRule(0, null, FontStyle.Bold, _A, _B),
new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET))
);
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving respects incoming defaults 4', (t: tape.Test) => {
test('Theme resolving respects incoming defaults 4', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#ff0000', null)
]);
@ -504,11 +493,10 @@ tape('Theme resolving respects incoming defaults 4', (t: tape.Test) => {
new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET))
);
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving respects incoming defaults 5', (t: tape.Test) => {
test('Theme resolving respects incoming defaults 5', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', null, -1, FontStyle.NotSet, null, '#ff0000')
]);
@ -521,11 +509,10 @@ tape('Theme resolving respects incoming defaults 5', (t: tape.Test) => {
new ThemeTrieElementRule(0, null, FontStyle.None, _A, _B),
new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET))
);
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving can merge incoming defaults', (t: tape.Test) => {
test('Theme resolving can merge incoming defaults', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', null, -1, FontStyle.NotSet, null, '#ff0000'),
new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#00ff00', null),
@ -540,11 +527,10 @@ tape('Theme resolving can merge incoming defaults', (t: tape.Test) => {
new ThemeTrieElementRule(0, null, FontStyle.Bold, _A, _B),
new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET))
);
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving defaults are inherited', (t: tape.Test) => {
test('Theme resolving defaults are inherited', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822'),
new ParsedThemeRule('var', null, -1, FontStyle.NotSet, '#ff0000', null)
@ -561,11 +547,10 @@ tape('Theme resolving defaults are inherited', (t: tape.Test) => {
'var': new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.NotSet, _C, _NOT_SET))
})
);
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving same rules get merged', (t: tape.Test) => {
test('Theme resolving same rules get merged', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822'),
new ParsedThemeRule('var', null, 1, FontStyle.Bold, null, null),
@ -583,11 +568,10 @@ tape('Theme resolving same rules get merged', (t: tape.Test) => {
'var': new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, _NOT_SET))
})
);
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving rules are inherited 1', (t: tape.Test) => {
test('Theme resolving rules are inherited 1', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822'),
new ParsedThemeRule('var', null, -1, FontStyle.Bold, '#ff0000', null),
@ -608,11 +592,10 @@ tape('Theme resolving rules are inherited 1', (t: tape.Test) => {
})
})
);
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving rules are inherited 2', (t: tape.Test) => {
test('Theme resolving rules are inherited 2', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822'),
new ParsedThemeRule('var', null, -1, FontStyle.Bold, '#ff0000', null),
@ -648,11 +631,10 @@ tape('Theme resolving rules are inherited 2', (t: tape.Test) => {
})
})
);
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving rules with parent scopes', (t: tape.Test) => {
test('Theme resolving rules with parent scopes', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822'),
new ParsedThemeRule('var', null, -1, FontStyle.Bold, '#100000', null),
@ -683,11 +665,10 @@ tape('Theme resolving rules with parent scopes', (t: tape.Test) => {
)
})
);
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving issue #38: ignores rules with invalid colors', (t: tape.Test) => {
test('Theme resolving issue #38: ignores rules with invalid colors', () => {
let actual = parseTheme({
settings: [{
settings: {
@ -739,11 +720,10 @@ tape('Theme resolving issue #38: ignores rules with invalid colors', (t: tape.Te
new ParsedThemeRule('variable.parameter.function.coffee', null, 5, FontStyle.Italic, '#F9D423', null),
];
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});
tape('Theme resolving issue #35: Trailing comma in a tmTheme scope selector', (t: tape.Test) => {
test('Theme resolving issue #35: Trailing comma in a tmTheme scope selector', () => {
let actual = parseTheme({
settings: [{
settings: {
@ -776,6 +756,5 @@ tape('Theme resolving issue #35: Trailing comma in a tmTheme scope selector', (t
new ParsedThemeRule('punctuation.definition', ['meta.at-rule.if.scss'], 1, FontStyle.NotSet, '#CC7832', null),
];
t.deepEqual(actual, expected);
t.end();
assert.deepStrictEqual(actual, expected);
});

Просмотреть файл

@ -4,7 +4,7 @@
import * as fs from 'fs';
import * as path from 'path';
import * as tape from 'tape';
import * as assert from 'assert';
import { Registry, IGrammar, RegistryOptions, StackElement, parseRawGrammar } from '../main';
import { IOnigLib, IRawGrammar } from '../types';
import { getOniguruma } from './onigLibs';
@ -33,15 +33,14 @@ function assertTokenizationSuite(testLocation: string): void {
let tests: IRawTest[] = JSON.parse(fs.readFileSync(testLocation).toString());
tests.forEach((test) => {
tests.forEach((tst) => {
tape(test.desc, async (t: tape.Test) => {
await performTest(t, test, getOniguruma());
t.end();
test(tst.desc, async () => {
await performTest(tst, getOniguruma());
});
});
async function performTest(t: tape.Test, test: IRawTest, onigLib: Promise<IOnigLib>): Promise<void> {
async function performTest(test: IRawTest, onigLib: Promise<IOnigLib>): Promise<void> {
let grammarScopeName = test.grammarScopeName;
let grammarByScope : { [scope:string]:IRawGrammar } = {};
@ -73,11 +72,11 @@ function assertTokenizationSuite(testLocation: string): void {
}
let prevState: StackElement | null = null;
for (let i = 0; i < test.lines.length; i++) {
prevState = assertLineTokenization(t, grammar, test.lines[i], prevState);
prevState = assertLineTokenization(grammar, test.lines[i], prevState);
}
}
function assertLineTokenization(t: tape.Test, grammar: IGrammar, testCase: IRawTestLine, prevState: StackElement | null): StackElement {
function assertLineTokenization(grammar: IGrammar, testCase: IRawTestLine, prevState: StackElement | null): StackElement {
let actual = grammar.tokenizeLine(testCase.line, prevState);
let actualTokens: IRawToken[] = actual.tokens.map((token) => {
@ -95,7 +94,7 @@ function assertTokenizationSuite(testLocation: string): void {
});
}
t.deepEqual(actualTokens, testCase.tokens, 'Tokenizing line ' + testCase.line);
assert.deepStrictEqual(actualTokens, testCase.tokens, 'Tokenizing line ' + testCase.line);
return actual.ruleStack;
}