feat: Add c_sharp support

This commit is contained in:
LucasTavaresA 2023-11-10 22:08:52 -03:00
parent f266409809
commit cb036ca850
No known key found for this signature in database
GPG key ID: 0BB0E0780E17746E
5 changed files with 159 additions and 14 deletions

View file

@ -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"

View file

@ -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 -->

View file

@ -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(),
}

View file

@ -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
spec/filetypes/c_sharp.lua Normal file
View file

@ -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)