-
Notifications
You must be signed in to change notification settings - Fork 20
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
1 parent
f266409
commit f947b53
Showing
5 changed files
with
159 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
local actions = require("ts-node-action.actions") | ||
|
||
local operators = { | ||
["!="] = "==", | ||
["=="] = "!=", | ||
[">"] = "<", | ||
["<"] = ">", | ||
[">="] = "<=", | ||
["<="] = ">=", | ||
["-"] = "+", | ||
["+"] = "-", | ||
["*"] = "/", | ||
["/"] = "*", | ||
["+="] = "-=", | ||
["-="] = "+=", | ||
["++"] = "--", | ||
["--"] = "++", | ||
["||"] = "&&", | ||
["&&"] = "||", | ||
} | ||
|
||
local modifiers = { | ||
["public"] = "private", | ||
["private"] = "public", | ||
["struct"] = "class", | ||
["class"] = "struct", | ||
} | ||
|
||
return { | ||
["boolean_literal"] = actions.toggle_boolean(), | ||
["binary"] = actions.toggle_operator(operators), | ||
["modifier"] = actions.toggle_operator(modifiers), | ||
["struct_declaration"] = actions.toggle_operator(modifiers), | ||
["class_declaration"] = actions.toggle_operator(modifiers), | ||
["binary_expression"] = actions.toggle_operator(operators), | ||
["assignment_operator"] = actions.toggle_operator(operators), | ||
["postfix_unary_expression"] = actions.toggle_operator(operators), | ||
["integer_literal"] = actions.toggle_int_readability(), | ||
} |
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,105 @@ | ||
dofile("spec/spec_helper.lua") | ||
|
||
local Helper = SpecHelper.new("c_sharp", { shiftwidth = 4 }) | ||
|
||
describe("boolean", function() | ||
it("turns 'true' into 'false'", function() | ||
assert.are.same( | ||
{ "bool bool = true;" }, | ||
Helper:call({ "bool bool = false;" }, { 1, 13 }) | ||
) | ||
end) | ||
|
||
it("turns 'false' into 'true'", function() | ||
assert.are.same( | ||
{ "bool bool = false;" }, | ||
Helper:call({ "bool bool = true;" }, { 1, 13 }) | ||
) | ||
end) | ||
end) | ||
|
||
describe("integer", function() | ||
it("adds underscores to long int", function() | ||
assert.are.same({ "1_000_000" }, Helper:call("1000000")) | ||
end) | ||
|
||
it("removes underscores from long int", function() | ||
assert.are.same({ "1000000" }, Helper:call("1_000_000")) | ||
end) | ||
|
||
it("doesn't change ints less than four places", function() | ||
assert.are.same({ "100" }, Helper:call("100")) | ||
end) | ||
end) | ||
|
||
describe("operator", function() | ||
it("toggles '<= into '>='", function() | ||
assert.are.same({ "i <= 8" }, Helper:call({ "i >= 8" }, { 1, 3 })) | ||
end) | ||
|
||
it("toggles '>=' into '<='", function() | ||
assert.are.same({ "i >= 8" }, Helper:call({ "i <= 8" }, { 1, 3 })) | ||
end) | ||
|
||
it("toggles '>' into '<'", function() | ||
assert.are.same({ "i > 8" }, Helper:call({ "i < 8" }, { 1, 3 })) | ||
end) | ||
|
||
it("toggles '<' into '>'", function() | ||
assert.are.same({ "i < 8" }, Helper:call({ "i > 8" }, { 1, 3 })) | ||
end) | ||
|
||
it("toggles '+' into '-'", function() | ||
assert.are.same({ "i + 8" }, Helper:call({ "i - 8" }, { 1, 3 })) | ||
end) | ||
|
||
it("toggles '-' into '+'", function() | ||
assert.are.same({ "i - 8" }, Helper:call({ "i + 8" }, { 1, 3 })) | ||
end) | ||
|
||
it("toggles '*' into '/'", function() | ||
assert.are.same({ "i * 8" }, Helper:call({ "i / 8" }, { 1, 3 })) | ||
end) | ||
|
||
it("toggles '/' into '*'", function() | ||
assert.are.same({ "i / 8" }, Helper:call({ "i * 8" }, { 1, 3 })) | ||
end) | ||
|
||
it("toggles '+=' into '-='", function() | ||
assert.are.same({ "i += 8" }, Helper:call({ "i -= 8" }, { 1, 3 })) | ||
end) | ||
|
||
it("toggles '-=' into '+='", function() | ||
assert.are.same({ "i -= 8" }, Helper:call({ "i += 8" }, { 1, 3 })) | ||
end) | ||
|
||
it("toggles '++' into '--'", function() | ||
assert.are.same({ "i++" }, Helper:call({ "i--" }, { 1, 2 })) | ||
end) | ||
|
||
it("toggles '--' into '++'", function() | ||
assert.are.same({ "i--" }, Helper:call({ "i++" }, { 1, 2 })) | ||
end) | ||
|
||
it("toggles '==' into '!='", function() | ||
assert.are.same({ "i == 8" }, Helper:call({ "i != 8" }, { 1, 3 })) | ||
end) | ||
|
||
it("toggles '!=' into '=='", function() | ||
assert.are.same({ "i != 8" }, Helper:call({ "i == 8" }, { 1, 3 })) | ||
end) | ||
|
||
it("toggles '&&' into '||'", function() | ||
assert.are.same( | ||
{ "i == 8 && x == 9" }, | ||
Helper:call({ "i == 8 || x == 9" }, { 1, 8 }) | ||
) | ||
end) | ||
|
||
it("toggles '||' into '&&'", function() | ||
assert.are.same( | ||
{ "i == 8 || x == 9" }, | ||
Helper:call({ "i == 8 && x == 9" }, { 1, 8 }) | ||
) | ||
end) | ||
end) |