diff options
| author | Lucas Perlind <perlindluca@gmail.com> | 2023-04-07 17:35:21 +1000 |
|---|---|---|
| committer | Lucas Perlind <perlindluca@gmail.com> | 2023-04-07 20:39:01 +1000 |
| commit | e0d9092df840b14410b709e383b196ed2ac9b9e0 (patch) | |
| tree | b4e3e16c38c7698c34c942fb00aa67ad740f93c0 /tests | |
| parent | f863264af6ef1546d3965a8bf865e14c01146054 (diff) | |
Document return values of strings and add allocator errors where
possible
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/core/strings/test_core_strings.odin | 38 | ||||
| -rw-r--r-- | tests/documentation/documentation_tester.odin | 2 |
2 files changed, 27 insertions, 13 deletions
diff --git a/tests/core/strings/test_core_strings.odin b/tests/core/strings/test_core_strings.odin index 00e53647f..fdaf3af28 100644 --- a/tests/core/strings/test_core_strings.odin +++ b/tests/core/strings/test_core_strings.odin @@ -5,6 +5,7 @@ import "core:testing" import "core:fmt" import "core:os" import "core:runtime" +import "core:mem" TEST_count := 0 TEST_fail := 0 @@ -105,33 +106,46 @@ Case_Kind :: enum { Ada_Case, } -test_cases := [Case_Kind]struct{s: string, p: proc(r: string, allocator: runtime.Allocator) -> string}{ +Case_Proc :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) + +test_cases := [Case_Kind]struct{s: string, p: Case_Proc}{ .Lower_Space_Case = {"hellope world", to_lower_space_case}, .Upper_Space_Case = {"HELLOPE WORLD", to_upper_space_case}, - .Lower_Snake_Case = {"hellope_world", strings.to_snake_case}, - .Upper_Snake_Case = {"HELLOPE_WORLD", strings.to_upper_snake_case}, - .Lower_Kebab_Case = {"hellope-world", strings.to_kebab_case}, - .Upper_Kebab_Case = {"HELLOPE-WORLD", strings.to_upper_kebab_case}, - .Camel_Case = {"hellopeWorld", strings.to_camel_case}, - .Pascal_Case = {"HellopeWorld", strings.to_pascal_case}, - .Ada_Case = {"Hellope_World", strings.to_ada_case}, + .Lower_Snake_Case = {"hellope_world", to_snake_case}, + .Upper_Snake_Case = {"HELLOPE_WORLD", to_upper_snake_case}, + .Lower_Kebab_Case = {"hellope-world", to_kebab_case}, + .Upper_Kebab_Case = {"HELLOPE-WORLD", to_upper_kebab_case}, + .Camel_Case = {"hellopeWorld", to_camel_case}, + .Pascal_Case = {"HellopeWorld", to_pascal_case}, + .Ada_Case = {"Hellope_World", to_ada_case}, } -to_lower_space_case :: proc(r: string, allocator: runtime.Allocator) -> string { +to_lower_space_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_delimiter_case(r, ' ', false, allocator) } -to_upper_space_case :: proc(r: string, allocator: runtime.Allocator) -> string { +to_upper_space_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_delimiter_case(r, ' ', true, allocator) } +// NOTE: we have these wrappers as having #optional_allocator_error changes the type to not be equivalent +to_snake_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_snake_case(r, allocator) } +to_upper_snake_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_upper_snake_case(r, allocator) } +to_kebab_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_kebab_case(r, allocator) } +to_upper_kebab_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_upper_kebab_case(r, allocator) } +to_camel_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_camel_case(r, allocator) } +to_pascal_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_pascal_case(r, allocator) } +to_ada_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_ada_case(r, allocator) } + @test test_case_conversion :: proc(t: ^testing.T) { for entry in test_cases { for test_case, case_kind in test_cases { - result := entry.p(test_case.s, context.allocator) + result, err := entry.p(test_case.s, context.allocator) + msg := fmt.tprintf("ERROR: We got the allocation error '{}'\n", err) + expect(t, err == nil, msg) defer delete(result) - msg := fmt.tprintf("ERROR: Input `{}` to converter {} does not match `{}`, got `{}`.\n", test_case.s, case_kind, entry.s, result) + msg = fmt.tprintf("ERROR: Input `{}` to converter {} does not match `{}`, got `{}`.\n", test_case.s, case_kind, entry.s, result) expect(t, result == entry.s, msg) } } diff --git a/tests/documentation/documentation_tester.odin b/tests/documentation/documentation_tester.odin index c50a18ce2..efba63f88 100644 --- a/tests/documentation/documentation_tester.odin +++ b/tests/documentation/documentation_tester.odin @@ -411,7 +411,7 @@ main :: proc() { // NOTE: this will escape the multiline string. Even with a backslash it still escapes due to the semantics of ` // I don't think any examples would really need this specific character so let's just make it forbidden and change // in the future if we really need to - if strings.contains_rune(line, '`') >= 0 { + if strings.contains_rune(line, '`') { fmt.eprintf("The line %q in the output for \"%s.%s\" contains a ` which is not allowed\n", line, test.package_name, test.entity_name) g_bad_doc = true had_line_error = true |