summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authortatsuya <t2h5k0@gmail.com>2020-12-13 17:06:23 +0900
committertatsuya <t2h5k0@gmail.com>2021-01-23 11:56:10 +0900
commit5a47d878fbb837af4c89ab545f473f8526bd4d64 (patch)
treeef98e0affc0ceff681bcb0386e0bac27b593012e /test
parentc37473630189a597f20016d11ba3ba1ae0bd6923 (diff)
downloadale-5a47d878fbb837af4c89ab545f473f8526bd4d64.zip
add spectral linter for yaml
ci
Diffstat (limited to 'test')
-rw-r--r--test/command_callback/spectral_paths/node_modules/.bin/spectral0
-rw-r--r--test/command_callback/spectral_paths/openapi.yaml0
-rw-r--r--test/command_callback/test_spectral_command_callback.vader31
-rw-r--r--test/handler/test_spectral_handler.vader52
4 files changed, 83 insertions, 0 deletions
diff --git a/test/command_callback/spectral_paths/node_modules/.bin/spectral b/test/command_callback/spectral_paths/node_modules/.bin/spectral
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/spectral_paths/node_modules/.bin/spectral
diff --git a/test/command_callback/spectral_paths/openapi.yaml b/test/command_callback/spectral_paths/openapi.yaml
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/spectral_paths/openapi.yaml
diff --git a/test/command_callback/test_spectral_command_callback.vader b/test/command_callback/test_spectral_command_callback.vader
new file mode 100644
index 00000000..ed3795b9
--- /dev/null
+++ b/test/command_callback/test_spectral_command_callback.vader
@@ -0,0 +1,31 @@
+Before:
+ call ale#assert#SetUpLinterTest('yaml', 'spectral')
+
+After:
+ call ale#assert#TearDownLinterTest()
+
+Execute(The yaml spectral command callback should return the correct default string):
+ AssertLinter 'spectral', ale#Escape('spectral') . ' lint --ignore-unknown-format -q -f text %t'
+
+Execute(The yaml spectral command callback should be configurable):
+ let g:ale_yaml_spectral_executable = '~/.local/bin/spectral'
+
+ AssertLinter '~/.local/bin/spectral',
+ \ ale#Escape('~/.local/bin/spectral')
+ \ . ' lint --ignore-unknown-format -q -f text %t'
+
+Execute(The yaml spectral command callback should allow a global installation to be used):
+ let g:ale_yaml_spectral_executable = '/usr/local/bin/spectral'
+ let g:ale_yaml_spectral_use_global = 1
+
+ AssertLinter '/usr/local/bin/spectral',
+ \ ale#Escape('/usr/local/bin/spectral')
+ \ . ' lint --ignore-unknown-format -q -f text %t'
+
+Execute(The yaml spectral command callback should allow a local installation to be used):
+ call ale#test#SetFilename('spectral_paths/openapi.yaml')
+
+ AssertLinter
+ \ ale#path#Simplify(g:dir . '/spectral_paths/node_modules/.bin/spectral'),
+ \ ale#Escape(ale#path#Simplify(g:dir . '/spectral_paths/node_modules/.bin/spectral'))
+ \ . ' lint --ignore-unknown-format -q -f text %t'
diff --git a/test/handler/test_spectral_handler.vader b/test/handler/test_spectral_handler.vader
new file mode 100644
index 00000000..b315168f
--- /dev/null
+++ b/test/handler/test_spectral_handler.vader
@@ -0,0 +1,52 @@
+Before:
+ runtime ale_linters/yaml/spectral.vim
+
+After:
+ call ale#linter#Reset()
+
+Execute(spectral handler should parse lines correctly):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 1,
+ \ 'col': 1,
+ \ 'code': 'oas3-api-servers',
+ \ 'text': 'OpenAPI `servers` must be present and non-empty array.',
+ \ 'type': 'W'
+ \ },
+ \ {
+ \ 'lnum': 1,
+ \ 'col': 1,
+ \ 'code': 'oas3-schema',
+ \ 'text': 'Object should have required property `paths`.',
+ \ 'type': 'E'
+ \ },
+ \ {
+ \ 'lnum': 1,
+ \ 'col': 1,
+ \ 'code': 'openapi-tags',
+ \ 'text': 'OpenAPI object should have non-empty `tags` array.',
+ \ 'type': 'W'
+ \ },
+ \ {
+ \ 'lnum': 3,
+ \ 'col': 6,
+ \ 'code': 'info-contact',
+ \ 'text': 'Info object should contain `contact` object.',
+ \ 'type': 'W'
+ \ },
+ \ {
+ \ 'lnum': 3,
+ \ 'col': 6,
+ \ 'code': 'oas3-schema',
+ \ 'text': '`info` property should have required property `version`.',
+ \ 'type': 'E'
+ \ },
+ \ ],
+ \ ale_linters#yaml#spectral#Handle(bufnr(''), [
+ \ 'openapi.yml:1:1 warning oas3-api-servers "OpenAPI `servers` must be present and non-empty array."',
+ \ 'openapi.yml:1:1 error oas3-schema "Object should have required property `paths`."',
+ \ 'openapi.yml:1:1 warning openapi-tags "OpenAPI object should have non-empty `tags` array."',
+ \ 'openapi.yml:3:6 warning info-contact "Info object should contain `contact` object."',
+ \ 'openapi.yml:3:6 error oas3-schema "`info` property should have required property `version`."',
+ \ ])