Socket
Socket
Sign inDemoInstall

vscode-tmgrammar-test

Package Overview
Dependencies
24
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.4 to 0.0.5

13

dist/src/snapshot.js

@@ -125,4 +125,13 @@ #!/usr/bin/env node

}
var wrongLines = flatten(expected.map(function (exp, i) {
var act = actual[i];
// renderSnap won't produce assertions for empty lines, so we'll remove them here
// for both actual end expected
var actual1 = actual.filter(function (a) { return a.src.trim().length > 0; });
var expected1 = expected.filter(function (a) { return a.src.trim().length > 0; });
// console.log(inspect(expected, false, 5, true))
// console.log(" ")
// console.log(" ")
// console.log(inspect(actual, false, 5, true))
// process.exit(-1)
var wrongLines = flatten(expected1.map(function (exp, i) {
var act = actual1[i];
var expTokenMap = toMap(function (t) { return t.startIndex + ":" + t.startIndex; }, exp.tokens);

@@ -129,0 +138,0 @@ var actTokenMap = toMap(function (t) { return t.startIndex + ":" + t.startIndex; }, act.tokens);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function parseSnap(s) {
return JSON.parse(s);
var result = [];
var ls = s.split("\n");
var i = 0;
while (i < ls.length) {
var l = ls[i];
if (l.startsWith(">")) {
var src = l.substr(1);
i++;
var tokens = [];
while (i < ls.length && ls[i].startsWith("#")) {
var startIndex = ls[i].indexOf("^");
var endIndex = ls[i].indexOf(" ", startIndex);
var scopes = ls[i].substr(endIndex + 1).split(/\s+/).filter(function (x) { return x !== ""; });
tokens.push({
startIndex: startIndex - 1,
endIndex: endIndex - 1,
scopes: scopes
});
i++;
}
result.push({
src: src,
tokens: tokens
});
}
else {
i++;
}
}
return result;
}
exports.parseSnap = parseSnap;
// expects xs to be already sorted by (linenumber,from)
function renderSnap(xs) {
return JSON.stringify(xs, undefined, 2);
var result = [];
xs.forEach(function (line) {
result.push(">" + line.src);
if (line.src.trim().length > 0) {
line.tokens.forEach(function (token) {
result.push("#" + (" ".repeat(token.startIndex)) + ("^".repeat(token.endIndex - token.startIndex)) + " " + (token.scopes.join(" ")));
});
}
});
return result.join("\n");
}
exports.renderSnap = renderSnap;
//# sourceMappingURL=parsing.js.map

2

package.json
{
"name": "vscode-tmgrammar-test",
"version": "0.0.4",
"version": "0.0.5",
"description": "Test helper for VSCode textmate grammars",

@@ -5,0 +5,0 @@ "main": "./dist/src/index.js",

@@ -5,7 +5,12 @@ ## VSCode Textmate grammar test

![Showcase](images/showcase.gif?raw=true "grammar test in action")
* Unit tests:
![Showcase unit](images/showcase.gif?raw=true "unit test in action")
* Snapshot tests:
![Showcase snap](images/Snapshots.png "snapshots test in action")
Inspired by [Sublime Text syntax tests](https://www.sublimetext.com/docs/3/syntax.html#testing)
### Installation

@@ -27,3 +32,3 @@

### Test cases
### Unit tests

@@ -56,3 +61,3 @@ ```scala

To write a test case:
To write a unit test:

@@ -93,5 +98,26 @@ * include a header line:

Note, that scope comparison takes into account relative scope's position.
So, if required scopes are `'scope1 scope2'`, the test will report an error if a grammar returns them as `'scope2 scope1'`.
So, if required scopes are `'scope1 scope2'`, the test will report an error if a grammar returns them as `'scope2 scope1'`.
### Snapshot tests
Snapshot tests are like `functional tests` but you don't have to write outputs explicitly.
All you have to do is to provide a source files, scopes of which you want to test. Then on
the first run `vscode-tmgrammar-snap` will generate a set of `.snap` files which are an
instant snapshot of lines of the source files together with corresponding scopes.
Then if you change the grammar and run the test again, the program will output the changes between
the `.snap` file and the real output.
If you satisfied with the changes you can `commit` them by running
```bash
vscode-tmgrammar-snap .... --updateSnapshot
```
this will overwrite the existing `.snap` files with a new ones.
After this you should commit them alongside with the source code test cases.
You can read more about them at [snapshot testing](https://jestjs.io/docs/en/snapshot-testing)
### Command Line Options
* Unit tests:
```

@@ -110,3 +136,20 @@ Usage: vscode-tmgrammar-test [options]

```
* Snapshot tests:
```
Usage: vscode-tmgrammar-snap [options]
Run VSCode textmate grammar snapshot tests
Options:
-V, --version output the version number
-s, --scope <scope> Language scope, e.g. source.dhall
-g, --grammar <grammar> Path to a grammar file, either .json or .xml
-t, --testcases <glob> A glob pattern which specifies testcases to run, e.g. './tests/**/test*.dhall'. Quotes are important!
-u, --updateSnapshot overwrite all snap files with new changes
--printNotModified include not modified scopes in the output
--expandDiff produce each diff on two lines prefixed with "++" and "--"
-h, --help output usage information
```
Example:

@@ -118,5 +161,5 @@

### Setup VSCode task
### Setup VSCode unit test task
You can setup a vscode test task for convenience:
You can setup a vscode unit test task for convenience:

@@ -123,0 +166,0 @@ ```json

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