-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert the original ZK tests to Cucumber
- Loading branch information
Showing
12 changed files
with
820 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Oops, something went wrong.