-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
648 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" # See documentation for possible values | ||
directory: "/" # Location of package manifests | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: unit-tests | ||
on: [push, pull_request] | ||
jobs: | ||
unit_test: | ||
name: unit_test | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
vim: | ||
- nightly | ||
- v9.0.0000 | ||
os: [ubuntu-latest, macos-latest] | ||
|
||
steps: | ||
|
||
- name: Setup Vim | ||
uses: rhysd/action-setup-vim@v1 | ||
id: vim | ||
with: | ||
version: ${{ matrix.vim }} | ||
|
||
- name: Checkout vim9-conversion-aid plugin code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run Tests | ||
run: | | ||
uname -a | ||
export VIMPRG=${{ steps.vim.outputs.executable }} | ||
$VIMPRG --version | ||
cd test | ||
source ./run_tests.sh 1 | ||
unit_test_windows: | ||
name: unit_test_windows | ||
runs-on: windows-latest | ||
strategy: | ||
matrix: | ||
vim: | ||
- nightly | ||
- v9.0.0000 | ||
|
||
|
||
- name: Setup Vim | ||
uses: rhysd/action-setup-vim@v1 | ||
id: vim | ||
with: | ||
version: ${{ matrix.vim }} | ||
|
||
- name: Checkout vim9-conversion-aid replica plugin code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run Tests | ||
run: | | ||
systeminfo | ||
echo "Vim command setup." | ||
$Env:VIMPRG = "${{ steps.vim.outputs.executable }}" | ||
& $Env:VIMPRG --version | ||
cd test | ||
.\run_tests.cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Tests | ||
|
||
Setup is heavily copied from yegappan/lsp. | ||
|
||
Use sleep in the test_vim9-conversion-aid.vim to see what happens on screen in | ||
combination with sleep. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
vim9scrip | ||
# Common routines used for running the unit tests | ||
|
||
|
||
# The WaitFor*() functions are reused from the Vim test suite. | ||
# | ||
# Wait for up to five seconds for "assert" to return zero. "assert" must be a | ||
# (lambda) function containing one assert function. Example: | ||
# call WaitForAssert({-> assert_equal("dead", job_status(job)}) | ||
# | ||
# A second argument can be used to specify a different timeout in msec. | ||
# | ||
# Return zero for success, one for failure (like the assert function). | ||
export def WaitForAssert(assert: any, ...itemlist: list<number>): number | ||
var timeout = get(itemlist, 0, 5000) | ||
if WaitForCommon(null, assert, timeout) < 0 | ||
return 1 | ||
endif | ||
return 0 | ||
enddef | ||
|
||
# Either "expr" or "assert" is not null | ||
# Return the waiting time for success, -1 for failure. | ||
export def WaitForCommon(Expr: any, Assert: any, timeout: number): number | ||
# using reltime() is more accurate, but not always available | ||
var slept = 0 | ||
var success = false | ||
var starttime = exists('*reltimefloat') ? reltime() : 0 | ||
|
||
while 1 | ||
if typename(Expr) == 'func()' | ||
success = Expr() | ||
elseif type(Assert) == v:t_func | ||
success = Assert() == 0 | ||
else | ||
success = eval(Expr) | ||
endif | ||
if success | ||
return slept | ||
endif | ||
|
||
if slept >= timeout | ||
break | ||
endif | ||
if type(Assert) == v:t_func | ||
# Remove the error added by the assert function. | ||
remove(v:errors, -1) | ||
endif | ||
|
||
sleep 10m | ||
if exists('*reltimefloat') | ||
slept = float2nr(reltimefloat(reltime(starttime)) * 1000) | ||
else | ||
slept += 10 | ||
endif | ||
endwhile | ||
|
||
return -1 # timed out | ||
enddef | ||
|
||
# Wait for up to five seconds for "expr" to become true. "expr" can be a | ||
# stringified expr to evaluate, or a funcref without arguments. | ||
# Using a lambda works best. Example: | ||
# call WaitFor({-> status == "ok"}) | ||
# | ||
# A second argument can be used to specify a different timeout in msec. | ||
# | ||
# When successful the time slept is returned. | ||
# When running into the timeout an exception is thrown, thus the function does | ||
# not return. | ||
export def WaitFor(expr: any, ...itemlist: list<number>) | ||
var timeout = get(itemlist, 0, 5000) | ||
var slept = WaitForCommon(expr, null, timeout) | ||
if slept < 0 | ||
throw 'WaitFor() timed out after ' .. timeout .. ' msec' | ||
endif | ||
return slept | ||
enddef | ||
|
||
|
||
# vim: shiftwidth=2 softtabstop=2 noexpandtab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
vim9script | ||
|
||
# Define a dictionary with the #{ } syntax | ||
g:mydict = {} | ||
|
||
# Add key-value pairs to the dictionary | ||
g:mydict.name = "Vim Script Example" | ||
g:mydict.version = 1.0 | ||
|
||
g:mydict['name'] = "Vim Script Example" | ||
|
||
# Test on random variables defined/updated in a in a messy layout | ||
g:foo = 'potato' | ||
|
||
var s:bar = 'banana' | ||
s:bar = 'strawberry' | ||
|
||
g:one_global_var = 1 | ||
var s:one_list = [-1, 2, 3, 4, 5, 6, 4, 5, 6, 3, 2, 3, 4, 5, 6, 4, 3, 3, 4, 58, 7] | ||
g:one_list_slice = s:one_list[7 : 12] | ||
var s:one_const = 2 | ||
s:one_list[0] = s:one_const | ||
g:one_list_slice = s:one_list[s:one_const: 9] | ||
|
||
g:one_script_var = 'name' | ||
b:one_buffer_var = -99 | ||
|
||
# Test leading-trailing white-space around comparison operators | ||
echom s:bar == 'blueberry' | ||
echom s:bar ==# 'blueberry' | ||
echom s:bar ==? 'blueberry' | ||
echom s:bar != 'blueberry' | ||
echom s:one_list[3] >? s:one_list[4] | ||
echom s:one_list[3] <= s:one_list[4] | ||
echom foo =~? 'carot' | ||
echom foo =~ 'carot' | ||
echom foo !~# 'carot' | ||
|
||
# Test on line continuation | ||
g:another_dict = {'foo': 'FOO', 'bar': s:bar, | ||
'baz': 'BAZ'} | ||
|
||
# Test on booleans | ||
var s:one_boolean = true | ||
s:one_boolean = false | ||
|
||
if s:one_boolean == true | ||
echo "foo" | ||
endif | ||
|
||
if exists('b:one_function') | ||
echom 'foo' | ||
endif | ||
|
||
|
||
# Test functions | ||
# Test on variables shadowing | ||
g:shadow = 2 | ||
var s:shadow = 3 | ||
b:shadow = 4 | ||
|
||
def TestShadow1() | ||
var shadow = 3 | ||
echom shadow | ||
enddef | ||
|
||
def TestShadow2() | ||
s:shadow = 3 | ||
echom s:shadow | ||
enddef | ||
|
||
def TestShadow3(shadow) | ||
s:shadow = a:shadow | ||
var shadow = a:shadow | ||
echom a:shadow | ||
enddef | ||
|
||
TestShadow3(shadow) | ||
TestShadow3(s:shadow) | ||
TestShadow3(b:shadow) | ||
|
||
# Test script/function scopes | ||
def PrintSomeText() | ||
var s:foo = false | ||
if false | ||
echom a.foo | ||
else | ||
echom A.BAR | ||
b:one_buffer_var = -66 | ||
endif | ||
enddef | ||
|
||
# Define a function that takes a dictionary as an argument and prints its content | ||
def PrintDictContent(dict) | ||
echo "Dictionary Content: " | ||
for [key, value] in items(a:dict) | ||
echo key .. ": " .. value | ||
endfor | ||
g:one_global_var = 66 | ||
enddef | ||
|
||
# Define a function that updates a dictionary value | ||
def UpdateDict(dict, key, value) | ||
let a:dict[a:key] = a:value | ||
b:another_buffer_var = 33 | ||
var one_script_var = 'monkey' | ||
enddef | ||
|
||
# Define a function that returns a dictionary | ||
def CreateDict() | ||
var newdict = { key1: "value1", key2: "value2", } | ||
newdict[g:one_global_var] = "one global" | ||
s:bar = 22 | ||
return newdict | ||
enddef | ||
|
||
# Call the functions | ||
PrintDictContent(mydict) | ||
UpdateDict(mydict, 'version', 2.0) | ||
PrintDictContent(mydict) | ||
|
||
g:newdict = CreateDict() | ||
PrintDictContent(newdict) | ||
|
||
# Test on function() removal | ||
w:one_function = PrintDictContent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Test_converted_script(): pass |
Oops, something went wrong.