Skip to content

Commit

Permalink
Merge pull request #56 from LucasTavaresA/master
Browse files Browse the repository at this point in the history
  • Loading branch information
CKolkey committed Nov 13, 2023
2 parents f266409 + cb036ca commit ac77160
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Compile parsers
run: |
nvim --headless -c "TSInstallSync ruby python lua javascript julia yaml sql r git_rebase" -c "q"
nvim --headless -c "TSInstallSync c_sharp ruby python lua javascript julia yaml sql r git_rebase" -c "q"
- name: Tests
env:
ci: "1"
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,19 +346,19 @@ overridden on a per-lang basis. Check out the implementations under

<!-- markdownlint-disable line-length -->

| | (\*) | Ruby | js/ts/tsx/jsx | Lua | Python | PHP | Rust | JSON | HTML | YAML | R |
| -------------------------- | ---- | ---- | ------------- | --- | ------ | --- | ---- | ---- | ---- | ---- | --- |
| `toggle_boolean()` |||||||| | |||
| `cycle_case()` |||||||| | | ||
| `cycle_quotes()` ||||||| | | | ||
| `toggle_multiline()` | |||||| || | ||
| `toggle_operator()` | |||||| | | | ||
| `toggle_int_readability()` | ||| ||||| | | |
| `toggle_block()` | || | | | | | | | | |
| if/else \<-> ternery | || | || | | | | | |
| if block/postfix | || | | | | | | | | |
| `toggle_hash_style()` | || | | | | | | | | |
| `conceal_string()` | | || | | | | || | |
| | (\*) | Ruby | js/ts/tsx/jsx | Lua | Python | PHP | Rust | C# | JSON | HTML | YAML | R |
| -------------------------- | ---- | ---- | ------------- | --- | ------ | --- | ---- | --- | ---- | ---- | ---- | --- |
| `toggle_boolean()` |||||||| | | |||
| `cycle_case()` |||||||| | | | ||
| `cycle_quotes()` ||||||| | | | | | |
| `toggle_multiline()` | |||||| | || | ||
| `toggle_operator()` | |||||| || | | ||
| `toggle_int_readability()` | ||| ||| ||| | | |
| `toggle_block()` | || | | | | | | | | | |
| if/else \<-> ternery | || | || | | | | | | |
| if block/postfix | || | | | | | | | | | |
| `toggle_hash_style()` | || | | | | | | | | | |
| `conceal_string()` | | || | | | | | | | | |

<!-- markdownlint-enable line-length -->

Expand Down
39 changes: 39 additions & 0 deletions lua/ts-node-action/filetypes/c_sharp.lua
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(),
}
1 change: 1 addition & 0 deletions lua/ts-node-action/filetypes/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ return {
sql = require("ts-node-action.filetypes.sql"),
r = require("ts-node-action.filetypes.r"),
git_rebase = require("ts-node-action.filetypes.git_rebase"),
c_sharp = require("ts-node-action.filetypes.c_sharp"),
}
105 changes: 105 additions & 0 deletions spec/filetypes/c_sharp.lua
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)

0 comments on commit ac77160

Please sign in to comment.