You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I modified the description in the When Writing Tests How to
Compare Resylt and Expected for Slice FAQ and created
the expect_helpers.odin template to provide an official
version of the comparison function for string slices and
general slices.
testing.expect_value(t, result, exp_str, loc = loc)
21
-
}
22
-
```
10
+
-`expect_string_slices :: proc(t: ^testing.T, actual, expected: []string, loc := #caller_location)` compares slices of string and displays the unicode strings in result and expected when the test fails.
11
+
-`expect_slices :: proc(t: ^testing.T, actual, expected: []$E, loc := #caller_location)` compares slices of any other type and displays human readable sets for both the result and expected values when the test fails.
23
12
24
13
2. use the helper function to compare the result and expected values.
expect_string_slices(t, result []string{"LISTEN", "Silent"})
28
19
```
29
20
30
21
Why are we asking you to use that specific procedure?
@@ -36,7 +27,9 @@ Using the function above, the message looks like:
36
27
[forth_test.odin:24:test_parsing_and_numbers__numbers_just_get_pushed_onto_the_stack()] expected result to be [1, 2, 3, 4], got [1, 2, 3, 4, 5]
37
28
```
38
29
39
-
Note how informative the messages is?
30
+
Note how informative the messages is!
40
31
It shows both result and expected values in a human-readable form (while using `slice.equal()` would result in 'expected true, got false').
41
32
In addition it correctly identifies the line where the test fails (not the line of the `expect_value()` in the helper procedure) and properly identify the result as 'result'.
42
33
There are other ways to achieve the same result but this one is battle tested.
0 commit comments