diff --git a/.github/workflows/vscode-language-yesod-ci.yml b/.github/workflows/vscode-language-yesod-ci.yml index 2c70674..129854e 100644 --- a/.github/workflows/vscode-language-yesod-ci.yml +++ b/.github/workflows/vscode-language-yesod-ci.yml @@ -36,3 +36,6 @@ jobs: - name: Test Hamlet's syntax highlighting run: npx vscode-tmgrammar-test -s source.yesod.hamlet -g syntaxes/hamlet.tmLanguage.json -t "test/tests/hamlet/*.hamlet" + + - name: Test Routes' syntax highlighting + run: npx vscode-tmgrammar-test -s source.yesod.routes -g syntaxes/routes.tmLanguage.json -t "test/tests/routes/*.yesodroutes" diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7dc225b..2e28255 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -57,11 +57,39 @@ ] } }, + { + "label": "Run routes tests", + "type": "shell", + "command": "npx vscode-tmgrammar-test -c -s source.yesod.routes -g syntaxes/routes.tmLanguage.json -t \"test/tests/routes/*.yesodroutes\"", + "group": "test", + "presentation": { + "reveal": "always", + "panel": "new" + }, + "problemMatcher": { + "fileLocation": [ + "relative", + "${workspaceFolder}" + ], + "pattern": [ + { + "regexp": "^(ERROR)\\s([^:]+):(\\d+):(\\d+):(\\d+)\\s(.*)$", + "severity": 1, + "file": 2, + "line": 3, + "column": 4, + "endColumn": 5, + "message": 6 + } + ] + } + }, { "label": "Run all tests", "dependsOn": [ "Run hamlet tests", - "Run cassius tests" + "Run cassius tests", + "Run routes tests" ] } ] diff --git a/CHANGELOG.md b/CHANGELOG.md index e5ac22d..72d10e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to the "language-yesod" extension will be documented in this Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +## [Unreleased] + +- Added a test case for route declarations. [#24](https://github.com/e-bigmoon/vscode-language-yesod/pull/24) + ## [0.7.0] - 2021-03-13 - Added CI with Github actions diff --git a/syntaxes/routes.tmLanguage.json b/syntaxes/routes.tmLanguage.json index 29a6082..a58bc1f 100644 --- a/syntaxes/routes.tmLanguage.json +++ b/syntaxes/routes.tmLanguage.json @@ -9,35 +9,45 @@ "toplevel": { "patterns": [ { - "begin": "^\\s*[/!]", + "begin": "^\\s*", "end": "\n", - "name": "meta.url.route.yesod", "patterns": [ { - "match": "[#*+]!?[A-Z][a-zA-Z0-9]+", - "name": "support.type.patterns" + "include": "#comment" }, { - "match": "\\b([A-Z][a-zA-Z0-9]+R)\\b", - "name": "constant.other.handler" - }, - { - "match": "(GET|HEAD|POST|PUT|DELETE|OPTIONS|PATCH)", - "name": "entity.name.function" - }, - { - "match": "![a-zA-Z0-9]+", - "name": "entity.other.attribute-name" - }, - { - "match": "--.*", - "name": "comment.line" + "begin": "[/!]", + "name": "meta.url.route.yesod", + "patterns": [ + { + "match": "[#*+]!?[A-Z][a-zA-Z0-9]+", + "name": "support.type.patterns" + }, + { + "match": "\\b([A-Z][a-zA-Z0-9]+R)\\b", + "name": "constant.other.handler" + }, + { + "match": "(GET|HEAD|POST|PUT|DELETE|OPTIONS|PATCH)", + "name": "entity.name.function" + }, + { + "match": "![a-zA-Z0-9]+", + "name": "entity.other.attribute-name" + }, + { + "include": "#comment" + } + ] } ] - }, + } + ] + }, + "comment": { + "patterns": [ { - "begin": "^\\s*--", - "end": "\n", + "match": "--.*$", "name": "comment.line" } ] diff --git a/test/tests/routes/attribute.yesodroutes b/test/tests/routes/attribute.yesodroutes new file mode 100644 index 0000000..64b5916 --- /dev/null +++ b/test/tests/routes/attribute.yesodroutes @@ -0,0 +1,14 @@ +-- SYNTAX TEST "source.yesod.routes" "attribute" + +/admin AdminR !admin: +-- <-------------- - entity.other.attribute-name +-- ^^^^^^ entity.other.attribute-name + /1 Admin1R GET !1 +-- ^^^^^^^^^^^^^^^ - entity.other.attribute-name +-- ^^ entity.other.attribute-name + /2 Admin2R GET !2 +-- ^^^^^^^^^^^^^^^ - entity.other.attribute-name +-- ^^ entity.other.attribute-name + /3 Admin3R GET !3 +-- ^^^^^^^^^^^^^^^ - entity.other.attribute-name +-- ^^ entity.other.attribute-name diff --git a/test/tests/routes/comment.yesodroutes b/test/tests/routes/comment.yesodroutes new file mode 100644 index 0000000..716e438 --- /dev/null +++ b/test/tests/routes/comment.yesodroutes @@ -0,0 +1,9 @@ +-- SYNTAX TEST "source.yesod.routes" "comment line" + + -- comment +-- <-- - comment.line +-- ^^^^^^^^^^ comment.line + +/ HomeR GET-- comment +-- <--------------------------- - comment.line +-- ^^^^^^^^^^ comment.line diff --git a/test/tests/routes/handler.yesodroutes b/test/tests/routes/handler.yesodroutes new file mode 100644 index 0000000..fca99d7 --- /dev/null +++ b/test/tests/routes/handler.yesodroutes @@ -0,0 +1,18 @@ +-- SYNTAX TEST "source.yesod.routes" "handler" + +/foo1 Foo1R GET +-- <-------------- - constant.other.handler +-- ^^^^^ constant.other.handler +-- ^^^^^^^^ - constant.other.handler +/foo2 Foo2R HEAD +-- <-------------- - constant.other.handler +-- ^^^^^ constant.other.handler +-- ^^^^^^^^^ - constant.other.handler +/multi MultiR GET POST +-- <-------------- - constant.other.handler +-- ^^^^^^ constant.other.handler +-- ^^^^^^^^^^^^ - constant.other.handler +/blog/#BlogId BlogPostR GET POST +-- <-------------- - constant.other.handler +-- ^^^^^^^^^ constant.other.handler +-- ^^^^^^^^^ - constant.other.handler diff --git a/test/tests/routes/method.yesodroutes b/test/tests/routes/method.yesodroutes new file mode 100644 index 0000000..fd4eaf0 --- /dev/null +++ b/test/tests/routes/method.yesodroutes @@ -0,0 +1,29 @@ +-- SYNTAX TEST "source.yesod.routes" "http methods" + +/foo1 Foo1R GET +-- <------------------------ - entity.name.function +-- ^^^ entity.name.function +/foo2 Foo2R HEAD +-- <------------------------ - entity.name.function +-- ^^^ entity.name.function +/foo3 Foo3R POST +-- <------------------------ - entity.name.function +-- ^^^ entity.name.function +/foo4 Foo4R PUT +-- <------------------------ - entity.name.function +-- ^^^ entity.name.function +/foo5 Foo5R DELETE +-- <------------------------ - entity.name.function +-- ^^^ entity.name.function +/foo6 Foo6R OPTIONS +-- <------------------------ - entity.name.function +-- ^^^ entity.name.function +/foo7 Foo7R PATCH +-- <------------------------ - entity.name.function +-- ^^^ entity.name.function +/multi MultiR GET POST +-- <------------------------ - entity.name.function +-- ^^^ ^^^^ entity.name.function +/blog/#BlogId BlogPostR GET POST +-- <------------------------ - entity.name.function +-- ^^^ ^^^^ entity.name.function diff --git a/test/tests/routes/pattern.yesodroutes b/test/tests/routes/pattern.yesodroutes new file mode 100644 index 0000000..ccf5862 --- /dev/null +++ b/test/tests/routes/pattern.yesodroutes @@ -0,0 +1,17 @@ +-- SYNTAX TEST "source.yesod.routes" "pattern" + +/foo/bar Foo1R GET +-- <-------------------- - support.type.patterns +/foo/#Text Foo2R GET +-- <----- - support.type.patterns +-- ^^^^^ support.type.patterns +-- ^^^^^^^^^^ - support.type.patterns +/foo/bar Foo1R GET +!/foo/#Int Foo2R GET +-- <------ - support.type.patterns +-- ^^^^ support.type.patterns +-- ^^^^^^^^^^^ - support.type.patterns +!/foo/#Text Foo3R GET +-- <------ - support.type.patterns +-- ^^^^^ support.type.patterns +-- ^^^^^^^^^^ - support.type.patterns \ No newline at end of file