Skip to content

Commit

Permalink
Clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Jan 7, 2017
1 parent c9c9c0a commit c27a05b
Showing 1 changed file with 12 additions and 48 deletions.
60 changes: 12 additions & 48 deletions spec/parser/ruby/ruby_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,56 +282,20 @@ def hello; end
end
end

it "\n Parses several formats of percent arrays into source strings\n" \
" in constant declarations. Loops thru all combinations of\n" \
" () {} [] <> || delimiters, %i %I %w %W array types, and five\n" \
" types of element/delimiter whitespace." do
delimiter_h = {
'(' => ')',
'{' => '}',
'[' => ']',
'<' => '>',
'|' => '|'
}

type_h = {
'i' => :qsymbols_literal,
'I' => :symbols_literal,
'w' => :qwords_literal,
'W' => :words_literal
}

str_a = [
'TEST = %{type}[A B C]',
'TEST = %{type}[ A B C ]',
'TEST = %{type}[ \nA \nB \nC \n]',
'TEST = %{type}[\n\nAD\n\nB\n\nC\n\n]',
'TEST = %{type}[\n A\n B\n C\n ]'
]

failed_tests = []

delimiter_h.each do |o, c|
type_h.each do |id, sym|
str_a.each do |str|
str_sub = str.sub(/\{type\}/, id).sub(/\[/, o).sub(/\]/, c)

s = stmt(str_sub.gsub(/\\n/, "\n"))

node = s.jump(sym)
p_source = node.source.gsub(/\n/, '\\n')
if p_source != str_sub[7..-1]
failed_tests << "#{str_sub.ljust(31)} -> #{p_source}"
end
end
{'i' => :qsymbols_literal, 'I' => :symbols_literal,
'w' => :qwords_literal, 'W' => :words_literal}.each do |id, sym|
it "parses %#{id}(...) literals" do
[
"TEST = %#{id}(A B C)",
"TEST = %#{id}( A B C )",
"TEST = %#{id}( \nA \nB \nC \n)",
"TEST = %#{id}(\n\nAD\n\nB\n\nC\n\n)",
"TEST = %#{id}(\n A\n B\n C\n )"
].each do |str|
node = stmt(str).jump(sym)
expect(node.source).to eq(str[/(\%#{id}\(.+\))/m, 1])
end
failed_tests << "\n" unless failed_tests.empty?
end
unless failed_tests.empty?
msg = "Failures:\n#{'-------- INPUT --------'.ljust(36)}" \
"---- OUTPUT -----\n#{failed_tests.join("\n")}"
end
expect(failed_tests).to be_empty, msg
end

it "parses %w() array in constant declaration" do
Expand Down

0 comments on commit c27a05b

Please sign in to comment.