Skip to content

Commit

Permalink
convert the original ZK tests to Cucumber
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Dec 16, 2014
1 parent 447b901 commit 38d8023
Show file tree
Hide file tree
Showing 12 changed files with 820 additions and 0 deletions.
75 changes: 75 additions & 0 deletions features/ops_assignments.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Feature: assignments

Scenario: manages niceness correctly in presence of `&&=`
Given the original code is
"""
nice1 = true
nice2 = true
ugly1 = nil
ugly2 = nil
nice1 &&= true
nice2 &&= nil
ugly1 &&= true
ugly2 &&= nil
Ops.add(nice1, 1)
Ops.add(nice2, 1)
Ops.add(ugly1, 1)
Ops.add(ugly2, 1)
"""
When the cop Yast/Ops autocorrects it
Then the code is converted to
"""
nice1 = true
nice2 = true
ugly1 = nil
ugly2 = nil
nice1 &&= true
nice2 &&= nil
ugly1 &&= true
ugly2 &&= nil
nice1 + 1
Ops.add(nice2, 1)
Ops.add(ugly1, 1)
Ops.add(ugly2, 1)
"""

Scenario: manages niceness correctly in presence of `||=`
Given the original code is
"""
nice1 = true
nice2 = true
ugly1 = nil
ugly2 = nil
nice1 ||= true
nice2 ||= nil
ugly1 ||= true
ugly2 ||= nil
Ops.add(nice1, 1)
Ops.add(nice2, 1)
Ops.add(ugly1, 1)
Ops.add(ugly2, 1)
"""
When the cop Yast/Ops autocorrects it
Then the code is converted to
"""
nice1 = true
nice2 = true
ugly1 = nil
ugly2 = nil
nice1 ||= true
nice2 ||= nil
ugly1 ||= true
ugly2 ||= nil
nice1 + 1
nice2 + 1
ugly1 + 1
Ops.add(ugly2, 1)
"""
32 changes: 32 additions & 0 deletions features/ops_blocks.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Feature: blocks

Scenario: does not translate inside a block and resumes with a clean slate
Given the original code is
"""
v = 1
v = Ops.add(v, 1)
2.times do
v = Ops.add(v, 1)
v = uglify
end
v = Ops.add(v, 1)
w = 1
w = Ops.add(w, 1)
"""
When the cop Yast/Ops autocorrects it
Then the code is converted to
"""
v = 1
v = v + 1
2.times do
v = Ops.add(v, 1)
v = uglify
end
v = Ops.add(v, 1)
w = 1
w = w + 1
"""
119 changes: 119 additions & 0 deletions features/ops_case.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
Feature: case

Scenario: translates the `when` body of a `case` statement
Given the original code is
"""
case expr
when 1
Ops.add(1, 1)
end
"""
When the cop Yast/Builtins autocorrects it
Then the code is converted to
"""
case expr
when 1
1 + 1
end
"""

Scenario: It translates all branches of a `case` statement, independently of each other
Given the original code is
"""
v = 1
case expr
when 1
Ops.add(v, 1)
v = nil
when 2
Ops.add(v, 2)
v = nil
else
Ops.add(1, v)
v = nil
end
"""
When the cop Yast/Builtins autocorrects it
Then the code is converted to
"""
v = 1
case expr
when 1
v + 1
v = nil
when 2
v + 2
v = nil
else
1 + v
v = nil
end
"""

Scenario: The expression also contributes to the data state
Given the original code is
"""
case v = 1
when 1
Ops.add(v, 1)
end
"""
When the cop Yast/Builtins autocorrects it
Then the code is converted to
"""
case v = 1
when 1
v + 1
end
"""

Scenario: The test also contributes to the data state
Given the original code is
"""
case expr
when v = 1
Ops.add(v, 1)
end
"""
When the cop Yast/Builtins autocorrects it
Then the code is converted to
"""
case expr
when v = 1
v + 1
end
"""

Scenario: The test also contributes to the data state
Given the original code is
"""
v = 1
case expr
when 1
v = nil
end
Ops.add(v, 1)
"""
When the cop Yast/Ops autocorrects it
Then the code is unchanged

Scenario: It translates zombies whose arguments were found nice after a `case`
Given the original code is
"""
case expr
when 1
v = nil
end
v = 1
Ops.add(v, 1)
"""
When the cop Yast/Ops autocorrects it
Then the code is converted to
"""
case expr
when 1
v = nil
end
v = 1
v + 1
"""
26 changes: 26 additions & 0 deletions features/ops_chained.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Feature: chained translation

Scenario: translates a left-associative chain of nice zombies
Given the original code is "Ops.add(Ops.add(1, 2), 3)"
When the cop Yast/Ops autocorrects it
Then the code is converted to "(1 + 2) + 3"

Scenario: translates a right-associative chain of nice zombies
Given the original code is "Ops.add(1, Ops.add(2, 3))"
When the cop Yast/Ops autocorrects it
Then the code is converted to "1 + (2 + 3)"

Scenario: translates `Ops.add` of plus and literal
Given the original code is "Ops.add("Hello" + " ", "World")"
When the cop Yast/Ops autocorrects it
Then the code is converted to "("Hello" + " ") + "World""

Scenario: translates `Ops.add` of parenthesized plus and literal
Given the original code is "Ops.add(("Hello" + " "), "World")"
When the cop Yast/Ops autocorrects it
Then the code is converted to "("Hello" + " ") + "World""

Scenario: translates `Ops.add` of literal and plus
Given the original code is "Ops.add("Hello", " " + "World")"
When the cop Yast/Ops autocorrects it
Then the code is converted to ""Hello" + (" " + "World")"
88 changes: 88 additions & 0 deletions features/ops_exceptions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Feature: exceptions

Scenario: translates the parts, joining else, rescue separately
Given the original code is
"""
def foo
v = 1
Ops.add(v, 1)
rescue
w = 1
Ops.add(w, 1)
v = nil
rescue
Ops.add(w, 1)
else
Ops.add(v, 1)
end
"""
When the cop Yast/Ops autocorrects it
Then the code is converted to
"""
def foo
v = 1
v + 1
rescue
w = 1
w + 1
v = nil
rescue
Ops.add(w, 1)
else
v + 1
end
"""

Scenario: does not translate code that depends on niceness skipped via an exception
Given the original code is
"""
def a_problem
v = nil
w = 1 / 0
v = 1
rescue
puts "Oops", Ops.add(v, 1)
end
"""
When the cop Yast/Ops autocorrects it
Then the code is unchanged

Scenario: can parse the syntactic variants of exception handling
Given the original code is
"""
begin
foo
raise "LOL"
foo
rescue Error
foo
rescue Bug, Blunder => b
foo
rescue => e
foo
rescue
foo
ensure
foo
end
yast rescue nil
"""
When the cop Yast/Ops autocorrects it
Then the code is unchanged

Scenario: does not translate a begin-body when a rescue contains a retry
Given the original code is
"""
def foo
v = 1
begin
Ops.add(v, 1)
maybe_raise
rescue
v = nil
retry
end
end
"""
When the cop Yast/Ops autocorrects it
Then the code is unchanged
45 changes: 45 additions & 0 deletions features/ops_formatting.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Feature: blocks

Scenario: does not translate inside a block and resumes with a clean slate
Given the original code is
"""
v = 1
v = Ops.add(v, 1)
2.times do
v = Ops.add(v, 1)
v = uglify
end
v = Ops.add(v, 1)
w = 1
w = Ops.add(w, 1)
"""
When the cop Yast/Ops autocorrects it
Then the code is converted to
"""
v = 1
v = v + 1
2.times do
v = Ops.add(v, 1)
v = uglify
end
v = Ops.add(v, 1)
w = 1
w = w + 1
"""

Scenario: does not translate `Ops.add` if any argument has a comment
Given the original code is
"""
Ops.add(
"Hello",
# foo
"World"
)
"""
When the cop Yast/Ops autocorrects it
Then the code is unchanged

0 comments on commit 38d8023

Please sign in to comment.