From 303259a96cd5bbb6ec50414621870b9018446391 Mon Sep 17 00:00:00 2001 From: isao-takejib Date: Sat, 20 Mar 2021 04:46:20 +0000 Subject: [PATCH 01/10] Add testcase for yesodroutes --- test/tests/routes/handler.yesodroutes | 9 +++++++++ test/tests/routes/method.yesodroutes | 19 +++++++++++++++++++ test/tests/routes/pattern.yesodroutes | 10 ++++++++++ 3 files changed, 38 insertions(+) create mode 100644 test/tests/routes/handler.yesodroutes create mode 100644 test/tests/routes/method.yesodroutes create mode 100644 test/tests/routes/pattern.yesodroutes diff --git a/test/tests/routes/handler.yesodroutes b/test/tests/routes/handler.yesodroutes new file mode 100644 index 0000000..ce30ff5 --- /dev/null +++ b/test/tests/routes/handler.yesodroutes @@ -0,0 +1,9 @@ +-- SYNTAX TEST "source.yesod.routes" "handler" +/foo1 Foo1R GET +-- ^^^^^ constant.other.handler +/foo2 Foo2R HEAD +-- ^^^^^ constant.other.handler +/multi MultiR GET POST +-- ^^^^^^ constant.other.handler +/blog/#BlogId BlogPostR GET POST +-- ^^^^^^^^^ constant.other.handler diff --git a/test/tests/routes/method.yesodroutes b/test/tests/routes/method.yesodroutes new file mode 100644 index 0000000..4a38090 --- /dev/null +++ b/test/tests/routes/method.yesodroutes @@ -0,0 +1,19 @@ +-- SYNTAX TEST "source.yesod.routes" "http methods" +/foo1 Foo1R GET +-- ^^^ entity.name.function +/foo2 Foo2R HEAD +-- ^^^ entity.name.function +/foo3 Foo3R POST +-- ^^^ entity.name.function +/foo4 Foo4R PUT +-- ^^^ entity.name.function +/foo5 Foo5R DELETE +-- ^^^ entity.name.function +/foo6 Foo6R OPTIONS +-- ^^^ entity.name.function +/foo7 Foo7R PATCH +-- ^^^ entity.name.function +/multi MultiR GET POST +-- ^^^ ^^^^ entity.name.function +/blog/#BlogId BlogPostR GET POST +-- ^^^ ^^^^ entity.name.function diff --git a/test/tests/routes/pattern.yesodroutes b/test/tests/routes/pattern.yesodroutes new file mode 100644 index 0000000..8a84dc0 --- /dev/null +++ b/test/tests/routes/pattern.yesodroutes @@ -0,0 +1,10 @@ +-- SYNTAX TEST "source.yesod.routes" "pattern" +/foo/bar Foo1R GET +/foo/#Text Foo2R GET +-- ^^^^^ support.type.patterns + +/foo/bar Foo1R GET +!/foo/#Int Foo2R GET +-- ^^^^ support.type.patterns +!/foo/#Text Foo3R GET +-- ^^^^^ support.type.patterns \ No newline at end of file From d9fd0c33b84eab53d4dc116d22681e846fc23def Mon Sep 17 00:00:00 2001 From: isao-takejib Date: Sat, 20 Mar 2021 04:56:19 +0000 Subject: [PATCH 02/10] Add routes test task --- .vscode/tasks.json | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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" ] } ] From 8aa26d49d9e9f0838624e0a8ffd0a32a7c74a322 Mon Sep 17 00:00:00 2001 From: isao-takejib Date: Sat, 20 Mar 2021 07:29:07 +0000 Subject: [PATCH 03/10] Add comment test for yesodroutes --- test/tests/routes/comment.yesodroutes | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/tests/routes/comment.yesodroutes 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 From cd78ce4278738961f65f9f11602553a4352f639b Mon Sep 17 00:00:00 2001 From: isao-takejib Date: Sat, 20 Mar 2021 07:29:46 +0000 Subject: [PATCH 04/10] minor fix --- test/tests/routes/handler.yesodroutes | 1 + test/tests/routes/method.yesodroutes | 1 + test/tests/routes/pattern.yesodroutes | 1 + 3 files changed, 3 insertions(+) diff --git a/test/tests/routes/handler.yesodroutes b/test/tests/routes/handler.yesodroutes index ce30ff5..17ea4d1 100644 --- a/test/tests/routes/handler.yesodroutes +++ b/test/tests/routes/handler.yesodroutes @@ -1,4 +1,5 @@ -- SYNTAX TEST "source.yesod.routes" "handler" + /foo1 Foo1R GET -- ^^^^^ constant.other.handler /foo2 Foo2R HEAD diff --git a/test/tests/routes/method.yesodroutes b/test/tests/routes/method.yesodroutes index 4a38090..d331e7e 100644 --- a/test/tests/routes/method.yesodroutes +++ b/test/tests/routes/method.yesodroutes @@ -1,4 +1,5 @@ -- SYNTAX TEST "source.yesod.routes" "http methods" + /foo1 Foo1R GET -- ^^^ entity.name.function /foo2 Foo2R HEAD diff --git a/test/tests/routes/pattern.yesodroutes b/test/tests/routes/pattern.yesodroutes index 8a84dc0..5b6eccc 100644 --- a/test/tests/routes/pattern.yesodroutes +++ b/test/tests/routes/pattern.yesodroutes @@ -1,4 +1,5 @@ -- SYNTAX TEST "source.yesod.routes" "pattern" + /foo/bar Foo1R GET /foo/#Text Foo2R GET -- ^^^^^ support.type.patterns From bd245d5e3a0712af73dcb5b2adeaf681fa691ed8 Mon Sep 17 00:00:00 2001 From: isao-takejib Date: Sat, 20 Mar 2021 08:49:04 +0000 Subject: [PATCH 05/10] refactoring --- syntaxes/routes.tmLanguage.json | 52 ++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 21 deletions(-) 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" } ] From 9d1387c0ee5540260ebc8d82c58a20af0217a888 Mon Sep 17 00:00:00 2001 From: isao-takejib Date: Sat, 20 Mar 2021 08:49:35 +0000 Subject: [PATCH 06/10] Add attribute test for yesodroutes --- test/tests/routes/attribute.yesodroutes | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 test/tests/routes/attribute.yesodroutes diff --git a/test/tests/routes/attribute.yesodroutes b/test/tests/routes/attribute.yesodroutes new file mode 100644 index 0000000..1412082 --- /dev/null +++ b/test/tests/routes/attribute.yesodroutes @@ -0,0 +1,10 @@ +-- SYNTAX TEST "source.yesod.routes" "attribute" + +/admin AdminR !admin: +-- ^^^^^^ entity.other.attribute-name + /1 Admin1R GET !1 +-- ^^ entity.other.attribute-name + /2 Admin2R GET !2 +-- ^^ entity.other.attribute-name + /3 Admin3R GET !3 +-- ^^ entity.other.attribute-name From 3a66d84319b8173f63cf0731c406e0550798cf18 Mon Sep 17 00:00:00 2001 From: isao-takejib Date: Sat, 20 Mar 2021 09:05:25 +0000 Subject: [PATCH 07/10] Modify testcase --- test/tests/routes/attribute.yesodroutes | 4 ++++ test/tests/routes/handler.yesodroutes | 8 ++++++++ test/tests/routes/method.yesodroutes | 9 +++++++++ test/tests/routes/pattern.yesodroutes | 10 ++++++++-- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/test/tests/routes/attribute.yesodroutes b/test/tests/routes/attribute.yesodroutes index 1412082..64b5916 100644 --- a/test/tests/routes/attribute.yesodroutes +++ b/test/tests/routes/attribute.yesodroutes @@ -1,10 +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/handler.yesodroutes b/test/tests/routes/handler.yesodroutes index 17ea4d1..fca99d7 100644 --- a/test/tests/routes/handler.yesodroutes +++ b/test/tests/routes/handler.yesodroutes @@ -1,10 +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 index d331e7e..fd4eaf0 100644 --- a/test/tests/routes/method.yesodroutes +++ b/test/tests/routes/method.yesodroutes @@ -1,20 +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 index 5b6eccc..ccf5862 100644 --- a/test/tests/routes/pattern.yesodroutes +++ b/test/tests/routes/pattern.yesodroutes @@ -1,11 +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 \ No newline at end of file +-- <------ - support.type.patterns +-- ^^^^^ support.type.patterns +-- ^^^^^^^^^^ - support.type.patterns \ No newline at end of file From dafccee996da2b957e0d480185d8f4a3fda242ef Mon Sep 17 00:00:00 2001 From: isao-takejib Date: Sat, 20 Mar 2021 09:11:54 +0000 Subject: [PATCH 08/10] Modified changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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 From 57cbaf8f96e0005ea012f89cff1e225b99c27287 Mon Sep 17 00:00:00 2001 From: isao-takejib Date: Sat, 20 Mar 2021 09:17:09 +0000 Subject: [PATCH 09/10] Add routes test to CI --- .github/workflows/vscode-language-yesod-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/vscode-language-yesod-ci.yml b/.github/workflows/vscode-language-yesod-ci.yml index 2c70674..ab3ebc6 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/hamlet.tmLanguage.json -t "test/tests/hamlet/*.yesodroutes" From 1a8b3337eabbbe5326d88ad470ef2c20ebd25d8b Mon Sep 17 00:00:00 2001 From: isao-takejib Date: Sat, 20 Mar 2021 09:18:47 +0000 Subject: [PATCH 10/10] minor fix --- .github/workflows/vscode-language-yesod-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/vscode-language-yesod-ci.yml b/.github/workflows/vscode-language-yesod-ci.yml index ab3ebc6..129854e 100644 --- a/.github/workflows/vscode-language-yesod-ci.yml +++ b/.github/workflows/vscode-language-yesod-ci.yml @@ -38,4 +38,4 @@ jobs: 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/hamlet.tmLanguage.json -t "test/tests/hamlet/*.yesodroutes" + run: npx vscode-tmgrammar-test -s source.yesod.routes -g syntaxes/routes.tmLanguage.json -t "test/tests/routes/*.yesodroutes"