diff --git a/spec/indent/anonymous_functions_spec.rb b/spec/indent/anonymous_functions_spec.rb index a16d9431..0a29890a 100644 --- a/spec/indent/anonymous_functions_spec.rb +++ b/spec/indent/anonymous_functions_spec.rb @@ -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 -> diff --git a/spec/indent/blocks_spec.rb b/spec/indent/blocks_spec.rb index f9ea00b2..740c96e1 100644 --- a/spec/indent/blocks_spec.rb +++ b/spec/indent/blocks_spec.rb @@ -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 diff --git a/spec/indent/case_spec.rb b/spec/indent/case_spec.rb index bf4ce6a5..6c232470 100644 --- a/spec/indent/case_spec.rb +++ b/spec/indent/case_spec.rb @@ -3,71 +3,61 @@ require 'spec_helper' describe 'Indenting case statements' do - it 'case..do..end' do - expect(<<~EOF).to be_elixir_indentation - case some_function do - :ok -> - :ok - { :error, :message } -> - { :error, :message } - end - EOF + i <<~EOF + case some_function do + :ok -> + :ok + { :error, :message } -> + { :error, :message } end + EOF - it 'case..do..end' do - expect(<<~EOF).to be_elixir_indentation - 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 - EOF + i <<~EOF + 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 + EOF - it 'nested case statements' do - expect(<<~EOF).to be_elixir_indentation - 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 + i <<~EOF + 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 + :error -> {:error, :shallow} end - EOF - end - - it 'type case..do..end' do - expect(<<~EOF).to be_typed_with_right_indent - 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 - EOF + EOF + + i <<~EOF + 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 + EOF - it 'with long bodies' do - expect(<<~'EOF').to be_elixir_indentation - decoded_msg = case JSON.decode(msg) do - {:error, _} -> - a = "a" - b = "dasdas" - ">#{a}<>#{b}<" - {:ok, decoded} -> decoded - end - EOF + i <<~'EOF' + decoded_msg = case JSON.decode(msg) do + {:error, _} -> + a = "a" + b = "dasdas" + ">#{a}<>#{b}<" + {:ok, decoded} -> decoded end + EOF i <<~EOF case Repo.insert(changeset) do diff --git a/spec/indent/comment_spec.rb b/spec/indent/comment_spec.rb index a92cf533..5d79f035 100644 --- a/spec/indent/comment_spec.rb +++ b/spec/indent/comment_spec.rb @@ -3,51 +3,43 @@ require 'spec_helper' describe 'Indenting *after* comments' do - it 'commented "do" should not cause next line to indent' do - expect(<<~EOF).to be_elixir_indentation - # do - IO.puts :test - EOF - end + i <<~EOF + # do + IO.puts :test + EOF - it 'aligns comments with pipes' do - expect(<<~EOF).to be_elixir_indentation - 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 + i <<~EOF + 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 - EOF end + EOF - it 'aligns comments after guard clause func' do - expect(<<~EOF).to be_elixir_indentation - 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 + i <<~EOF + defmodule Foo do + def run(task) when task in [:t1, :t2] do end - EOF + + # now starts a new line + # use to start here + # but now starts here end + EOF - it 'comments in after block' do - expect(<<~EOF).to be_elixir_indentation - 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 - EOF + i <<~EOF + 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 + EOF end diff --git a/spec/indent/cond_spec.rb b/spec/indent/cond_spec.rb index 176bf0fb..a6e5b6e5 100644 --- a/spec/indent/cond_spec.rb +++ b/spec/indent/cond_spec.rb @@ -3,12 +3,10 @@ require 'spec_helper' describe 'Indenting cond statements' do - it 'cond..do..end' do - expect(<<~EOF).to be_elixir_indentation - cond do - foo -> 1 - bar -> 2 - end - EOF + i <<~EOF + cond do + foo -> 1 + bar -> 2 end + EOF end diff --git a/spec/indent/documentation_spec.rb b/spec/indent/documentation_spec.rb index a3ccb470..a45372e0 100644 --- a/spec/indent/documentation_spec.rb +++ b/spec/indent/documentation_spec.rb @@ -3,13 +3,11 @@ require 'spec_helper' describe 'Indenting documentation' do - it 'with end keyword' do - expect(<<~EOF).to be_elixir_indentation - defmodule Test do - @doc """ - end - """ + i <<~EOF + defmodule Test do + @doc """ end - EOF + """ end + EOF end diff --git a/spec/indent/ecto_queries_spec.rb b/spec/indent/ecto_queries_spec.rb index 4fca7ba2..639beb60 100644 --- a/spec/indent/ecto_queries_spec.rb +++ b/spec/indent/ecto_queries_spec.rb @@ -3,47 +3,39 @@ require 'spec_helper' describe 'Indenting Ecto queries' do - it 'works correctly' do - expect(<<~EOF).to be_elixir_indentation - 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 + i <<~EOF + 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 - EOF end + EOF - it 'does not affect similar statements that are not queries' do - expect(<<~EOF).to be_elixir_indentation - def smth do - from = 1 - to = 7 - end - EOF - - expect(<<~EOF).to be_elixir_indentation - fromin, - EOF + i <<~EOF + def smth do + from = 1 + to = 7 end + EOF - it 'does not affect single lined queries' do - expect(<<~EOF).to be_elixir_indentation - query = from u in query, select: u.city - EOF - end + i <<~EOF + fromin, + EOF - it 'works correctly with inverted queries' do - expect(<<~EOF).to be_elixir_indentation - 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 - EOF + i <<~EOF + query = from u in query, select: u.city + EOF + + i <<~EOF + 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 + EOF i <<~EOF def alphabetical(query) do diff --git a/spec/indent/if_spec.rb b/spec/indent/if_spec.rb index c0efafc8..92ca685c 100644 --- a/spec/indent/if_spec.rb +++ b/spec/indent/if_spec.rb @@ -3,31 +3,25 @@ require 'spec_helper' describe 'Indenting if clauses' do - it 'if..do..end' do - expect(<<~EOF).to be_elixir_indentation - if foo do - bar - end - EOF + i <<~EOF + if foo do + bar end + EOF - it 'if..do..else..end' do - expect(<<~EOF).to be_elixir_indentation - if foo do - bar - else - baz - end - EOF + i <<~EOF + if foo do + bar + else + baz end + EOF - it 'does not indent keywords in strings' do - expect(<<~EOF).to be_elixir_indentation - def test do - "else" - end - EOF + i <<~EOF + def test do + "else" end + EOF i <<~EOF if true do diff --git a/spec/indent/lists_spec.rb b/spec/indent/lists_spec.rb index f8309f55..fc66d9f7 100644 --- a/spec/indent/lists_spec.rb +++ b/spec/indent/lists_spec.rb @@ -3,233 +3,193 @@ require 'spec_helper' describe 'Indenting lists' do - it 'lists' do - expect(<<~EOF).to be_elixir_indentation - def example do - [ :foo, - :bar, - :baz ] - end - EOF + i <<~EOF + def example do + [ :foo, + :bar, + :baz ] end + EOF - it 'nested list' do - expect(<<~EOF).to be_elixir_indentation + i <<~EOF + [ [ - [ - :foo - ] + :foo ] - EOF - end + ] + EOF - it 'keyword list' do - expect(<<~EOF).to be_elixir_indentation - def project do - [ name: "mix", - version: "0.1.0", - deps: deps ] - end - EOF + i <<~EOF + def project do + [ name: "mix", + version: "0.1.0", + deps: deps ] end + EOF - it 'keyword' do - expect(<<~EOF).to be_elixir_indentation - def config do - [ name: - "John" ] - end - EOF + i <<~EOF + def config do + [ name: + "John" ] end + EOF - it 'list of tuples' do - expect(<<~EOF).to be_elixir_indentation - def test do - [ { :cowboy, github: "extend/cowboy" }, - { :dynamo, "0.1.0-dev", github: "elixir-lang/dynamo" }, - { :ecto, github: "elixir-lang/ecto" }, - { :pgsql, github: "semiocast/pgsql" } ] - end - EOF + i <<~EOF + def test do + [ { :cowboy, github: "extend/cowboy" }, + { :dynamo, "0.1.0-dev", github: "elixir-lang/dynamo" }, + { :ecto, github: "elixir-lang/ecto" }, + { :pgsql, github: "semiocast/pgsql" } ] end + EOF - it 'list of lists' do - expect(<<~EOF).to be_elixir_indentation - def test do - [ [:a, :b, :c], - [:d, :e, :f] ] - end - EOF + i <<~EOF + def test do + [ [:a, :b, :c], + [:d, :e, :f] ] end + EOF - it 'complex list' do - expect(<<~EOF).to be_elixir_indentation - def test do - [ app: :first, - version: "0.0.1", - dynamos: [First.Dynamo], - compilers: [:elixir, :dynamo, :ecto, :app], - env: [prod: [compile_path: "ebin"]], - compile_path: "tmp/first/ebin", - deps: deps ] - end - EOF + i <<~EOF + def test do + [ app: :first, + version: "0.0.1", + dynamos: [First.Dynamo], + compilers: [:elixir, :dynamo, :ecto, :app], + env: [prod: [compile_path: "ebin"]], + compile_path: "tmp/first/ebin", + deps: deps ] end + EOF - it 'lists with line break after square brackets' do - expect(<<~EOF).to be_elixir_indentation - def project do - [ - { :bar, path: "deps/umbrella/apps/bar" }, - { :umbrella, path: "deps/umbrella" } - ] - end - EOF + i <<~EOF + def project do + [ + { :bar, path: "deps/umbrella/apps/bar" }, + { :umbrella, path: "deps/umbrella" } + ] end + EOF - it 'multiple lists with multiline elements' do - expect(<<~EOF).to be_elixir_indentation - def test do - a = [ - %{ - foo: 1, - bar: 2 - } - ] - - b = %{ - [ - :foo, - :bar - ] + i <<~EOF + def test do + a = [ + %{ + foo: 1, + bar: 2 } + ] + b = %{ [ - a, - b + :foo, + :bar ] - end - EOF + } + + [ + a, + b + ] end + EOF - it 'indent function body even when breaking the parameter list in many lines' do - expect(<<~EOF).to be_elixir_indentation - def create(conn, %{ - "grant_type" => "password", - "username" => username, - "password" => password - }) do - 1 - end - EOF + i <<~EOF + def create(conn, %{ + "grant_type" => "password", + "username" => username, + "password" => password + }) do + 1 end + EOF - it 'parameters list in many lines' do - expect(<<~EOF).to be_elixir_indentation - def double(x) do - add( - x, - y - ) - end - EOF - end - - it 'long parameters list in many lines' do - expect(<<~EOF).to be_elixir_indentation - def double(x) do - add( - x, - y, - w, - z - ) - end - EOF - end - - describe 'restore last indentation after multiline lists' do - it 'correct indentation after long parameter list' do - expect(<<~EOF).to be_elixir_indentation - def double(x) do - result = add( - x, - z - ) - div(result, 2) - end - EOF - end + i <<~EOF + def double(x) do + add( + x, + y + ) + end + EOF - it 'correct indentation after long map list' do - expect(<<~EOF).to be_elixir_indentation - defmodule Module do - @person1 { name: "name", - age: 18, - enabled?: true } - @person2 { name: "other name", - age: 21, - enabled?: false } - end - EOF - end + i <<~EOF + def double(x) do + add( + x, + y, + w, + z + ) + end + EOF + + i <<~EOF + def double(x) do + result = add( + x, + z + ) + div(result, 2) + end + EOF + + i <<~EOF + defmodule Module do + @person1 { name: "name", + age: 18, + enabled?: true } + @person2 { name: "other name", + age: 21, + enabled?: false } end + EOF - describe 'mix of opened symbols' do - it 'indents every opened symbol' do - expect(<<~EOF).to be_elixir_indentation - def test_another_feature do - assert json_response(conn, 200) == %{ - "results" => [ - %{ - "id" => result.id, - } - ] + i <<~EOF + def test_another_feature do + assert json_response(conn, 200) == %{ + "results" => [ + %{ + "id" => result.id, } - end - EOF - end + ] + } + end + EOF - it 'reset indentation on not nested lists' do - expect(<<~EOF).to be_elixir_indentation - defmodule Mod do - def test do - foo == %{ - } - - assert json_response == %{ - "id" => "identifier" - } - end - end - EOF + i <<~EOF + defmodule Mod do + def test do + foo == %{ + } + + assert json_response == %{ + "id" => "identifier" + } end end + EOF - it 'reset the indent level afer long parameter list' do - expect(<<~EOF).to be_elixir_indentation - defmodule Mod do - def fun do - json_logger = Keyword.merge(Application.get_env(:logger, :json_logger, []), options) - Application.put_env(:logger, :json_logger, json_logger) - level = Keyword.get(json_logger, :level) + i <<~EOF + defmodule Mod do + def fun do + json_logger = Keyword.merge(Application.get_env(:logger, :json_logger, []), options) + Application.put_env(:logger, :json_logger, json_logger) + level = Keyword.get(json_logger, :level) - %{level: level, output: :console} - end + %{level: level, output: :console} end - EOF end + EOF - it 'reset the indent level after complex list of parameters' do - expect(<<~EOF).to be_elixir_indentation - defmodule Mod do - def fun do - Enum.each(s.routing_keys, fn k -> Queue.bind(chan, s.queue, s.exchange, routing_key: k) end) - Basic.consume(chan, s.queue, nil, no_ack: true) - end + i <<~EOF + defmodule Mod do + def fun do + Enum.each(s.routing_keys, fn k -> Queue.bind(chan, s.queue, s.exchange, routing_key: k) end) + Basic.consume(chan, s.queue, nil, no_ack: true) end - EOF end + EOF i <<~EOF def init(_) do diff --git a/spec/indent/map_spec.rb b/spec/indent/map_spec.rb index bcf36a78..8bfa0da5 100644 --- a/spec/indent/map_spec.rb +++ b/spec/indent/map_spec.rb @@ -3,15 +3,13 @@ require 'spec_helper' describe 'Map indent' do - it 'maps in funcs' do - expect(<<~'EOF').to be_elixir_indentation - DrMock.mock(fn -> - params = %{ + it <<~'EOF' + DrMock.mock(fn -> + params = %{ - } - end) - EOF - end + } + end) + EOF i <<~EOF x = %{ diff --git a/spec/indent/pipeline_spec.rb b/spec/indent/pipeline_spec.rb index 28bfe736..75f5d343 100644 --- a/spec/indent/pipeline_spec.rb +++ b/spec/indent/pipeline_spec.rb @@ -3,154 +3,125 @@ require 'spec_helper' describe 'Indenting pipeline' do - it 'using multiline pipeline' do - expect(<<~EOF).to be_elixir_indentation - "a,b,c,d" - |> String.split(",") - |> Enum.reverse - EOF - end + i <<~EOF + "a,b,c,d" + |> String.split(",") + |> Enum.reverse + EOF + + i <<~EOF + [ h | t ] = "a,b,c,d" + |> String.split(",") + |> Enum.reverse + EOF - it 'attribuition using multline pipeline operator' do - expect(<<~EOF).to be_elixir_indentation + i <<~EOF + def test do [ h | t ] = "a,b,c,d" |> String.split(",") |> Enum.reverse - EOF - end - it 'function with pipeline operator' do - expect(<<~EOF).to be_elixir_indentation - def test do - [ h | t ] = "a,b,c,d" - |> String.split(",") - |> Enum.reverse - - { :ok, h } - end - EOF + { :ok, h } end + EOF - it 'do not breaks on `==`' do - expect(<<~EOF).to be_elixir_indentation - def test do - my_post = Post - |> where([p], p.id == 10) - |> where([p], u.user_id == 1) - |> select([p], p) - end - EOF + i <<~EOF + def test do + my_post = Post + |> where([p], p.id == 10) + |> where([p], u.user_id == 1) + |> select([p], p) end + EOF - it 'pipeline operator with block open' do - expect(<<~EOF).to be_elixir_indentation - def test do - "a,b,c,d" - |> String.split(",") - |> Enum.first - |> case do - "a" -> "A" - _ -> "Z" - end + i <<~EOF + def test do + "a,b,c,d" + |> String.split(",") + |> Enum.first + |> case do + "a" -> "A" + _ -> "Z" end - EOF end + EOF - it 'using a record with pipeline' do - expect(<<~EOF).to be_elixir_indentation - defrecord RECORD, field_a: nil, field_b: nil + i <<~EOF + defrecord RECORD, field_a: nil, field_b: nil - rec = RECORD.new - |> IO.inspect - EOF - end + rec = RECORD.new + |> IO.inspect + EOF - it 'indents pipelines with blocks and symbols' do - expect(<<~EOF).to be_elixir_indentation - defmodule MyMod do - def export_info(users) do - {:ok, infos} = users - |> Enum.map(fn (u) -> do_something(u) end) - |> Enum.map(fn (u) -> - do_even_more(u) - end) - |> finall_thing - - infos - end + i <<~EOF + defmodule MyMod do + def export_info(users) do + {:ok, infos} = users + |> Enum.map(fn (u) -> do_something(u) end) + |> Enum.map(fn (u) -> + do_even_more(u) + end) + |> finall_thing + + infos end - EOF end + EOF - it 'correctly indents pipelines on a string with "=" embedded in it' do - expect(<<~EOF).to be_elixir_indentation - def build_command(input, output) do - "embedded=here" - |> - end - EOF + i <<~EOF + def build_command(input, output) do + "embedded=here" + |> end + EOF - it 'correctly indents pipelines on a charlist with "=" embedded in it' do - expect(<<~EOF).to be_elixir_indentation - def build_command(input, output) do - 'embedded=here' - |> - end - EOF - end + i <<~EOF + def build_command(input, output) do + 'embedded=here' + |> + EOF - it 'correctly indents pipelines on a map with "=>" syntax' do - expect(<<~EOF).to be_elixir_indentation - def build_command(input, output) do - %{:hello => :world} - |> - end - EOF + i <<~EOF + def build_command(input, output) do + %{:hello => :world} + |> end + EOF %w(<= >= == != === !== =~).each do |op| - it "ignores indents with #{op}" do - expect(<<~EOF).to be_elixir_indentation - def build_command(input, output) do - true #{op} false - |> IO.inspect - end - EOF + i <<~EOF + def build_command(input, output) do + true #{op} false + |> IO.inspect end + EOF end - it 'resets the indent after a blank new line' do - expect(<<~EOF).to be_elixir_indentation - upcased_names = names - |> Enum.map(fn name -> - String.upcase(name) - end) + i <<~EOF + upcased_names = names + |> Enum.map(fn name -> + String.upcase(name) + end) - IO.inspect names - EOF - end + IO.inspect names + EOF - it 'resets the indent after a blank line pt. 2' do - expect(<<~EOF).to be_elixir_indentation - upcased_names = names - |> Enum.map(fn name -> - String.upcase(name) end) + i <<~EOF + upcased_names = names + |> Enum.map(fn name -> + String.upcase(name) end) - IO.inspect names - EOF - end + IO.inspect names + EOF - it 'keeps indent after a blank if current starts with pipe' do - expect(<<~EOF).to be_elixir_indentation - upcased_names = names - |> Enum.map(fn name -> - String.upcase(name) - end) + i <<~EOF + upcased_names = names + |> Enum.map(fn name -> + String.upcase(name) + end) - |> do_stuff - EOF - end + |> do_stuff + EOF i <<~EOF def hello do diff --git a/spec/indent/tuples_spec.rb b/spec/indent/tuples_spec.rb index bbe23db9..57e39743 100644 --- a/spec/indent/tuples_spec.rb +++ b/spec/indent/tuples_spec.rb @@ -3,33 +3,27 @@ require 'spec_helper' describe 'Indenting tuples' do - it 'multiline tuple' do - expect(<<~EOF).to be_elixir_indentation - def xpto do - { :a, - :b, - :c } - end - EOF + i <<~EOF + def xpto do + { :a, + :b, + :c } end + EOF - it 'tuples with break line after square brackets' do - expect(<<~EOF).to be_elixir_indentation - def method do - { - :bar, - path: "deps/umbrella/apps/bar" - } - end - EOF + i <<~EOF + def method do + { + :bar, + path: "deps/umbrella/apps/bar" + } end + EOF - it 'tuples with strings with embedded braces' do - expect(<<~EOF).to be_elixir_indentation - x = [ - {:text, "asd {"}, - {:text, "qwe"}, - ] - EOF - end + i <<~EOF + x = [ + {:text, "asd {"}, + {:text, "qwe"}, + ] + EOF end diff --git a/spec/indent/with_spec.rb b/spec/indent/with_spec.rb index 4a9e45a7..23330301 100644 --- a/spec/indent/with_spec.rb +++ b/spec/indent/with_spec.rb @@ -11,50 +11,42 @@ end EOF - it 'with..do..end' do - expect(<<~EOF).to be_elixir_indentation - with {:ok, width} <- Map.fetch(opts, :width), - double_width = width * 2, - {:ok, height} <- Map.fetch(opts, :height) - do - {:ok, double_width * height} - end - EOF - end - - it 'with..do:' do - expect(<<~EOF).to be_elixir_indentation - with {:ok, width} <- Map.fetch(opts, :width), - double_width = width * 2, - {:ok, height} <- Map.fetch(opts, :height), - do: {:ok, double_width * height} - EOF - end - - it 'with..do..else..end' do - expect(<<~EOF).to be_elixir_indentation - with {:ok, width} <- Map.fetch(opts, :width), - {:ok, height} <- Map.fetch(opts, :height) - do - {:ok, width * height} - else - :error -> - {:error, :wrong_data} - end - EOF + i <<~EOF + with {:ok, width} <- Map.fetch(opts, :width), + double_width = width * 2, + {:ok, height} <- Map.fetch(opts, :height) + do + {:ok, double_width * height} end + EOF - it 'with..,do:..,else:..' do - expect(<<~EOF).to be_elixir_indentation + i <<~EOF with {:ok, width} <- Map.fetch(opts, :width), + double_width = width * 2, {:ok, height} <- Map.fetch(opts, :height), - do: - {:ok, - width * height * height * height * height * height * height * height * height * height * - height * height * height * height * height * height * height}, - else: (:error -> {:error, :wrong_data}) - EOF + do: {:ok, double_width * height} + EOF + + i <<~EOF + with {:ok, width} <- Map.fetch(opts, :width), + {:ok, height} <- Map.fetch(opts, :height) + do + {:ok, width * height} + else + :error -> + {:error, :wrong_data} end + EOF + + i <<~EOF + with {:ok, width} <- Map.fetch(opts, :width), + {:ok, height} <- Map.fetch(opts, :height), + do: + {:ok, + width * height * height * height * height * height * height * height * height * height * + height * height * height * height * height * height * height}, + else: (:error -> {:error, :wrong_data}) + EOF i <<~'EOF' # This file is responsible for configuring your application diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 42291a77..01d60634 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,13 +26,12 @@ def type(content) with_file do @vim.normal 'gg' - content.each_line.each_with_index do |line, index| - if index.zero? - @vim.type("i#{line.strip}") - else - @vim.normal 'o' - @vim.type(line.strip) - end + lines = content.each_line + count = lines.count + @vim.type("i") + lines.each_with_index do |line, index| + @vim.type("#{line.strip}") + @vim.type("") if index < count - 1 end end end @@ -239,7 +238,8 @@ def self.new VIM.command('filetype off') VIM.command('filetype plugin indent on') VIM.command('autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o') # disable automatic comment continuation - VIM.normal(":set ignorecase") # make sure we test ignorecase + VIM.command("set ignorecase") # make sure we test ignorecase + VIM.command("set formatoptions-=cro") # disable auto comments on VIM end end