Skip to content

Commit

Permalink
Merge pull request #11 from garazdawi/main
Browse files Browse the repository at this point in the history
Add basic testing infrastructure
  • Loading branch information
robertoaloi authored Apr 3, 2024
2 parents d9db24b + 94baa66 commit a928ef9
Show file tree
Hide file tree
Showing 18 changed files with 5,062 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Erlang TextMate Grammar tests

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- run: npm ci
- run: npm test
35 changes: 35 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run tests",
"type": "shell",
"command": "npx vscode-tmgrammar-test -c './tests/*.erl' && npx vscode-tmgrammar-snap './tests/snap/*.erl'",
"group": "test",
"presentation": {
"reveal": "always",
"panel":"new",
},
"problemMatcher": {
"owner": "vscode-tmgrammar-test",
"fileLocation": [
"relative",
"${workspaceFolder}",
],
"pattern": [
{
"regexp": "^(ERROR)\\s([^:]+):(\\d+):(\\d+):(\\d+)\\s(.*)$",
"severity": 1,
"file": 2,
"line": 3,
"column": 4,
"endColumn": 5,
"message": 6,
},
],
},
}
]
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ from _Ben Hockley_.

Commit your updates on `Erlang.plist` and ignode `Erlang.yaml`.

To test the grammar we use [VSCode Textmate grammar test](https://github.com/PanAeon/vscode-tmgrammar-test),
simply run `npm ci && npm test` and all tests will be run. To add more tests you can either add annotated files
to `./tests/` or use the snapshot facility and then tests should be added to `./test/snap`.

See more:

1. Visual Studio Code [Syntax Highlight Guide](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide)
2. TextMate [Language Grammars](https://macromates.com/manual/en/language_grammars)
3. [Writing a TextMate Grammar: Some Lessons Learned](https://www.apeth.com/nonblog/stories/textmatebundle.html)
4. [Building a syntax highlighting extension for VS Code](https://dev.to/borama/building-a-syntax-highlighting-extension-for-vs-code-594)
238 changes: 238 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"scripts": {
"test": "vscode-tmgrammar-test './tests/*.erl' && vscode-tmgrammar-snap './tests/snap/*.erl'"
},
"contributes": {
"languages": [
{
"id": "erlang",
"extensions": [
".erl",
".escript",
".es",
".hrl",
".xrl",
".yrl"
]
}
],
"grammars": [
{
"language": "erlang",
"scopeName": "source.erlang",
"path": "./Erlang.plist"
}
]
},
"devDependencies": {
"vscode-tmgrammar-test": "^0.1.3"
}
}
31 changes: 31 additions & 0 deletions tests/basic.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
% SYNTAX TEST "source.erlang" "A basic test"
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.erlang comment.line.percentage.erlang
-module(basic).
%<- source.erlang meta.directive.module.erlang punctuation.section.directive.begin.erlang
%^^^^^^ source.erlang meta.directive.module.erlang keyword.control.directive.module.erlang
% ^ source.erlang meta.directive.module.erlang punctuation.definition.parameters.begin.erlang
% ^^^^^ source.erlang meta.directive.module.erlang entity.name.type.class.module.definition.erlang
% ^ source.erlang meta.directive.module.erlang punctuation.definition.parameters.end.erlang
% ^ source.erlang meta.directive.module.erlang punctuation.section.directive.end.erlang
-export([test/0]).
%<- source.erlang meta.directive.export.erlang punctuation.section.directive.begin.erlang
%^^^^^^ source.erlang meta.directive.export.erlang keyword.control.directive.export.erlang
% ^ source.erlang meta.directive.export.erlang punctuation.definition.parameters.begin.erlang
% ^ source.erlang meta.directive.export.erlang meta.structure.list.function.erlang punctuation.definition.list.begin.erlang
% ^^^^ source.erlang meta.directive.export.erlang meta.structure.list.function.erlang entity.name.function.erlang
% ^ source.erlang meta.directive.export.erlang meta.structure.list.function.erlang punctuation.separator.function-arity.erlang
% ^ source.erlang meta.directive.export.erlang meta.structure.list.function.erlang constant.numeric.integer.decimal.erlang
% ^ source.erlang meta.directive.export.erlang meta.structure.list.function.erlang punctuation.definition.list.end.erlang
% ^ source.erlang meta.directive.export.erlang punctuation.definition.parameters.end.erlang
% ^ source.erlang meta.directive.export.erlang punctuation.section.directive.end.erlang

test() -> ok.
%<---- source.erlang meta.function.erlang entity.name.function.definition.erlang
% ^ source.erlang meta.function.erlang meta.expression.parenthesized punctuation.section.expression.begin.erlang
% ^ source.erlang meta.function.erlang meta.expression.parenthesized punctuation.section.expression.end.erlang
% ^ source.erlang meta.function.erlang
% ^ source.erlang meta.function.erlang keyword.operator.symbolic.erlang
% ^ source.erlang meta.function.erlang keyword.operator.symbolic.erlang
% ^ source.erlang meta.function.erlang
% ^^ source.erlang meta.function.erlang constant.other.symbol.unquoted.erlang
% ^ source.erlang meta.function.erlang punctuation.terminator.function.erlang
19 changes: 19 additions & 0 deletions tests/snap/function_call.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-module(function_call).

-define(F, f).

f() ->
ok.

g(M, F) ->
m:f(),
m:F(),
m:?F(),
M:f(),
?MODULE:f(),
ok.

-spec h() -> ok.
h() ->
g(m, f),
ok.
Loading

0 comments on commit a928ef9

Please sign in to comment.