From 25a0ad1bc36f5ff40b7f17e4240407712a02895f Mon Sep 17 00:00:00 2001 From: moonz Date: Tue, 27 Jan 2026 11:22:42 +0100 Subject: refactor: renamed the test file to reflect which code action is being tested --- tests/action_invert_if_test.odin | 382 +++++++++++++++++++++++++++++++++++++++ tests/action_test.odin | 380 -------------------------------------- 2 files changed, 382 insertions(+), 380 deletions(-) create mode 100644 tests/action_invert_if_test.odin delete mode 100644 tests/action_test.odin diff --git a/tests/action_invert_if_test.odin b/tests/action_invert_if_test.odin new file mode 100644 index 0000000..0639b69 --- /dev/null +++ b/tests/action_invert_if_test.odin @@ -0,0 +1,382 @@ +package tests + +import "core:testing" + +import test "src:testing" + +INVERT_IF_ACTION :: "Invert if" + +@(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_ACTION}) +} + +@(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_ACTION, 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_ACTION}) +} + +@(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_ACTION, 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_ACTION}) +} + +@(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_ACTION, 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_ACTION, 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_ACTION, 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_ACTION, 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_ACTION, 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_ACTION, 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_ACTION, 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_ACTION, 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_ACTION}) +} diff --git a/tests/action_test.odin b/tests/action_test.odin deleted file mode 100644 index f5c57a5..0000000 --- a/tests/action_test.odin +++ /dev/null @@ -1,380 +0,0 @@ -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"}) -} -- cgit v1.2.3