Skip to content

replace all indent tests with i helper #455

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

Merged
merged 1 commit into from
Dec 6, 2018
Merged
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
92 changes: 38 additions & 54 deletions spec/indent/anonymous_functions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,53 @@
require 'spec_helper'

describe 'Indenting anonymous functions' do
context 'single body functions inside do block' do
it 'is declared with fn syntax' do
expect(<<~EOF).to be_elixir_indentation
def do
some_func = fn x -> x end
end
EOF
end
i <<~EOF
def do
some_func = fn x -> x end
end
EOF

it 'is declared with function syntax' do
expect(<<~EOF).to be_elixir_indentation
def do
some_func = function do x -> x end
end
EOF
end
i <<~EOF
def do
some_func = function do x -> x end
end
EOF

it 'spans in multiple lines' do
expect(<<~EOF).to be_elixir_indentation
def test do
assert_raise Queue.Empty, fn ->
Q.new |> Q.deq!
end
end
EOF
i <<~EOF
def test do
assert_raise Queue.Empty, fn ->
Q.new |> Q.deq!
end
end
EOF

it 'spans in multiple lines inside parentheses' do
expect(<<~EOF).to be_elixir_indentation
defmodule Test do
def lol do
Enum.map([1,2,3], fn x ->
x * 3
end)
end
end
EOF
i <<~EOF
defmodule Test do
def lol do
Enum.map([1,2,3], fn x ->
x * 3
end)
end
end
EOF

context 'multiple body functions declaring' do
it 'it with fn syntax' do
expect(<<~EOF).to be_elixir_indentation
fizzbuzz = fn
0, 0, _ -> "FizzBuzz"
0, _, _ -> "Fizz"
_, 0, _ -> "Buzz"
_, _, x -> x
end
EOF
end
i <<~EOF
fizzbuzz = fn
0, 0, _ -> "FizzBuzz"
0, _, _ -> "Fizz"
_, 0, _ -> "Buzz"
_, _, x -> x
end
EOF

it 'it with function syntax' do
expect(<<~EOF).to be_elixir_indentation
fizzbuzz = function do
0, 0, _ -> "FizzBuzz"
0, _, _ -> "Fizz"
_, 0, _ -> "Buzz"
_, _, x -> x
end
EOF
end
i <<~EOF
fizzbuzz = function do
0, 0, _ -> "FizzBuzz"
0, _, _ -> "Fizz"
_, 0, _ -> "Buzz"
_, _, x -> x
end
EOF

i <<~EOF
{:ok, 0} = Mod.exec!(cmd, fn progress ->
Expand Down
142 changes: 60 additions & 82 deletions spec/indent/blocks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,116 +3,94 @@
require 'spec_helper'

describe 'Indenting blocks' do
it "'do' indenting" do
expect(<<~EOF).to be_elixir_indentation
do
something
end
EOF
i <<~EOF
do
something
end
EOF

it 'does not consider :end as end' do
expect(<<~EOF).to be_elixir_indentation
defmodule Test do
def lol do
IO.inspect :end
end
i <<~EOF
defmodule Test do
def lol do
IO.inspect :end
end
EOF
end
EOF

it 'indent inline functions' do
expect(<<~EOF).to be_elixir_indentation
defmodule Hello do
def name, do: IO.puts "bobmarley"
# expect next line starting here
i <<~EOF
defmodule Hello do
def name, do: IO.puts "bobmarley"
# expect next line starting here

def name(param) do
param
end
def name(param) do
param
end
EOF
end
EOF

it 'type inline functions' do
expect(<<~EOF).to be_typed_with_right_indent
defmodule Hello do
def name, do: IO.puts "bobmarley"
i <<~EOF
defmodule Hello do
def name, do: IO.puts "bobmarley"

def name(param) do
param
end
def name(param) do
param
end
EOF
end
EOF

it 'does not consider do: as the start of a block' do
expect(<<~EOF).to be_elixir_indentation
def f do
if true, do: 42
end
EOF
i <<~EOF
def f do
if true, do: 42
end
EOF

it "do not mislead atom ':do'" do
expect(<<~EOF).to be_elixir_indentation
def f do
x = :do
end
EOF
i <<~EOF
def f do
x = :do
end
EOF

it 'multiline assignment' do
expect(<<~EOF).to be_elixir_indentation
defmodule Test do
def test do
one =
user
|> build_assoc(:videos)
|> Video.changeset()

other =
user2
|> build_assoc(:videos)
|> Video.changeset()
end
i <<~EOF
defmodule Test do
def test do
one =
user
|> build_assoc(:videos)
|> Video.changeset()

other =
user2
|> build_assoc(:videos)
|> Video.changeset()
end
EOF
end
EOF

it 'does not indent based on opening symbols inside strings' do
expect(<<~EOF).to be_elixir_indentation
defmodule MyMod do
def how_are_you do
IO.puts "I'm filling bad :("
IO.puts "really bad"
end
i <<~EOF
defmodule MyMod do
def how_are_you do
IO.puts "I'm filling bad :("
IO.puts "really bad"
end
EOF
end
EOF

describe 'indenting while typing' do
it 'close block' do
expect(<<~EOF).to be_typed_with_right_indent
defmodule MyMod do
def how_are_you do
"function return"
end
end
EOF
i <<~EOF
defmodule MyMod do
def how_are_you do
"function return"
end
end
EOF

it 'indenting with a blank line in it' do
expect(<<~EOF).to be_elixir_indentation
scope "/", API do
pipe_through :api # Use the default browser stack
i <<~EOF
scope "/", API do
pipe_through :api # Use the default browser stack

get "/url", Controller, :index
post "/url", Controller, :create
end
EOF
get "/url", Controller, :index
post "/url", Controller, :create
end
EOF

i <<~EOF
def hello do
Expand Down
Loading