1
0
Fork 0
mirror of synced 2024-11-14 05:08:56 -05:00
ultimate-vim/sources_non_forked/vim-elixir/spec/syntax/variable_spec.rb
2022-05-19 01:31:41 +08:00

75 lines
1.9 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
describe 'Variable syntax' do
it 'unused' do
expect(<<~EOF).to include_elixir_syntax('elixirUnusedVariable', '_from')
def handle_call(:pop, _from, [h|stack]) do
{ :reply, h, stack }
end
EOF
end
it 'unused in function body' do
expect(<<~EOF).not_to include_elixir_syntax('elixirUnusedVariable', '_from')
def handle_call(:pop)
Hello._from
end
EOF
end
it 'unused, multiple lines' do
expect(<<~EOF).to include_elixir_syntax('elixirUnusedVariable', '_from')
def handle_call(:pop,
_from,
[h|stack]) do
{ :reply, h, stack }
end
EOF
end
it 'unused, single char' do
expect(<<~EOF).to include_elixir_syntax('elixirUnusedVariable', '_')
def call(:pop, _, [h|stack]) do
{ :reply, h, stack }
end
EOF
end
it 'unused in pattern_match' do
str = <<~EOF
def sign_in(conn, %{
"data" => %{
"type" => "doctor",
"attributes" => %{
"institution_code" => institution_code,
"password" => password,
"email_or_phone" => email_or_phone}}}, _user, _claims) do
:ok
end
EOF
expect(str).to include_elixir_syntax('elixirUnusedVariable', '_user')
expect(str).to include_elixir_syntax('elixirUnusedVariable', '_claims')
end
it 'unused, in anonymous function, inline' do
expect(<<~EOF).to include_elixir_syntax('elixirUnusedVariable', '_unused')
fun = fn _unused -> false end
EOF
end
it 'unused, in anonymous function, multiple lines' do
expect(<<~EOF).to include_elixir_syntax('elixirUnusedVariable', '_unused')
fun = fn
([], _unused) -> true
end
EOF
end
it 'unused, in pattern matching' do
expect(<<~EOF).to include_elixir_syntax('elixirUnusedVariable', '_unused')
_unused = false
EOF
end
end