Organize files
This commit is contained in:
parent
0c4c82e70e
commit
44cc3f3e4a
19 changed files with 6 additions and 8 deletions
20
tests/nvimcfg/init.vim
Normal file
20
tests/nvimcfg/init.vim
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
scriptencoding utf-8
|
||||
|
||||
|
||||
if has('nvim')
|
||||
runtime! plugin/python_setup.vim
|
||||
endif
|
||||
|
||||
call plug#begin('$HOME/.config/nvim/plugged')
|
||||
Plug 'baabelfish/nvim-nim'
|
||||
call plug#end()
|
||||
|
||||
filetype plugin indent on
|
||||
|
||||
if has("multi_byte") && has("starting")
|
||||
if &termencoding == ""
|
||||
let &termencoding = &encoding
|
||||
endif
|
||||
setglobal fileencoding=utf-8
|
||||
scriptencoding utf-8
|
||||
endif
|
||||
9
tests/rc.vim
Normal file
9
tests/rc.vim
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
filetype off
|
||||
set rtp+=./plugins/vader.vim
|
||||
set rtp+=..
|
||||
filetype plugin indent on
|
||||
syntax enable
|
||||
|
||||
set ts=4 sts=4 sw=4
|
||||
|
||||
let g:nvim_nim_enable_async = 0
|
||||
20
tests/run_tests.sh
Executable file
20
tests/run_tests.sh
Executable file
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Intall plugins
|
||||
if [[ ! -d plugins ]]; then
|
||||
mkdir plugins
|
||||
git clone https://github.com/baabelfish/vader.vim plugins/vader.vim
|
||||
fi
|
||||
|
||||
# Run tests
|
||||
# Running test
|
||||
nvim -u rc.vim -c 'Vader! tests/**/*.vader'
|
||||
# nvim -u rc.vim -c 'Vader! tests/**/*.vader' > /dev/null
|
||||
err=$?
|
||||
if [ "$err" != "0" ]; then
|
||||
cat report.log
|
||||
exit 1
|
||||
else
|
||||
echo ""
|
||||
echo "Great success!"
|
||||
fi
|
||||
39
tests/tests/nimsuggest/suggestions.nim
Normal file
39
tests/tests/nimsuggest/suggestions.nim
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import
|
||||
strutils,
|
||||
sequtils,
|
||||
util
|
||||
|
||||
static:
|
||||
test "outline", "tests/tmodule.nim", CompletionV2, 1, 1:
|
||||
assert results.len == 10
|
||||
assert results[1].location == "tmodule.Vec"
|
||||
assert results[1].module == "tmodule"
|
||||
assert results[1].lname == "x"
|
||||
|
||||
# v1 is broken
|
||||
test "use", "tests/tmodule.nim", CompletionV1, 14, 8:
|
||||
assert results.len == 3 # Wrong (only finds results under search)
|
||||
test "use", "tests/tmodule.nim", CompletionV2, 14, 8:
|
||||
assert results.len == 9
|
||||
test "use", "tests/tmodule.nim", CompletionV1, 9, 22:
|
||||
assert results.len == 1 # Wrong
|
||||
test("use", "tests/tmodule.nim", CompletionV2, 9, 22):
|
||||
assert results.len == 9
|
||||
|
||||
# v2 is broken
|
||||
test("def", "tests/tmodule.nim", CompletionV1, 21, 8):
|
||||
assert results.len == 1
|
||||
assert results[0].doc == "\"\""
|
||||
test("def", "tests/tmodule.nim", CompletionV2, 21, 8):
|
||||
assert results.len == 0 # Wrong (should find one)
|
||||
|
||||
test("sug", "tests/tmodule.nim", CompletionV1, 22, 3):
|
||||
assert results.len == 4
|
||||
test("sug", "tests/tmodule.nim", CompletionV2, 22, 3):
|
||||
assert results.len == 4
|
||||
|
||||
# con returns the function def??
|
||||
test("con", "tests/tmodule.nim", CompletionV1, 18, 7):
|
||||
assert results.len == 1
|
||||
test("con", "tests/tmodule.nim", CompletionV2, 18, 7):
|
||||
assert results.len == 1
|
||||
22
tests/tests/nimsuggest/tmodule.nim
Normal file
22
tests/tests/nimsuggest/tmodule.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import
|
||||
tother
|
||||
|
||||
type Vec = object
|
||||
x: int
|
||||
y: int
|
||||
|
||||
proc `$`(x: Vec): string = $x & ":" & $y
|
||||
proc print(x: Vec) = echo x
|
||||
proc sum(a, b: Vec): Vec = Vec(
|
||||
x: a.x + b.x,
|
||||
y: a.y + b.y)
|
||||
|
||||
var a: Vec
|
||||
var b: Vec
|
||||
var z: X
|
||||
|
||||
a.sum(
|
||||
|
||||
asdoifjasdoi # Works after error
|
||||
var x: Vec
|
||||
b.
|
||||
4
tests/tests/nimsuggest/tother.nim
Normal file
4
tests/tests/nimsuggest/tother.nim
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
## A documentation string
|
||||
type X* = int
|
||||
|
||||
5.echo
|
||||
91
tests/tests/nimsuggest/util.nim
Normal file
91
tests/tests/nimsuggest/util.nim
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
import
|
||||
sequtils,
|
||||
strutils
|
||||
|
||||
|
||||
proc last[T](a: seq[T]): T = a[a.len - 1]
|
||||
|
||||
proc slice[T](a: seq[T], hi: static[int]): auto = slice(a, 0, hi)
|
||||
|
||||
proc slice[T](a: seq[T], lo, hi: static[int]): seq[T] =
|
||||
result = @[]
|
||||
let realHi = if hi < 0: a.len + hi else: hi
|
||||
for idx in lo..min(realHi, a.len - 1):
|
||||
result.add(a[idx])
|
||||
|
||||
|
||||
type
|
||||
CompletionV1* = object
|
||||
values: array[10, string]
|
||||
CompletionV2* = object
|
||||
values: array[10, string]
|
||||
Completion* = CompletionV1 | CompletionV2
|
||||
|
||||
|
||||
proc len*(c: Completion): auto = c.values.len
|
||||
proc `$`*(c: seq[Completion]): string =
|
||||
result = ""
|
||||
for r in c:
|
||||
result &= $r & "\n"
|
||||
|
||||
|
||||
# Create accessors for array-types
|
||||
template access(name: expr, idx: static[int]): expr =
|
||||
proc name*(c: Completion): string = c.values[idx]
|
||||
|
||||
access(ctype, 0)
|
||||
access(kind, 1)
|
||||
access(symbol, 2)
|
||||
access(signature, 3)
|
||||
access(file, 4)
|
||||
access(line, 5)
|
||||
access(col, 6)
|
||||
access(doc, 7)
|
||||
access(random, 8)
|
||||
access(`$`, 9)
|
||||
access(str, 9)
|
||||
|
||||
|
||||
proc lname*(c: Completion): string =
|
||||
c.symbol.split(".").last
|
||||
|
||||
proc location*(c: Completion): string =
|
||||
c.symbol.split(".").slice(0, -2).join(".")
|
||||
|
||||
proc module*(c: Completion): string =
|
||||
c.symbol.split(".").slice(0, -3).join(".")
|
||||
|
||||
|
||||
proc cmd*(CT: typedesc, source: string, ctype: string, line, col: int): string {.compileTime.} =
|
||||
when CT is CompletionV1:
|
||||
let paramsV2 = ""
|
||||
else:
|
||||
let paramsV2 = " --v2 "
|
||||
|
||||
"echo \"" &
|
||||
ctype &
|
||||
" " &
|
||||
source &
|
||||
":" & $line & ":" & $col & "\"" &
|
||||
" | nimsuggest --stdin " & paramsV2 & source & "\n"
|
||||
|
||||
|
||||
proc getResults*[T: Completion](f: string, ctype: string, line, col: int = 1): seq[T] {.compileTime.} =
|
||||
result = @[]
|
||||
let command = cmd(T, f, ctype, line, col)
|
||||
let lines = command.staticExec.split("\n")
|
||||
|
||||
for line in lines[4..lines.len - 2]:
|
||||
var completion: T
|
||||
let raw = line.split("\t")
|
||||
for idx in 0..completion.len - 1:
|
||||
if idx < raw.len:
|
||||
completion.values[9] = line
|
||||
completion.values[idx] = raw[idx]
|
||||
result.add(completion)
|
||||
|
||||
|
||||
template test*(name, file: static[string], t: typedesc, line, col: int, body: expr): expr =
|
||||
block:
|
||||
let results {.inject.} = getResults[t](file, name, line, col)
|
||||
body
|
||||
15
tests/tests/vim/definition.vader
Normal file
15
tests/tests/vim/definition.vader
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
Given nim:
|
||||
proc other = "foobar".echo
|
||||
proc hello = "hello".echo
|
||||
|
||||
hello()
|
||||
|
||||
Execute:
|
||||
set buftype=""
|
||||
saveas! vader_workbench.nim
|
||||
w!
|
||||
norm G^
|
||||
NimDefinition
|
||||
|
||||
Then:
|
||||
AssertEqual 2, line(".")
|
||||
26
tests/tests/vim/indent.vader
Normal file
26
tests/tests/vim/indent.vader
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
Given nim:
|
||||
import
|
||||
sequtils,
|
||||
streams
|
||||
|
||||
type Obj = object
|
||||
x, y: int
|
||||
|
||||
proc nope =
|
||||
echo "foobar"
|
||||
nope()
|
||||
|
||||
Do:
|
||||
gg=G
|
||||
|
||||
Expect nim:
|
||||
import
|
||||
sequtils,
|
||||
streams
|
||||
|
||||
type Obj = object
|
||||
x, y: int
|
||||
|
||||
proc nope =
|
||||
echo "foobar"
|
||||
nope()
|
||||
28
tests/tests/vim/smoke.vader
Normal file
28
tests/tests/vim/smoke.vader
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
Given nim:
|
||||
echo "hello"
|
||||
|
||||
Do:
|
||||
gg
|
||||
|
||||
Then:
|
||||
AssertEqual "nim", &filetype
|
||||
Assert exists(":NimDebug") > 0
|
||||
Assert exists(":NimDefinition") > 0
|
||||
Assert exists(":NimInfo") > 0
|
||||
Assert exists(":NimWeb") > 0
|
||||
Assert exists(":NimUsages") > 0
|
||||
Assert exists(":NimUsagesProject") > 0
|
||||
Assert exists(":NimRenameSymbol") > 0
|
||||
Assert exists(":NimRenameSymbolProject") > 0
|
||||
Assert exists(":NimDebug") > 0
|
||||
Assert exists(":NimOutline") > 0
|
||||
Assert exists(":NimOutlineUpdate") > 0
|
||||
|
||||
Given cpp:
|
||||
std::cout << "hello world" << std::endl;
|
||||
|
||||
Do:
|
||||
gg
|
||||
|
||||
Then:
|
||||
AssertEqual "cpp", &filetype
|
||||
24
tests/tests/vim/syntax.vader
Normal file
24
tests/tests/vim/syntax.vader
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Given nim:
|
||||
import
|
||||
sequtils,
|
||||
streams
|
||||
|
||||
type Obj = object
|
||||
x, y: int
|
||||
|
||||
proc nope =
|
||||
echo "foobar"
|
||||
echo "x" == "y"
|
||||
nope()
|
||||
|
||||
|
||||
Execute:
|
||||
AssertEqual SyntaxAt(1, 1), "nimInclude"
|
||||
AssertEqual SyntaxAt(5, 12), "nimStorage"
|
||||
AssertEqual SyntaxAt(5, 1), "nimStorageClass"
|
||||
AssertEqual SyntaxAt(6, 9), "nimBuiltinType"
|
||||
AssertEqual SyntaxAt(8, 1), "nimTypedef"
|
||||
AssertEqual SyntaxAt(9, 3), "nimBuiltinFunction"
|
||||
AssertEqual SyntaxAt(9, 8), "nimString"
|
||||
AssertEqual SyntaxAt(10, 13), "nimOP5"
|
||||
AssertEqual SyntaxAt(11, 1), "nimIdentifier"
|
||||
6
tests/testwatcher.sh
Executable file
6
tests/testwatcher.sh
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
while inotifywait -r -q -e close_write "../autoload" "."
|
||||
do
|
||||
./run_tests.sh
|
||||
sleep 1
|
||||
done
|
||||
87
tests/travis.sh
Executable file
87
tests/travis.sh
Executable file
|
|
@ -0,0 +1,87 @@
|
|||
#!/bin/bash
|
||||
|
||||
current=$PWD
|
||||
|
||||
|
||||
install_nim() {
|
||||
wget "http://nim-lang.org/download/nim-0.13.0.tar.xz" -O nim.tar.xz
|
||||
mkdir nim
|
||||
tar -xvf nim.tar.xz -C nim --strip-components=1
|
||||
cd nim
|
||||
./build.sh
|
||||
export PATH=$PATH:$PWD/bin
|
||||
cd ..
|
||||
}
|
||||
|
||||
install_nimble() {
|
||||
git clone https://github.com/nim-lang/nimble.git
|
||||
cd nimble
|
||||
git clone -b v0.13.0 --depth 1 https://github.com/nim-lang/nim vendor/nim
|
||||
nim c -r src/nimble
|
||||
export PATH=$PATH:$PWD/src
|
||||
cd ..
|
||||
}
|
||||
|
||||
install_nimsuggest() {
|
||||
git clone https://github.com/nim-lang/nimsuggest
|
||||
cd nimsuggest
|
||||
echo "y" | nimble build
|
||||
export PATH=$PATH:$PWD
|
||||
cd ..
|
||||
}
|
||||
|
||||
|
||||
if [[ ! -d "tmp" ]]; then
|
||||
mkdir tmp
|
||||
cd tmp
|
||||
|
||||
echo "Installing nim"
|
||||
install_nim
|
||||
|
||||
echo "Installing nimble"
|
||||
install_nimble
|
||||
|
||||
echo "Installing nimsuggest"
|
||||
install_nimsuggest
|
||||
|
||||
cd ..
|
||||
fi
|
||||
|
||||
export PATH=$PATH:$current/tmp/nim/bin
|
||||
export PATH=$PATH:$current/nimble/src
|
||||
export PATH=$PATH:$current/nimble/nimsuggest
|
||||
|
||||
echo "================================================================================"
|
||||
|
||||
echo -e "\nNeovim:"
|
||||
nvim --version
|
||||
|
||||
echo -e "\nNim:"
|
||||
nim --version
|
||||
|
||||
echo -e "\nNimble:"
|
||||
nimble --version
|
||||
|
||||
echo -e "\nNimsuggest:"
|
||||
nimsuggest --version
|
||||
|
||||
echo "================================================================================"
|
||||
|
||||
cd $current/other
|
||||
curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
|
||||
cp nvimcfg/init.vim ~/.config/nvim/
|
||||
mkdir -p "$HOME/.config/nvim/undodir"
|
||||
mkdir -p "$HOME/.config/nvim/autoload"
|
||||
mkdir -p "$HOME/.config/nvim/view"
|
||||
|
||||
cd ~/.config/nvim
|
||||
mkdir plugged
|
||||
cd plugged
|
||||
git clone https://github.com/baabelfish/nvim-nim
|
||||
tree ~/.config/nvim
|
||||
|
||||
|
||||
echo "================================================================================"
|
||||
echo "Run vim tests"
|
||||
cd $current/other
|
||||
./run_tests.sh
|
||||
Loading…
Add table
Add a link
Reference in a new issue