test_core_strings.odin 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package test_core_image
  2. import "core:strings"
  3. import "core:testing"
  4. import "core:fmt"
  5. import "core:os"
  6. TEST_count := 0
  7. TEST_fail := 0
  8. when ODIN_TEST {
  9. expect :: testing.expect
  10. log :: testing.log
  11. } else {
  12. expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
  13. TEST_count += 1
  14. if !condition {
  15. TEST_fail += 1
  16. fmt.printf("[%v] %v\n", loc, message)
  17. return
  18. }
  19. }
  20. log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
  21. fmt.printf("[%v] ", loc)
  22. fmt.printf("log: %v\n", v)
  23. }
  24. }
  25. main :: proc() {
  26. t := testing.T{}
  27. test_index_any_small_string_not_found(&t)
  28. test_index_any_larger_string_not_found(&t)
  29. test_index_any_small_string_found(&t)
  30. test_index_any_larger_string_found(&t)
  31. fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
  32. if TEST_fail > 0 {
  33. os.exit(1)
  34. }
  35. }
  36. @test
  37. test_index_any_small_string_not_found :: proc(t: ^testing.T) {
  38. index := strings.index_any(".", "/:\"")
  39. log(t, index)
  40. expect(t, index == -1, "index_any should be negative")
  41. }
  42. @test
  43. test_index_any_larger_string_not_found :: proc(t: ^testing.T) {
  44. index := strings.index_any("aaaaaaaa.aaaaaaaa", "/:\"")
  45. expect(t, index == -1, "index_any should be negative")
  46. }
  47. @test
  48. test_index_any_small_string_found :: proc(t: ^testing.T) {
  49. index := strings.index_any(".", "/:.\"")
  50. expect(t, index == 0, "index_any should be 0")
  51. }
  52. @test
  53. test_index_any_larger_string_found :: proc(t: ^testing.T) {
  54. index := strings.index_any("aaaaaaaa:aaaaaaaa", "/:\"")
  55. expect(t, index == 8, "index_any should be 8")
  56. }