diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/completion/test_ale_import_command.vader | 4 | ||||
-rw-r--r-- | test/completion/test_completion_events.vader | 4 | ||||
-rw-r--r-- | test/handler/test_bibclean_handler.vader | 57 | ||||
-rwxr-xr-x | test/maven-test-files/maven-java-project/module1/mvnw | 0 | ||||
-rwxr-xr-x | test/maven-test-files/maven-java-project/module1/mvnw.cmd | 0 | ||||
-rw-r--r-- | test/maven-test-files/maven-java-project/module1/pom.xml | 1 | ||||
-rw-r--r-- | test/maven-test-files/maven-java-project/module1/src/main/java/dummy1.java | 0 | ||||
-rw-r--r-- | test/maven-test-files/maven-java-project/module2/pom.xml | 1 | ||||
-rw-r--r-- | test/maven-test-files/maven-java-project/module2/src/main/java/dummy2.java | 0 | ||||
-rwxr-xr-x | test/maven-test-files/mvn | 0 | ||||
-rw-r--r-- | test/maven-test-files/non-maven-project/src/main/java/dummy.java | 0 | ||||
-rw-r--r-- | test/test_code_action.vader | 76 | ||||
-rw-r--r-- | test/test_maven_build_classpath_command.vader | 48 | ||||
-rw-r--r-- | test/test_maven_find_executable.vader | 46 | ||||
-rw-r--r-- | test/test_maven_find_project_root.vader | 28 | ||||
-rw-r--r-- | test/test_organize_imports.vader | 4 | ||||
-rw-r--r-- | test/test_rename.vader | 10 |
17 files changed, 235 insertions, 44 deletions
diff --git a/test/completion/test_ale_import_command.vader b/test/completion/test_ale_import_command.vader index 2ba9b8d7..d36caae2 100644 --- a/test/completion/test_ale_import_command.vader +++ b/test/completion/test_ale_import_command.vader @@ -65,8 +65,8 @@ Before: return g:server_started_value endfunction - function! ale#code_action#HandleCodeAction(code_action, should_save) abort - Assert !a:should_save + function! ale#code_action#HandleCodeAction(code_action, options) abort + Assert !get(a:options, 'should_save') call add(g:code_action_list, a:code_action) endfunction diff --git a/test/completion/test_completion_events.vader b/test/completion/test_completion_events.vader index f678e773..30bf603c 100644 --- a/test/completion/test_completion_events.vader +++ b/test/completion/test_completion_events.vader @@ -50,8 +50,8 @@ Before: let g:handle_code_action_called = 0 function! MockHandleCodeAction() abort " delfunction! ale#code_action#HandleCodeAction - function! ale#code_action#HandleCodeAction(action, should_save) abort - AssertEqual v:false, a:should_save + function! ale#code_action#HandleCodeAction(action, options) abort + Assert !get(a:options, 'should_save') let g:handle_code_action_called += 1 endfunction endfunction diff --git a/test/handler/test_bibclean_handler.vader b/test/handler/test_bibclean_handler.vader index 6179d7f5..9da52a92 100644 --- a/test/handler/test_bibclean_handler.vader +++ b/test/handler/test_bibclean_handler.vader @@ -4,7 +4,7 @@ Before: After: call ale#linter#Reset() -Execute(The bibclean handler should parse lines correctly): +Execute(The bibclean handler should parse lines from bibclean <= v2.11.4 correctly): AssertEqual \ [ @@ -19,6 +19,12 @@ Execute(The bibclean handler should parse lines correctly): \ 'type': 'E', \ 'text': 'Expected comma after last field ``keywords''''.', \ 'col': ' 1' + \ }, + \ { + \ 'lnum': '176', + \ 'type': 'W', + \ 'text': 'Unexpected DOI in URL value ``"https://doi.org/DOI"'''': move to separate DOI = "..." key/value in this entry.', + \ 'col': '14' \ } \ ], \ ale_linters#bib#bibclean#Handle(255, [ @@ -31,5 +37,52 @@ Execute(The bibclean handler should parse lines correctly): \ "?? File positions: input [main.bib] output [stdout]", \ "?? Entry input byte=2145 line=63 column= 1 output byte=2146 line=63 column= 0", \ "?? Value input byte=2528 line=71 column= 2 output byte=2527 line=70 column=49", - \ "?? Current input byte=2529 line=71 column= 3 output byte=2528 line=70 column=50" + \ "?? Current input byte=2529 line=71 column= 3 output byte=2528 line=70 column=50", + \ "%% \"stdin\", line 176: Unexpected DOI in URL value ``\"https://doi.org/DOI\"'': move to separate DOI = \"...\" key/value in this entry.", + \ "%% File positions: input [stdin] output [stdout]", + \ "%% Entry input byte=6813 line=174 column= 1 output byte=8543 line=227 column= 0", + \ "%% Value input byte=6890 line=176 column=14 output byte=8641 line=229 column=17", + \ "%% Current input byte=6938 line=176 column=62 output byte=8641 line=229 column=17" + \ ]) + +Execute(The bibclean handler should parse lines of bibclean > v2.11.4 correctly): + + AssertEqual + \ [ + \ { + \ 'lnum': '60', + \ 'type': 'W', + \ 'text': 'Unexpected value in ``month = "09"''''.', + \ 'col': '17' + \ }, + \ { + \ 'lnum': '63', + \ 'type': 'E', + \ 'text': 'Expected comma after last field ``keywords''''.', + \ 'col': ' 1' + \ }, + \ { + \ 'lnum': '176', + \ 'type': 'W', + \ 'text': 'Unexpected DOI in URL value ``"https://doi.org/DOI"'''': move to separate DOI = "..." key/value in this entry.', + \ 'col': '14' + \ } + \ ], + \ ale_linters#bib#bibclean#Handle(255, [ + \ "%% stdin:60:Unexpected value in ``month = \"09\"''.", + \ "%% File positions: input [main.bib] output [stdout]", + \ "%% Entry input byte=1681 line=50 column= 1 output byte=1680 line=50 column= 0", + \ "%% Value input byte=2137 line=60 column=17 output byte=2137 line=60 column=17", + \ "%% Current input byte=2139 line=60 column=19 output byte=2137 line=60 column=17", + \ "?? stdin:71:Expected comma after last field ``keywords''.", + \ "?? File positions: input [main.bib] output [stdout]", + \ "?? Entry input byte=2145 line=63 column= 1 output byte=2146 line=63 column= 0", + \ "?? Value input byte=2528 line=71 column= 2 output byte=2527 line=70 column=49", + \ "?? Current input byte=2529 line=71 column= 3 output byte=2528 line=70 column=50", + \ "%% stdin:176:Unexpected DOI in URL value ``\"https://doi.org/DOI\"'': move to separate DOI = \"...\" key/value in this entry.", + \ "%% File positions: input [stdin] output [stdout]", + \ "%% Entry input byte=6813 line=174 column= 1 output byte=8543 line=227 column= 0", + \ "%% Value input byte=6890 line=176 column=14 output byte=8641 line=229 column=17", + \ "%% Current input byte=6938 line=176 column=62 output byte=8641 line=229 column=17" \ ]) + diff --git a/test/maven-test-files/maven-java-project/module1/mvnw b/test/maven-test-files/maven-java-project/module1/mvnw new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/test/maven-test-files/maven-java-project/module1/mvnw diff --git a/test/maven-test-files/maven-java-project/module1/mvnw.cmd b/test/maven-test-files/maven-java-project/module1/mvnw.cmd new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/test/maven-test-files/maven-java-project/module1/mvnw.cmd diff --git a/test/maven-test-files/maven-java-project/module1/pom.xml b/test/maven-test-files/maven-java-project/module1/pom.xml new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/maven-test-files/maven-java-project/module1/pom.xml @@ -0,0 +1 @@ + diff --git a/test/maven-test-files/maven-java-project/module1/src/main/java/dummy1.java b/test/maven-test-files/maven-java-project/module1/src/main/java/dummy1.java new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/maven-test-files/maven-java-project/module1/src/main/java/dummy1.java diff --git a/test/maven-test-files/maven-java-project/module2/pom.xml b/test/maven-test-files/maven-java-project/module2/pom.xml new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/maven-test-files/maven-java-project/module2/pom.xml @@ -0,0 +1 @@ + diff --git a/test/maven-test-files/maven-java-project/module2/src/main/java/dummy2.java b/test/maven-test-files/maven-java-project/module2/src/main/java/dummy2.java new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/maven-test-files/maven-java-project/module2/src/main/java/dummy2.java diff --git a/test/maven-test-files/mvn b/test/maven-test-files/mvn new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/test/maven-test-files/mvn diff --git a/test/maven-test-files/non-maven-project/src/main/java/dummy.java b/test/maven-test-files/non-maven-project/src/main/java/dummy.java new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/maven-test-files/non-maven-project/src/main/java/dummy.java diff --git a/test/test_code_action.vader b/test/test_code_action.vader index 19de7268..2e5d1381 100644 --- a/test/test_code_action.vader +++ b/test/test_code_action.vader @@ -85,7 +85,8 @@ Execute(It should modify and save multiple files): \ 'import D from "D"', \], g:file2, 'S') - call ale#code_action#HandleCodeAction({ + call ale#code_action#HandleCodeAction( + \ { \ 'changes': [{ \ 'fileName': g:file1, \ 'textChanges': [{ @@ -122,8 +123,10 @@ Execute(It should modify and save multiple files): \ }, \ 'newText': "import {A, B} from 'module'\n\n", \ }] - \ }], - \}, v:true) + \ }], + \ }, + \ {'should_save': 1}, + \) AssertEqual [ \ 'class Value {', @@ -153,7 +156,8 @@ Execute(Beginning of file can be modified): \] call writefile(g:test.text, g:file1, 'S') - call ale#code_action#HandleCodeAction({ + call ale#code_action#HandleCodeAction( + \ { \ 'changes': [{ \ 'fileName': g:file1, \ 'textChanges': [{ @@ -168,7 +172,9 @@ Execute(Beginning of file can be modified): \ 'newText': "type A: string\ntype B: number\n", \ }], \ }] - \}, v:true) + \ }, + \ {'should_save': 1}, + \) AssertEqual [ \ 'type A: string', @@ -184,22 +190,25 @@ Execute(End of file can be modified): \] call writefile(g:test.text, g:file1, 'S') - call ale#code_action#HandleCodeAction({ + call ale#code_action#HandleCodeAction( + \ { \ 'changes': [{ - \ 'fileName': g:file1, - \ 'textChanges': [{ - \ 'start': { - \ 'line': 4, - \ 'offset': 1, - \ }, - \ 'end': { - \ 'line': 4, - \ 'offset': 1, - \ }, - \ 'newText': "type A: string\ntype B: number\n", - \ }], + \ 'fileName': g:file1, + \ 'textChanges': [{ + \ 'start': { + \ 'line': 4, + \ 'offset': 1, + \ }, + \ 'end': { + \ 'line': 4, + \ 'offset': 1, + \ }, + \ 'newText': "type A: string\ntype B: number\n", + \ }], \ }] - \}, v:true) + \ }, + \ {'should_save': 1}, + \) AssertEqual g:test.text + [ \ 'type A: string', @@ -219,7 +228,8 @@ Execute(Current buffer contents will be reloaded): execute 'edit ' . g:file1 let g:test.buffer = bufnr(g:file1) - call ale#code_action#HandleCodeAction({ + call ale#code_action#HandleCodeAction( + \ { \ 'changes': [{ \ 'fileName': g:file1, \ 'textChanges': [{ @@ -234,7 +244,9 @@ Execute(Current buffer contents will be reloaded): \ 'newText': "type A: string\ntype B: number\n", \ }], \ }] - \}, v:true) + \ }, + \ {'should_save': 1}, + \) AssertEqual [ \ 'type A: string', @@ -256,11 +268,11 @@ Execute(Cursor will not move when it is before text change): let g:test.changes = g:test.create_change(2, 3, 2, 8, 'value2') call setpos('.', [0, 1, 1, 0]) - call ale#code_action#HandleCodeAction(g:test.changes, v:true) + call ale#code_action#HandleCodeAction(g:test.changes, {'should_save': 1}) AssertEqual [1, 1], getpos('.')[1:2] call setpos('.', [0, 2, 2, 0]) - call ale#code_action#HandleCodeAction(g:test.changes, v:true) + call ale#code_action#HandleCodeAction(g:test.changes, {'should_save': 1}) AssertEqual [2, 2], getpos('.')[1:2] # ====C==== @@ -271,7 +283,7 @@ Execute(Cursor column will move to the change end when cursor between start/end) call WriteFileAndEdit() call setpos('.', [0, 2, r, 0]) AssertEqual ' value: string', getline('.') - call ale#code_action#HandleCodeAction(g:test.changes, v:true) + call ale#code_action#HandleCodeAction(g:test.changes, {'should_save': 1}) AssertEqual ' value2: string', getline('.') AssertEqual [2, 9], getpos('.')[1:2] endfor @@ -283,7 +295,9 @@ Execute(Cursor column will move back when new text is shorter): call setpos('.', [0, 2, 8, 0]) AssertEqual ' value: string', getline('.') call ale#code_action#HandleCodeAction( - \ g:test.create_change(2, 3, 2, 8, 'val'), v:true) + \ g:test.create_change(2, 3, 2, 8, 'val'), + \ {'should_save': 1}, + \) AssertEqual ' val: string', getline('.') AssertEqual [2, 6], getpos('.')[1:2] @@ -295,7 +309,7 @@ Execute(Cursor column will move forward when new text is longer): call setpos('.', [0, 2, 8, 0]) AssertEqual ' value: string', getline('.') call ale#code_action#HandleCodeAction( - \ g:test.create_change(2, 3, 2, 8, 'longValue'), v:true) + \ g:test.create_change(2, 3, 2, 8, 'longValue'), {'should_save': 1}) AssertEqual ' longValue: string', getline('.') AssertEqual [2, 12], getpos('.')[1:2] @@ -307,7 +321,7 @@ Execute(Cursor line will move when updates are happening on lines above): call setpos('.', [0, 3, 1, 0]) AssertEqual '}', getline('.') call ale#code_action#HandleCodeAction( - \ g:test.create_change(1, 1, 2, 1, "test\ntest\n"), v:true) + \ g:test.create_change(1, 1, 2, 1, "test\ntest\n"), {'should_save': 1}) AssertEqual '}', getline('.') AssertEqual [4, 1], getpos('.')[1:2] @@ -319,7 +333,7 @@ Execute(Cursor line and column will move when change on lines above and just bef call setpos('.', [0, 2, 2, 0]) AssertEqual ' value: string', getline('.') call ale#code_action#HandleCodeAction( - \ g:test.create_change(1, 1, 2, 1, "test\ntest\n123"), v:true) + \ g:test.create_change(1, 1, 2, 1, "test\ntest\n123"), {'should_save': 1}) AssertEqual '123 value: string', getline('.') AssertEqual [3, 5], getpos('.')[1:2] @@ -331,7 +345,7 @@ Execute(Cursor line and column will move at the end of changes): call setpos('.', [0, 2, 10, 0]) AssertEqual ' value: string', getline('.') call ale#code_action#HandleCodeAction( - \ g:test.create_change(1, 1, 3, 1, "test\n"), v:true) + \ g:test.create_change(1, 1, 3, 1, "test\n"), {'should_save': 1}) AssertEqual '}', getline('.') AssertEqual [2, 1], getpos('.')[1:2] @@ -342,14 +356,14 @@ Execute(Cursor will not move when changes happening on lines >= cursor, but afte call setpos('.', [0, 2, 3, 0]) AssertEqual ' value: string', getline('.') call ale#code_action#HandleCodeAction( - \ g:test.create_change(2, 10, 3, 1, "number\n"), v:true) + \ g:test.create_change(2, 10, 3, 1, "number\n"), {'should_save': 1}) AssertEqual ' value: number', getline('.') AssertEqual [2, 3], getpos('.')[1:2] Execute(It should just modify file when should_save is set to v:false): call WriteFileAndEdit() let g:test.change = g:test.create_change(1, 1, 1, 1, "import { writeFile } from 'fs';\n") - call ale#code_action#HandleCodeAction(g:test.change, v:false) + call ale#code_action#HandleCodeAction(g:test.change, {}) AssertEqual 1, getbufvar(bufnr(''), '&modified') AssertEqual [ \ 'import { writeFile } from ''fs'';', diff --git a/test/test_maven_build_classpath_command.vader b/test/test_maven_build_classpath_command.vader new file mode 100644 index 00000000..2d8b38a5 --- /dev/null +++ b/test/test_maven_build_classpath_command.vader @@ -0,0 +1,48 @@ +Before: + Save $PATH + Save $PATHEXT + + let $PATHEXT = '.' + + call ale#test#SetDirectory('/testplugin/test') + runtime ale_linters/java/javac.vim + let g:expected_wrapper = '' + if has('unix') + let g:expected_wrapper = 'mvnw' + else + let g:expected_wrapper = 'mvnw.cmd' + endif + +After: + Restore + + unlet! g:expected_wrapper + + call ale#test#RestoreDirectory() + call ale#linter#Reset() + +Execute(Should use 'mvnw' in classpath command if available): + call ale#test#SetFilename('maven-test-files/maven-java-project/module1/src/main/java/dummy1.java') + + AssertEqual + \ ale#path#CdString(ale#path#Simplify(g:dir . '/maven-test-files/maven-java-project/module1')) + \ . ale#path#Simplify(g:dir . '/maven-test-files/maven-java-project/module1/' . g:expected_wrapper) + \ . ' dependency:build-classpath', + \ ale#maven#BuildClasspathCommand(bufnr('')) + +Execute(Should use 'mvn' in classpath command if it is executable and 'mvnw' is unavailable): + call ale#test#SetFilename('maven-test-files/maven-java-project/module2/src/main/java/dummy2.java') + let $PATH .= (has('win32') ? ';' : ':') + \ . ale#path#Simplify(g:dir . '/maven-test-files') + + AssertEqual + \ ale#path#CdString(ale#path#Simplify(g:dir . '/maven-test-files/maven-java-project/module2')) + \ . 'mvn dependency:build-classpath', + \ ale#maven#BuildClasspathCommand(bufnr('')) + +Execute(Should return empty string if maven cannot be executed): + call ale#test#SetFilename('maven-test-files/non-maven-project/src/main/java/dummy.java') + + AssertEqual + \ '', + \ ale#maven#BuildClasspathCommand(bufnr('')) diff --git a/test/test_maven_find_executable.vader b/test/test_maven_find_executable.vader new file mode 100644 index 00000000..1d2f6da2 --- /dev/null +++ b/test/test_maven_find_executable.vader @@ -0,0 +1,46 @@ +Before: + Save $PATH + Save $PATHEXT + + " Count the maven executable without .exe as executable on Windows + let $PATHEXT = '.' + + call ale#test#SetDirectory('/testplugin/test') + runtime ale_linters/java/javac.vim + let g:expected_wrapper = '' + if has('unix') + let g:expected_wrapper = 'mvnw' + else + let g:expected_wrapper = 'mvnw.cmd' + endif + +After: + Restore + + unlet! g:expected_wrapper + + call ale#test#RestoreDirectory() + call ale#linter#Reset() + +Execute(Should return 'mvnw' if found in parent directory): + call ale#test#SetFilename('maven-test-files/maven-java-project/module1/src/main/java/dummy1.java') + + AssertEqual + \ ale#path#Simplify(g:dir . '/maven-test-files/maven-java-project/module1/' . g:expected_wrapper), + \ ale#maven#FindExecutable(bufnr('')) + +Execute(Should return 'mvn' if 'mvnw' not found in parent directory): + call ale#test#SetFilename('maven-test-files/maven-java-project/module2/src/main/java/dummy2.java') + let $PATH .= (has('win32') ? ';' : ':') + \ . ale#path#Simplify(g:dir . '/maven-test-files') + + AssertEqual + \ 'mvn', + \ ale#maven#FindExecutable(bufnr('')) + +Execute(Should return empty string if 'mvnw' not in parent directory and mvn not in path): + call ale#test#SetFilename('mvn-test-files/java-maven-project/module2/src/main/java/dummy2.java') + + AssertEqual + \ '', + \ ale#gradle#FindExecutable(bufnr('')) diff --git a/test/test_maven_find_project_root.vader b/test/test_maven_find_project_root.vader new file mode 100644 index 00000000..3a2138d1 --- /dev/null +++ b/test/test_maven_find_project_root.vader @@ -0,0 +1,28 @@ +Before: + call ale#test#SetDirectory('/testplugin/test') + runtime ale_linters/kotlin/javac.vim + +After: + call ale#test#RestoreDirectory() + call ale#linter#Reset() + +Execute(Should return directory for 'mvnw' if found in parent directory): + call ale#test#SetFilename('maven-test-files/maven-java-project/module1/src/main/java/dummy1.java') + + AssertEqual + \ ale#path#Simplify(g:dir . '/maven-test-files/maven-java-project/module1'), + \ ale#maven#FindProjectRoot(bufnr('')) + +Execute(Should return directory for 'pom.xml' if found in parent directory): + call ale#test#SetFilename('maven-test-files/maven-java-project/module2/src/main/java/dummy2.java') + + AssertEqual + \ ale#path#Simplify(g:dir . '/maven-test-files/maven-java-project/module2'), + \ ale#maven#FindProjectRoot(bufnr('')) + +Execute(Should return empty string if maven files are not found in parent directory): + call ale#test#SetFilename('maven-test-files/non-maven-project/src/main/java/dummy.java') + + AssertEqual + \ '', + \ ale#maven#FindProjectRoot(bufnr('')) diff --git a/test/test_organize_imports.vader b/test/test_organize_imports.vader index c51ff1c0..35cd99ff 100644 --- a/test/test_organize_imports.vader +++ b/test/test_organize_imports.vader @@ -57,9 +57,9 @@ Before: call add(g:expr_list, a:expr) endfunction - function! ale#code_action#HandleCodeAction(code_action, should_save) abort + function! ale#code_action#HandleCodeAction(code_action, options) abort let g:handle_code_action_called = 1 - AssertEqual v:false, a:should_save + Assert !get(a:options, 'should_save') call add(g:code_actions, a:code_action) endfunction diff --git a/test/test_rename.vader b/test/test_rename.vader index 34d9e32e..2e8b746e 100644 --- a/test/test_rename.vader +++ b/test/test_rename.vader @@ -57,9 +57,9 @@ Before: call add(g:expr_list, a:expr) endfunction - function! ale#code_action#HandleCodeAction(code_action, should_save) abort + function! ale#code_action#HandleCodeAction(code_action, options) abort let g:handle_code_action_called = 1 - AssertEqual v:true, a:should_save + Assert get(a:options, 'should_save') call add(g:code_actions, a:code_action) endfunction @@ -269,7 +269,7 @@ Execute(tsserver rename requests should be sent): \ }] \ ], \ g:message_list - AssertEqual {'42': {'old_name': 'somelongerline', 'new_name': 'a-new-name'}}, + AssertEqual {'42': {'old_name': 'somelongerline', 'new_name': 'a-new-name', 'force_save': 0}}, \ ale#rename#GetMap() Given python(Some Python file): @@ -470,7 +470,7 @@ Execute(LSP rename requests should be sent): let b:ale_linters = ['pyls'] call setpos('.', [bufnr(''), 1, 5, 0]) - ALERename + ALERename! " We shouldn't register the callback yet. AssertEqual '''''', string(g:Callback) @@ -500,5 +500,5 @@ Execute(LSP rename requests should be sent): \ ], \ g:message_list - AssertEqual {'42': {'old_name': 'foo', 'new_name': 'a-new-name'}}, + AssertEqual {'42': {'old_name': 'foo', 'new_name': 'a-new-name', 'force_save': 1}}, \ ale#rename#GetMap() |