Skip to content

Commit

Permalink
Remove unnecessary PromptRow strcut and boilerplate code
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Jul 14, 2023
1 parent 74211ab commit a897fb0
Showing 1 changed file with 61 additions and 71 deletions.
132 changes: 61 additions & 71 deletions test/irb/test_ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,64 +235,60 @@ def test_symbols

def test_endless_range_at_end_of_line
input_with_prompt = [
PromptRow.new('001:0: :> ', %q(a = 3..)),
PromptRow.new('002:0: :> ', %q()),
['001:0: :> ', %q(a = 3..)],
['002:0: :> ', %q()],
]

lines = input_with_prompt.map(&:content)
expected_prompt_list = input_with_prompt.map(&:prompt)
expected_prompt_list, lines = input_with_prompt.transpose
assert_dynamic_prompt(lines, expected_prompt_list)
end

def test_heredoc_with_embexpr
input_with_prompt = [
PromptRow.new('001:0:":* ', %q(<<A+%W[#{<<B)),
PromptRow.new('002:0:":* ', %q(#{<<C+%W[)),
PromptRow.new('003:0:":* ', %q(a)),
PromptRow.new('004:0:]:* ', %q(C)),
PromptRow.new('005:0:]:* ', %q(a)),
PromptRow.new('006:0:":* ', %q(]})),
PromptRow.new('007:0:":* ', %q(})),
PromptRow.new('008:0:":* ', %q(A)),
PromptRow.new('009:0:]:* ', %q(B)),
PromptRow.new('010:0:]:* ', %q(})),
PromptRow.new('011:0: :> ', %q(])),
PromptRow.new('012:0: :> ', %q()),
]

lines = input_with_prompt.map(&:content)
expected_prompt_list = input_with_prompt.map(&:prompt)
['001:0:":* ', %q(<<A+%W[#{<<B)],
['002:0:":* ', %q(#{<<C+%W[)],
['003:0:":* ', %q(a)],
['004:0:]:* ', %q(C)],
['005:0:]:* ', %q(a)],
['006:0:":* ', %q(]})],
['007:0:":* ', %q(})],
['008:0:":* ', %q(A)],
['009:0:]:* ', %q(B)],
['010:0:]:* ', %q(})],
['011:0: :> ', %q(])],
['012:0: :> ', %q()],
]

expected_prompt_list, lines = input_with_prompt.transpose
assert_dynamic_prompt(lines, expected_prompt_list)
end

def test_heredoc_prompt_with_quotes
input_with_prompt = [
PromptRow.new("001:1:':* ", %q(<<~'A')),
PromptRow.new("002:1:':* ", %q(#{foobar})),
PromptRow.new("003:0: :> ", %q(A)),
PromptRow.new("004:1:`:* ", %q(<<~`A`)),
PromptRow.new("005:1:`:* ", %q(whoami)),
PromptRow.new("006:0: :> ", %q(A)),
PromptRow.new('007:1:":* ', %q(<<~"A")),
PromptRow.new('008:1:":* ', %q(foobar)),
PromptRow.new('009:0: :> ', %q(A)),
]

lines = input_with_prompt.map(&:content)
expected_prompt_list = input_with_prompt.map(&:prompt)
["001:1:':* ", %q(<<~'A')],
["002:1:':* ", %q(#{foobar})],
["003:0: :> ", %q(A)],
["004:1:`:* ", %q(<<~`A`)],
["005:1:`:* ", %q(whoami)],
["006:0: :> ", %q(A)],
['007:1:":* ', %q(<<~"A")],
['008:1:":* ', %q(foobar)],
['009:0: :> ', %q(A)],
]

expected_prompt_list, lines = input_with_prompt.transpose
assert_dynamic_prompt(lines, expected_prompt_list)
end

def test_backtick_method
input_with_prompt = [
PromptRow.new('001:0: :> ', %q(self.`(arg))),
PromptRow.new('002:0: :> ', %q()),
PromptRow.new('003:0: :> ', %q(def `(); end)),
PromptRow.new('004:0: :> ', %q()),
['001:0: :> ', %q(self.`(arg))],
['002:0: :> ', %q()],
['003:0: :> ', %q(def `(); end)],
['004:0: :> ', %q()],
]

lines = input_with_prompt.map(&:content)
expected_prompt_list = input_with_prompt.map(&:prompt)
expected_prompt_list, lines = input_with_prompt.transpose
assert_dynamic_prompt(lines, expected_prompt_list)
end

Expand Down Expand Up @@ -593,8 +589,6 @@ def test_heredoc_keep_indent_spaces
end
end

PromptRow = Struct.new(:prompt, :content)

class MockIO_DynamicPrompt
def initialize(params, &assertion)
@params = params
Expand Down Expand Up @@ -680,57 +674,53 @@ def assert_dynamic_prompt(lines, expected_prompt_list)

def test_dynamic_prompt
input_with_prompt = [
PromptRow.new('001:1: :* ', %q(def hoge)),
PromptRow.new('002:1: :* ', %q( 3)),
PromptRow.new('003:0: :> ', %q(end)),
['001:1: :* ', %q(def hoge)],
['002:1: :* ', %q( 3)],
['003:0: :> ', %q(end)],
]

lines = input_with_prompt.map(&:content)
expected_prompt_list = input_with_prompt.map(&:prompt)
expected_prompt_list, lines = input_with_prompt.transpose
assert_dynamic_prompt(lines, expected_prompt_list)
end

def test_dynamic_prompt_with_double_newline_breaking_code
input_with_prompt = [
PromptRow.new('001:1: :* ', %q(if true)),
PromptRow.new('002:1: :* ', %q(%)),
PromptRow.new('003:1: :* ', %q(;end)),
PromptRow.new('004:1: :* ', %q(;hello)),
PromptRow.new('005:0: :> ', %q(end)),
['001:1: :* ', %q(if true)],
['002:1: :* ', %q(%)],
['003:1: :* ', %q(;end)],
['004:1: :* ', %q(;hello)],
['005:0: :> ', %q(end)],
]

lines = input_with_prompt.map(&:content)
expected_prompt_list = input_with_prompt.map(&:prompt)
expected_prompt_list, lines = input_with_prompt.transpose
assert_dynamic_prompt(lines, expected_prompt_list)
end

def test_dynamic_prompt_with_multiline_literal
input_with_prompt = [
PromptRow.new('001:1: :* ', %q(if true)),
PromptRow.new('002:1:]:* ', %q( %w[)),
PromptRow.new('003:1:]:* ', %q( a)),
PromptRow.new('004:1: :* ', %q( ])),
PromptRow.new('005:1: :* ', %q( b)),
PromptRow.new('006:1:]:* ', %q( %w[)),
PromptRow.new('007:1:]:* ', %q( c)),
PromptRow.new('008:1: :* ', %q( ])),
PromptRow.new('009:0: :> ', %q(end)),
]

lines = input_with_prompt.map(&:content)
expected_prompt_list = input_with_prompt.map(&:prompt)
['001:1: :* ', %q(if true)],
['002:1:]:* ', %q( %w[)],
['003:1:]:* ', %q( a)],
['004:1: :* ', %q( ])],
['005:1: :* ', %q( b)],
['006:1:]:* ', %q( %w[)],
['007:1:]:* ', %q( c)],
['008:1: :* ', %q( ])],
['009:0: :> ', %q(end)],
]

expected_prompt_list, lines = input_with_prompt.transpose
assert_dynamic_prompt(lines, expected_prompt_list)
end

def test_dynamic_prompt_with_blank_line
input_with_prompt = [
PromptRow.new('001:0:]:* ', %q(%w[)),
PromptRow.new('002:0:]:* ', %q()),
PromptRow.new('003:0: :> ', %q(])),
['001:0:]:* ', %q(%w[)],
['002:0:]:* ', %q()],
['003:0: :> ', %q(])],
]

lines = input_with_prompt.map(&:content)
expected_prompt_list = input_with_prompt.map(&:prompt)
expected_prompt_list, lines = input_with_prompt.transpose
assert_dynamic_prompt(lines, expected_prompt_list)
end

Expand Down

0 comments on commit a897fb0

Please sign in to comment.