-
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.
- Loading branch information
Showing
22 changed files
with
909 additions
and
179 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
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
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
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
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,36 @@ | ||
Feature: blocks | ||
|
||
Inside a block the data flow is more complex than we handle now. | ||
After it, we start anew. | ||
|
||
Scenario: does not translate inside a block and resumes with a clean slate | ||
Given this gets implemented | ||
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,129 @@ | ||
Feature: case | ||
|
||
With a **single-pass top-down data flow analysis**, that we have been using, | ||
we can process the `case` statement but not beyond it, | ||
because we cannot know which branch was taken. | ||
|
||
We can proceed after the `case` statement but must **start with a clean slate**. | ||
More precisely we should remove knowledge of all variables affected in either | ||
branch of the `case` statement, but we will first simplify the job and wipe all | ||
state for the processed method. | ||
|
||
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/Ops 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 this gets implemented | ||
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/Ops 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/Ops 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/Ops 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,28 @@ | ||
Feature: chained translation | ||
|
||
Scenario: translates a left-associative chain of nice zombies | ||
Given this gets implemented | ||
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 this gets implemented | ||
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")" |
Oops, something went wrong.