Skip to content

Commit

Permalink
port indent tests to run completely in vim
Browse files Browse the repository at this point in the history
  • Loading branch information
jbodah committed Sep 18, 2024
1 parent 39cfaec commit e4db0da
Show file tree
Hide file tree
Showing 232 changed files with 1,874 additions and 0 deletions.
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"
64 changes: 64 additions & 0 deletions test.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
" 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
" let s:results = s:results + [printf("PASS %s", a:testcase['name'])]
else
let s:results = s:results + [printf("FAIL %s\nwant\n%s\ngot\n\%s\n", a:testcase['name'], a:expected, a:actual)]
end
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 join(readfile(a:name), "\n")
endfunction

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

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

for tc in s:testcases
call s:test_indent(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
6 changes: 6 additions & 0 deletions vimtest/indent/indent129.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
defmodule Test do
@doc """
it should
have reasonable
default start indent when typed
"""
4 changes: 4 additions & 0 deletions vimtest/indent/indent13.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
defmodule Hello do
def some_func do
end
end
7 changes: 7 additions & 0 deletions vimtest/indent/indent130.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule New do
def do_query do
from user in Users,
select: user.name,
join: signup in Signups, where: user.id == signup.user_id
end
end
4 changes: 4 additions & 0 deletions vimtest/indent/indent131.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def smth do
from = 1
to = 7
end
1 change: 1 addition & 0 deletions vimtest/indent/indent132.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fromin,
1 change: 1 addition & 0 deletions vimtest/indent/indent133.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
query = from u in query, select: u.city
6 changes: 6 additions & 0 deletions vimtest/indent/indent134.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def do_query do
where = [category: "fresh and new"]
order_by = [desc: :published_at]
select = [:id, :title, :body]
from Post, where: ^where, order_by: ^order_by, select: ^select
end
3 changes: 3 additions & 0 deletions vimtest/indent/indent135.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def alphabetical(query) do
from c in query, order_by: c.name
end
Loading

0 comments on commit e4db0da

Please sign in to comment.