test_core_strings.odin 1.6 KB

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