Socket
Socket
Sign inDemoInstall

vscode-tmgrammar-test

Package Overview
Dependencies
22
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 0.1.2

dist/unit/reporter.d.ts

13

dist/common/index.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -17,3 +21,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -90,3 +94,2 @@ return result;

function loadConfiguration(config, scope, grammar) {
var _a, _b;
const configPath = config || 'package.json';

@@ -101,3 +104,3 @@ let grammars = [];

const json = JSON.parse(fs.readFileSync(configPath).toString());
let xs = ((_a = json === null || json === void 0 ? void 0 : json.contributes) === null || _a === void 0 ? void 0 : _a.grammars) || [];
let xs = json?.contributes?.grammars || [];
const dirPath = path.dirname(configPath);

@@ -108,3 +111,3 @@ xs.forEach((x) => {

grammars.push(...xs);
let ys = ((_b = json === null || json === void 0 ? void 0 : json.contributes) === null || _b === void 0 ? void 0 : _b.languages) || [];
let ys = json?.contributes?.languages || [];
let langToScope = Object.assign({}, ...grammars.filter((x) => x.language).map((x) => ({ [x.language || '']: x.scopeName })));

@@ -111,0 +114,0 @@ let extToLang = Object.assign({}, ...ys.map((x) => x.extensions.map((e) => ({ [e]: x.id }))).flat());

@@ -5,3 +5,7 @@ #!/usr/bin/env node

if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -19,3 +23,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -77,4 +81,4 @@ return result;

}
let { grammars, extensionToScope } = index_1.loadConfiguration(options.config, options.scope, options.grammar);
const registry = index_1.createRegistry(grammars);
let { grammars, extensionToScope } = (0, index_1.loadConfiguration)(options.config, options.scope, options.grammar);
const registry = (0, index_1.createRegistry)(grammars);
const testResults = Promise.all(testCases.map((filename) => {

@@ -88,12 +92,12 @@ const src = fs.readFileSync(filename).toString();

}
return index_2.getVSCodeTokens(registry, scope, src)
return (0, index_2.getVSCodeTokens)(registry, scope, src)
.then((tokens) => {
if (fs.existsSync(filename + '.snap')) {
if (options.updateSnapshot) {
console.log(chalk_1.default.yellowBright('Updating snapshot for') + chalk_1.default.whiteBright(filename + '.snap'));
fs.writeFileSync(filename + '.snap', index_2.renderSnap(tokens), 'utf8');
console.log(chalk_1.default.yellowBright('Updating snapshot for ') + chalk_1.default.whiteBright(filename + '.snap'));
fs.writeFileSync(filename + '.snap', (0, index_2.renderSnap)(tokens), 'utf8');
return TestSuccessful;
}
else {
const expectedTokens = index_2.parseSnap(fs.readFileSync(filename + '.snap').toString());
const expectedTokens = (0, index_2.parseSnap)(fs.readFileSync(filename + '.snap').toString());
return renderTestResult(filename, expectedTokens, tokens);

@@ -104,3 +108,3 @@ }

console.log(chalk_1.default.yellowBright('Generating snapshot ') + chalk_1.default.whiteBright(filename + '.snap'));
fs.writeFileSync(filename + '.snap', index_2.renderSnap(tokens));
fs.writeFileSync(filename + '.snap', (0, index_2.renderSnap)(tokens));
return TestSuccessful;

@@ -107,0 +111,0 @@ }

@@ -5,3 +5,7 @@ #!/usr/bin/env node

if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -19,3 +23,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -29,8 +33,7 @@ return result;

const fs = __importStar(require("fs"));
const tty = __importStar(require("tty"));
const chalk_1 = __importDefault(require("chalk"));
const commander_1 = require("commander");
const glob_1 = __importDefault(require("glob"));
const os_1 = require("os");
const index_1 = require("./unit/index");
const reporter_1 = require("./unit/reporter");
const index_2 = require("./common/index");

@@ -46,2 +49,4 @@ let packageJson = require('../package.json');

.option('-c, --compact', 'Display output in the compact format, which is easier to use with VSCode problem matchers')
.option('--xunit-report <report.xml>', 'Path to directory where test reports in the XUnit format will be emitted in addition to console output')
.option('--xunit-format <generic|gitlab>', 'Format of XML reports generated when --xunit-report is used. `gitlab` format is suitable for viewing the results in GitLab CI/CD web GUI')
.version(packageJson.version)

@@ -51,24 +56,6 @@ .argument('<testcases...>', 'A glob pattern(s) which specifies testcases to run, e.g. "./tests/**/test*.dhall". Quotes are important!')

const options = commander_1.program.opts();
let isatty = tty.isatty(1) && tty.isatty(2);
const symbols = {
ok: '✓',
err: '✖',
dot: '․',
comma: ',',
bang: '!'
};
if (process.platform === 'win32') {
symbols.ok = '\u221A';
symbols.err = '\u00D7';
symbols.dot = '.';
}
let terminalWidth = 75;
if (isatty) {
terminalWidth = process.stdout.getWindowSize()[0];
}
const TestFailed = -1;
const TestSuccessful = 0;
const Padding = ' ';
let { grammars } = index_2.loadConfiguration(options.config, options.scope, options.grammar);
const registry = index_2.createRegistry(grammars);
let { grammars } = (0, index_2.loadConfiguration)(options.config, options.scope, options.grammar);
const registry = (0, index_2.createRegistry)(grammars);
if (options.validate) {

@@ -82,3 +69,10 @@ if (!!registry && typeof registry === 'object') {

}
const displayTestResult = options.compact ? displayTestResultCompact : displayTestResultFull;
const consoleReporter = options.compact
? new reporter_1.ConsoleCompactReporter()
: new reporter_1.ConsoleFullReporter();
const reporter = options.xunitReport
? new reporter_1.CompositeReporter(consoleReporter, options.xunitFormat === 'gitlab'
? new reporter_1.XunitGitlabReporter(options.xunitReport)
: new reporter_1.XunitGenericReporter(options.xunitReport))
: consoleReporter;
const rawTestCases = commander_1.program.args.map((x) => glob_1.default.sync(x)).flat();

@@ -92,7 +86,6 @@ if (rawTestCases.length === 0) {

try {
tc = index_1.parseGrammarTestCase(fs.readFileSync(filename).toString());
tc = (0, index_1.parseGrammarTestCase)(fs.readFileSync(filename).toString());
}
catch (error) {
console.log(chalk_1.default.red('ERROR') + " can't parse testcase: " + chalk_1.default.whiteBright(filename) + '');
console.log(error);
reporter.reportParseError(filename, error);
return new Promise((resolve, reject) => {

@@ -103,11 +96,14 @@ resolve(TestFailed);

let testCase = tc;
return index_1.runGrammarTestCase(registry, testCase)
return (0, index_1.runGrammarTestCase)(registry, testCase)
.then((failures) => {
return displayTestResult(filename, testCase, failures);
reporter.reportTestResult(filename, testCase, failures);
return failures.length === 0 ? TestSuccessful : TestFailed;
})
.catch((error) => {
return handleGrammarTestError(filename, testCase, error);
reporter.reportGrammarTestError(filename, testCase, error);
return TestFailed;
});
}));
testResults.then((xs) => {
reporter.reportSuiteResult();
const result = xs.reduce((a, b) => a + b, 0);

@@ -121,79 +117,2 @@ if (result === TestSuccessful) {

});
function printSourceLine(testCase, failure) {
const line = testCase.source[failure.srcLine];
const pos = failure.line + 1 + ': ';
const accents = ' '.repeat(failure.start) + '^'.repeat(failure.end - failure.start);
const termWidth = terminalWidth - pos.length - Padding.length - 5;
const trimLeft = failure.end > termWidth ? Math.max(0, failure.start - 8) : 0;
const line1 = line.substr(trimLeft);
const accents1 = accents.substr(trimLeft);
console.log(Padding + chalk_1.default.gray(pos) + line1.substr(0, termWidth));
console.log(Padding + ' '.repeat(pos.length) + accents1.substr(0, termWidth));
}
function printReason(testCase, failure) {
if (failure.missing && failure.missing.length > 0) {
console.log(chalk_1.default.red(Padding + 'missing required scopes: ') + chalk_1.default.gray(failure.missing.join(' ')));
}
if (failure.unexpected && failure.unexpected.length > 0) {
console.log(chalk_1.default.red(Padding + 'prohibited scopes: ') + chalk_1.default.gray(failure.unexpected.join(' ')));
}
if (failure.actual !== undefined) {
console.log(chalk_1.default.red(Padding + 'actual: ') + chalk_1.default.gray(failure.actual.join(' ')));
}
}
function displayTestResultFull(filename, testCase, failures) {
if (failures.length === 0) {
console.log(chalk_1.default.green(symbols.ok) + ' ' + chalk_1.default.whiteBright(filename) + ` run successfuly.`);
return TestSuccessful;
}
else {
console.log(chalk_1.default.red(symbols.err + ' ' + filename + ' failed'));
failures.forEach((failure) => {
const { l, s, e } = getCorrectedOffsets(failure);
console.log(Padding + 'at [' + chalk_1.default.whiteBright(`${filename}:${l}:${s}:${e}`) + ']:');
printSourceLine(testCase, failure);
printReason(testCase, failure);
console.log(os_1.EOL);
});
console.log('');
return TestFailed;
}
}
function renderCompactErrorMsg(testCase, failure) {
let res = '';
if (failure.missing && failure.missing.length > 0) {
res += `Missing required scopes: [ ${failure.missing.join(' ')} ] `;
}
if (failure.unexpected && failure.unexpected.length > 0) {
res += `Prohibited scopes: [ ${failure.unexpected.join(' ')} ] `;
}
if (failure.actual !== undefined) {
res += `actual scopes: [${failure.actual.join(' ')}]`;
}
return res;
}
function displayTestResultCompact(filename, testCase, failures) {
if (failures.length === 0) {
console.log(chalk_1.default.green(symbols.ok) + ' ' + chalk_1.default.whiteBright(filename) + ` run successfuly.`);
return TestSuccessful;
}
else {
failures.forEach((failure) => {
console.log(`ERROR ${filename}:${failure.line + 1}:${failure.start + 1}:${failure.end + 1} ${renderCompactErrorMsg(testCase, failure)}`);
});
return TestFailed;
}
}
function handleGrammarTestError(filename, testCase, reason) {
console.log(chalk_1.default.red(symbols.err) + ' testcase ' + chalk_1.default.gray(filename) + ' aborted due to an error');
console.log(reason);
return TestFailed;
}
function getCorrectedOffsets(failure) {
return {
l: failure.line + 1,
s: failure.start + 1,
e: failure.end + 1
};
}
//# sourceMappingURL=unit.js.map
{
"name": "vscode-tmgrammar-test",
"version": "0.1.1",
"version": "0.1.2",
"description": "Test runner for VSCode textmate grammars",

@@ -39,6 +39,7 @@ "homepage": "https://github.com/PanAeon/vscode-tmgrammar-test",

"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.7",
"@types/node": "^12.12.37",
"@types/mocha": "^10.0.1",
"@types/node": "^18.11.9",
"@types/xml2js": "^0.4.11",
"chai": "^4.2.0",
"mocha": "^6.2.3",
"mocha": "^10.2.0",
"nyc": "^15.0.1",

@@ -48,3 +49,4 @@ "prettier": "^2.1.2",

"tslint": "^5.20.1",
"typescript": "^3.8.3"
"typescript": "^5.1.6",
"xml2js": "^0.6.0"
},

@@ -51,0 +53,0 @@ "dependencies": {

@@ -1,2 +0,2 @@

![Node.js CI](https://img.shields.io/github/workflow/status/PanAeon/vscode-tmgrammar-test/Node.js%20CI?style=for-the-badge) ![NPM Version](https://img.shields.io/npm/v/vscode-tmgrammar-test?style=for-the-badge)
![Node.js CI](https://img.shields.io/github/actions/workflow/status/PanAeon/vscode-tmgrammar-test/nodejs.yml?branch=master&style=for-the-badge) ![NPM Version](https://img.shields.io/npm/v/vscode-tmgrammar-test?style=for-the-badge)
## VSCode Textmate grammar test

@@ -73,6 +73,9 @@

* Ensure that tokens **don't** have undesired scopes by using&nbsp;&nbsp; `- scopes`&nbsp;:
* To ensure that tokens **don't** have undesired scopes put `-` symbol before them:
```scala
// ensure comment start with two double slashes
^ - comment.line.double-slash.scala punctuation.definition.comment.scala
/ ensure comment start with two double slashes
^ - comment.line.double slash.scala
/ or you can combine both positive and negative scopes
^ source.scala - comment.line.double slash.scala
```

@@ -159,7 +162,11 @@

Options:
-g, --grammar <grammar> Path to a grammar file. Multiple options supported. 'scopeName' is taken from the grammar (default: [])
--config <configuration.json> Path to the language configuration, package.json by default
-c, --compact Display output in the compact format, which is easier to use with VSCode problem matchers
-V, --version output the version number
-h, --help display help for command
-g, --grammar <grammar> Path to a grammar file. Multiple options supported. 'scopeName' is taken from the grammar (default: [])
--config <configuration.json> Path to the language configuration, package.json by default
-c, --compact Display output in the compact format, which is easier to use with VSCode problem matchers
--xunit-report <report.xml> Path to directory where test reports in the XUnit format will
be emitted in addition to console output
--xunit-format <generic|gitlab> Format of XML reports generated when --xunit-report is used.
`gitlab` format is suitable for viewing the results in GitLab
-V, --version output the version number
-h, --help display help for command
```

@@ -166,0 +173,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc