mirror of
https://github.com/CKolkey/ts-node-action
synced 2024-09-16 13:44:05 +02:00
feat: Add c_sharp support
This commit is contained in:
parent
f266409809
commit
cb036ca850
5 changed files with 159 additions and 14 deletions
2
.github/workflows/spec.yml
vendored
2
.github/workflows/spec.yml
vendored
|
@ -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"
|
||||
|
|
26
README.md
26
README.md
|
@ -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 -->
|
||||
|
||||
|
|
39
lua/ts-node-action/filetypes/c_sharp.lua
Normal file
39
lua/ts-node-action/filetypes/c_sharp.lua
Normal 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(),
|
||||
}
|
|
@ -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
105
spec/filetypes/c_sharp.lua
Normal 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)
|
Loading…
Reference in a new issue