diff options
| author | pc <pmnarimani@gmail.com> | 2026-01-27 03:50:56 +0100 |
|---|---|---|
| committer | moonz <pmnarimani@gmail.com> | 2026-01-30 18:03:45 +0100 |
| commit | 8e5580815af631401dfa46fbf2997e44128681a6 (patch) | |
| tree | 86f678f1bc4e4c207c1435a973fc055406e7c8ec /tests | |
| parent | 791b0cd1c199880574d9377a56c6569a1831efd8 (diff) | |
feat: add invert if action
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/action_test.odin | 380 |
1 files changed, 380 insertions, 0 deletions
diff --git a/tests/action_test.odin b/tests/action_test.odin new file mode 100644 index 0000000..f5c57a5 --- /dev/null +++ b/tests/action_test.odin @@ -0,0 +1,380 @@ +package tests + +import "core:testing" + +import test "src:testing" + +@(test) +action_invert_if_simple :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + x := 5 + if x{*} >= 0 { + foo() + } +} +`, + packages = {}, + } + + test.expect_action(t, &source, {"Invert if"}) +} + +@(test) +action_invert_if_simple_edit :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + x := 5 + if x{*} >= 0 { + foo() + } +} +`, + packages = {}, + } + + expected := `if x < 0 { + } else { + foo() + }` + + test.expect_action_with_edit(t, &source, "Invert if", expected) +} + +@(test) +action_invert_if_with_else :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + x := 5 + if x{*} == 0 { + foo() + } else { + bar() + } +} +`, + packages = {}, + } + + test.expect_action(t, &source, {"Invert if"}) +} + +@(test) +action_invert_if_with_else_edit :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + x := 5 + if x{*} == 0 { + foo() + } else { + bar() + } +} +`, + packages = {}, + } + + expected := `if x != 0 { + bar() + } else { + foo() + }` + + test.expect_action_with_edit(t, &source, "Invert if", expected) +} + +@(test) +action_invert_if_with_init :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + if x{*} := foo(); x < 0 { + bar() + } +} +`, + packages = {}, + } + + test.expect_action(t, &source, {"Invert if"}) +} + +@(test) +action_invert_if_with_init_edit :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + if x{*} := foo(); x < 0 { + bar() + } +} +`, + packages = {}, + } + + expected := `if x := foo(); x >= 0 { + } else { + bar() + }` + + test.expect_action_with_edit(t, &source, "Invert if", expected) +} + +@(test) +action_invert_if_not_on_if :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + x :={*} 5 +} +`, + packages = {}, + } + + // Should not have the invert action when not on an if statement + test.expect_action(t, &source, {}) +} + +@(test) +action_invert_if_not_eq :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + if x{*} != 0 { + foo() + } +} +`, + packages = {}, + } + + expected := `if x == 0 { + } else { + foo() + }` + + test.expect_action_with_edit(t, &source, "Invert if", expected) +} + +@(test) +action_invert_if_lt :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + if x{*} < 5 { + foo() + } +} +`, + packages = {}, + } + + expected := `if x >= 5 { + } else { + foo() + }` + + test.expect_action_with_edit(t, &source, "Invert if", expected) +} + +@(test) +action_invert_if_gt :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + if x{*} > 5 { + foo() + } +} +`, + packages = {}, + } + + expected := `if x <= 5 { + } else { + foo() + }` + + test.expect_action_with_edit(t, &source, "Invert if", expected) +} + +@(test) +action_invert_if_le :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + if x{*} <= 5 { + foo() + } +} +`, + packages = {}, + } + + expected := `if x > 5 { + } else { + foo() + }` + + test.expect_action_with_edit(t, &source, "Invert if", expected) +} + +@(test) +action_invert_if_negated :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + if !x{*} { + foo() + } +} +`, + packages = {}, + } + + expected := `if x { + } else { + foo() + }` + + test.expect_action_with_edit(t, &source, "Invert if", expected) +} + +@(test) +action_invert_if_boolean :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + if x{*} { + foo() + } +} +`, + packages = {}, + } + + expected := `if !x { + } else { + foo() + }` + + test.expect_action_with_edit(t, &source, "Invert if", expected) +} + +@(test) +action_invert_if_else_if_chain :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + x := something() + if x{*} > 0 { + statement1() + } else if x < 0 { + statement2() + } else { + statement3() + } +} +`, + packages = {}, + } + + expected := `if x <= 0 { + if x < 0 { + statement2() + } else { + statement3() + } + } else { + statement1() + }` + + test.expect_action_with_edit(t, &source, "Invert if", expected) +} + +@(test) +action_invert_if_not_on_else_if :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + x := something() + if x > 0 { + statement1() + } else if x{*} < 0 { + statement2() + } else { + statement3() + } +} +`, + packages = {}, + } + + // Should not have the invert action when on an else-if statement + test.expect_action(t, &source, {}) +} + +@(test) +action_invert_if_not_on_else :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + x := something() + if x > 0 { + statement1() + } else { + statement3(){*} + } +} +`, + packages = {}, + } + + // Should not have the invert action when in the else block (not on an if) + test.expect_action(t, &source, {}) +} + +@(test) +action_invert_if_nested_in_else_if_body :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + x := something() + if x > 0 { + statement1() + } else if x < 0 { + if y{*} > 0 { + statement2() + } + } else { + statement3() + } +} +`, + packages = {}, + } + + // Should have the invert action for an if statement nested inside an else-if body + test.expect_action(t, &source, {"Invert if"}) +} |