Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] port tests to run completely in vim #582

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions run_vimtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /usr/bin/env sh
set +xe
vim -c ":so test.vim"
Copy link
Collaborator Author

@jbodah jbodah Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to initialize with clean vimrc

106 changes: 106 additions & 0 deletions test.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
" TODO: @jbodah 2024-09-17: setup path to lookup local git plugin

let s:results = []

func s:assert_equal(testcase, expected, actual)
if (a:actual == a:expected) == 1
call s:record_success(a:testcase, a:expected, a:actual)
else
call s:record_failure(a:testcase, a:expected, a:actual)
end
endfunction

func s:record_success(testcase, expected, actual)
let s:results = s:results + [printf("PASS %s\n", a:testcase['name'])]
" let s:results = s:results + [printf("PASS %s\nwant\n%s\ngot\n\%s\n", a:testcase['name'], a:expected, a:actual)]
endfunction

func s:record_failure(testcase, expected, actual)
let s:results = s:results + [printf("FAIL %s\nwant\n%s\ngot\n\%s\n", a:testcase['name'], a:expected, a:actual)]
endfunction

func s:paste(text)
let @p = a:text
normal V"pP
call setreg("p", [])
endfunction

func s:copy_buffer()
normal ggVG"yy
let l:copied = @y
call setreg("y", [])
return l:copied
endfunction

func s:clear_buffer()
normal ggVGD
endfunction

func s:indent_buffer()
normal ggVG=
endfunction

func s:load_file(name)
return
endfunction

function s:test_indent(testcase)
set ft=elixir
call s:paste(a:testcase['expected'])
let s:expected = s:copy_buffer()

call s:indent_buffer()
let s:actual = s:copy_buffer()

call s:assert_equal(a:testcase, s:expected, s:actual)
endfunction

function s:paste_results()
set ft=none
call s:paste(join(s:results, ""))
endfunction

func s:test_syntax(testcase)
set ft=elixir
call s:paste(a:testcase['body'])

call search(a:testcase['pattern'], 'c')
let l:syngroups = map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
call cursor(0, 0)
let l:i = index(l:syngroups, a:testcase['expected'])
if l:i == -1
call s:record_failure({'name': "test_syntax"}, a:testcase['expected'], l:syngroups)
else
call s:record_success({'name': "test_syntax"}, a:testcase['expected'], l:syngroups)
end
endfunction

let s:indent_testcases = map(readdir("vimtest/indent"), {_, val -> {'name': "vimtest/indent/" . val, 'expected': join(readfile("vimtest/indent/" . val), "\n")}})
" Pin a test by uncommenting the following:
" let s:indent_testcases = [
" \ {'name': "vimtest/indent/indent110.ex", 'expected': join(readfile("vimtest/indent/indent110.ex"), "\n")}
" \ ]

" for tc in s:indent_testcases
" call s:test_indent(tc)
" call s:clear_buffer()
" endfor

let s:syntax_testcases = []
let s:syndir = readdir("vimtest/syntax")
for path in s:syndir
let contents = readfile("vimtest/syntax/" . path)

let pattern = contents[0][2:-1]
let expected = contents[1][2:-1]
let body = join(contents[2:-1], "\n")

let s:syntax_testcases = s:syntax_testcases + [{'body': body, 'pattern': pattern, 'expected': expected}]
endfor

for tc in s:syntax_testcases
call s:test_syntax(tc)
call s:clear_buffer()
endfor

call s:paste_results()
3 changes: 3 additions & 0 deletions vimtest/indent/indent0.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def do
some_func = fn x -> x end
end
3 changes: 3 additions & 0 deletions vimtest/indent/indent1.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def do
some_func = function do x -> x end
end
2 changes: 2 additions & 0 deletions vimtest/indent/indent10.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

defmodule Hello do
5 changes: 5 additions & 0 deletions vimtest/indent/indent100.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule Test do
def lol do
IO.inspect :end
end
end
8 changes: 8 additions & 0 deletions vimtest/indent/indent101.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule Hello do
def name, do: IO.puts "bobmarley"
# expect next line starting here

def name(param) do
param
end
end
7 changes: 7 additions & 0 deletions vimtest/indent/indent102.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule Hello do
def name, do: IO.puts "bobmarley"

def name(param) do
param
end
end
3 changes: 3 additions & 0 deletions vimtest/indent/indent103.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def f do
if true, do: 42
end
3 changes: 3 additions & 0 deletions vimtest/indent/indent104.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def f do
x = :do
end
13 changes: 13 additions & 0 deletions vimtest/indent/indent105.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Test do
def test do
one =
user
|> build_assoc(:videos)
|> Video.changeset()

other =
user2
|> build_assoc(:videos)
|> Video.changeset()
end
end
6 changes: 6 additions & 0 deletions vimtest/indent/indent106.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
defmodule MyMod do
def how_are_you do
IO.puts "I'm filling bad :("
IO.puts "really bad"
end
end
5 changes: 5 additions & 0 deletions vimtest/indent/indent107.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule MyMod do
def how_are_you do
"function return"
end
end
6 changes: 6 additions & 0 deletions vimtest/indent/indent108.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
scope "/", API do
pipe_through :api # Use the default browser stack

get "/url", Controller, :index
post "/url", Controller, :create
end
5 changes: 5 additions & 0 deletions vimtest/indent/indent109.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def hello do
{:ok, _} = TaskRunner.TaskStore.start_link(name: @task_store)
{:ok, _} = Workspace.start_link
{:ok, pending_task_sup} = TaskRunner.PendingTaskSupervisor.start_link
end
2 changes: 2 additions & 0 deletions vimtest/indent/indent11.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
defmodule Hello do
def some_func do
4 changes: 4 additions & 0 deletions vimtest/indent/indent110.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def handle_info(:tick, state = %{policy_iteration: []}) do
state = put_in(state[:policy_iteration], state.policy)
{:noreply, state}
end
6 changes: 6 additions & 0 deletions vimtest/indent/indent111.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
case some_function do
:ok ->
:ok
{ :error, :message } ->
{ :error, :message }
end
8 changes: 8 additions & 0 deletions vimtest/indent/indent112.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
case Connection.open(rabbitmq) do
{:ok, conn} ->
Woody.info "CONNECTION_SUCCESSFUL"
{:ok, chan} = Channel.open(conn)
{:error, error} ->
Woody.info "CONNECTION_FAILED"
:timer.sleep(10000)
end
12 changes: 12 additions & 0 deletions vimtest/indent/indent113.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule M do
defp _fetch(result, key, deep_key) do
case _fetch(result, key) do
{:ok, val} ->
case _fetch(val, deep_key) do
:error -> {:error, :deep}
res -> res
end

:error -> {:error, :shallow}
end
end
8 changes: 8 additions & 0 deletions vimtest/indent/indent114.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
case Connection.open(rabbitmq) do
{:ok, conn} ->
Woody.info "CONNECTION_SUCCESSFUL"
{:ok, chan} = Channel.open(conn)
{:error, error} ->
Woody.info "CONNECTION_FAILED"
:timer.sleep(10000)
end
7 changes: 7 additions & 0 deletions vimtest/indent/indent115.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
decoded_msg = case JSON.decode(msg) do
{:error, _} ->
a = "a"
b = "dasdas"
">#{a}<>#{b}<"
{:ok, decoded} -> decoded
end
8 changes: 8 additions & 0 deletions vimtest/indent/indent116.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
case Repo.insert(changeset) do
{:ok, user} ->
conn
|> put_flash(:info, "%{user.name} created!")
|> redirect(to: user_path(conn, :index))
{:error, changeset} ->
render(conn, "new.html", changeset: changeset)
end
10 changes: 10 additions & 0 deletions vimtest/indent/indent117.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
case st do
sym ->
code = if true do
:ok
else
:error
end
Logger.info(code)
st
end
9 changes: 9 additions & 0 deletions vimtest/indent/indent118.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
case world do
"apple" ->
IO.puts "its an apple"

IO.puts "no really, its an apple"
"orange" ->
IO.puts "its not an apple"
IO.puts "believe it or not"
end
4 changes: 4 additions & 0 deletions vimtest/indent/indent119.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
case o do
a ->
e(fn -> f end)
end
3 changes: 3 additions & 0 deletions vimtest/indent/indent12.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Hello do
def some_func do
end
4 changes: 4 additions & 0 deletions vimtest/indent/indent120.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
case pattern do
:* -> :ok
_ -> :error
end
2 changes: 2 additions & 0 deletions vimtest/indent/indent121.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# do
IO.puts :test
10 changes: 10 additions & 0 deletions vimtest/indent/indent122.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule Foo do
def run do
list =
File.read!("/path/to/file")
|> String.split()
# now start a new line
# used to start here
# but now starts here
end
end
8 changes: 8 additions & 0 deletions vimtest/indent/indent123.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule Foo do
def run(task) when task in [:t1, :t2] do
end

# now starts a new line
# use to start here
# but now starts here
end
7 changes: 7 additions & 0 deletions vimtest/indent/indent124.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
receive do
{{:lock_ready, ^key}, ^pid} ->
after
# NOTE: @jbodah 2017-03-28: we should do some math to adjust the timeout
timeout ->
{:error, :timed_out_waiting_for_lock}
end
4 changes: 4 additions & 0 deletions vimtest/indent/indent125.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cond do
foo -> 1
bar -> 2
end
12 changes: 12 additions & 0 deletions vimtest/indent/indent126.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def handle_call({:release_lock, key}, _from, state) do
case get_lock(state, key) do
nil ->
{:reply, {:error, :already_unlocked}, state}

_ ->
new_state = delete_lock(state, key)
{:reply, :ok, new_state}
end
end

def
47 changes: 47 additions & 0 deletions vimtest/indent/indent127.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
defmodule Hello do
def hello do
end









































def world do
end
end
5 changes: 5 additions & 0 deletions vimtest/indent/indent128.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule Test do
@doc """
end
"""
end
Loading