test_core_strings.odin 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. fmt.printf("[%v] ", loc)
  14. TEST_count += 1
  15. if !condition {
  16. TEST_fail += 1
  17. fmt.println(message)
  18. return
  19. }
  20. fmt.println(" PASS")
  21. }
  22. log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
  23. fmt.printf("[%v] ", loc)
  24. fmt.printf("log: %v\n", v)
  25. }
  26. }
  27. main :: proc() {
  28. t := testing.T{}
  29. test_index_any_small_string_not_found(&t)
  30. test_index_any_larger_string_not_found(&t)
  31. test_index_any_small_string_found(&t)
  32. test_index_any_larger_string_found(&t)
  33. fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
  34. if TEST_fail > 0 {
  35. os.exit(1)
  36. }
  37. }
  38. @test
  39. test_index_any_small_string_not_found :: proc(t: ^testing.T) {
  40. index := strings.index_any(".", "/:\"")
  41. log(t, index)
  42. expect(t, index == -1, "index_any should be negative")
  43. }
  44. @test
  45. test_index_any_larger_string_not_found :: proc(t: ^testing.T) {
  46. index := strings.index_any("aaaaaaaa.aaaaaaaa", "/:\"")
  47. expect(t, index == -1, "index_any should be negative")
  48. }
  49. @test
  50. test_index_any_small_string_found :: proc(t: ^testing.T) {
  51. index := strings.index_any(".", "/:.\"")
  52. expect(t, index == 0, "index_any should be 0")
  53. }
  54. @test
  55. test_index_any_larger_string_found :: proc(t: ^testing.T) {
  56. index := strings.index_any("aaaaaaaa:aaaaaaaa", "/:\"")
  57. expect(t, index == 8, "index_any should be 8")
  58. }