aboutsummaryrefslogtreecommitdiff
path: root/tests/core/encoding
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2024-05-30 11:42:34 +0200
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-02 14:47:08 -0400
commit3404dea8ac741f98e3de4a341f64ef37d06550d9 (patch)
treee2a386ae11e40bd6c1541e0482402c18c93ffa32 /tests/core/encoding
parent40b20fb47353e61681ef815c43423d76b99e61d9 (diff)
Port `tests\encoding\hex`
Diffstat (limited to 'tests/core/encoding')
-rw-r--r--tests/core/encoding/hex/test_core_hex.odin94
1 files changed, 44 insertions, 50 deletions
diff --git a/tests/core/encoding/hex/test_core_hex.odin b/tests/core/encoding/hex/test_core_hex.odin
index d928cd28e..6a00c9705 100644
--- a/tests/core/encoding/hex/test_core_hex.odin
+++ b/tests/core/encoding/hex/test_core_hex.odin
@@ -2,42 +2,6 @@ package test_core_hex
import "core:encoding/hex"
import "core:testing"
-import "core:fmt"
-import "core:os"
-
-TEST_count := 0
-TEST_fail := 0
-
-when ODIN_TEST {
- expect :: testing.expect
- log :: testing.log
-} else {
- expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
- TEST_count += 1
- if !condition {
- TEST_fail += 1
- fmt.printf("[%v] %v\n", loc, message)
- return
- }
- }
- log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
- fmt.printf("[%v] ", loc)
- fmt.printf("log: %v\n", v)
- }
-}
-
-main :: proc() {
- t := testing.T{}
-
- hex_encode(&t)
- hex_decode(&t)
- hex_decode_sequence(&t)
-
- fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
- if TEST_fail > 0 {
- os.exit(1)
- }
-}
CASES :: [][2]string{
{"11", "3131"},
@@ -49,10 +13,14 @@ CASES :: [][2]string{
hex_encode :: proc(t: ^testing.T) {
for test in CASES {
encoded := string(hex.encode(transmute([]byte)test[0]))
- expect(
+ defer delete(encoded)
+ testing.expectf(
t,
encoded == test[1],
- fmt.tprintf("encode: %q -> %q (should be: %q)", test[0], encoded, test[1]),
+ "encode: %q -> %q (should be: %q)",
+ test[0],
+ encoded,
+ test[1],
)
}
}
@@ -61,11 +29,20 @@ hex_encode :: proc(t: ^testing.T) {
hex_decode :: proc(t: ^testing.T) {
for test in CASES {
decoded, ok := hex.decode(transmute([]byte)test[1])
- expect(t, ok, fmt.tprintf("decode: %q not ok", test[1]))
- expect(
+ defer delete(decoded)
+ testing.expectf(
+ t,
+ ok,
+ "decode: %q not ok",
+ test[1],
+ )
+ testing.expectf(
t,
string(decoded) == test[0],
- fmt.tprintf("decode: %q -> %q (should be: %q)", test[1], string(decoded), test[0]),
+ "decode: %q -> %q (should be: %q)",
+ test[1],
+ string(decoded),
+ test[0],
)
}
}
@@ -73,20 +50,37 @@ hex_decode :: proc(t: ^testing.T) {
@(test)
hex_decode_sequence :: proc(t: ^testing.T) {
b, ok := hex.decode_sequence("0x23")
- expect(t, ok, "decode_sequence: 0x23 not ok")
- expect(t, b == '#', fmt.tprintf("decode_sequence: 0x23 -> %c (should be: %c)", b, '#'))
+ testing.expect(t, ok, "decode_sequence: 0x23 not ok")
+ testing.expectf(
+ t,
+ b == '#',
+ "decode_sequence: 0x23 -> %c (should be: %c)",
+ b,
+ '#',
+ )
b, ok = hex.decode_sequence("0X3F")
- expect(t, ok, "decode_sequence: 0X3F not ok")
- expect(t, b == '?', fmt.tprintf("decode_sequence: 0X3F -> %c (should be: %c)", b, '?'))
+ testing.expect(t, ok, "decode_sequence: 0X3F not ok")
+ testing.expectf(
+ t,
+ b == '?',
+ "decode_sequence: 0X3F -> %c (should be: %c)",
+ b,
+ '?',
+ )
b, ok = hex.decode_sequence("2a")
- expect(t, ok, "decode_sequence: 2a not ok")
- expect(t, b == '*', fmt.tprintf("decode_sequence: 2a -> %c (should be: %c)", b, '*'))
+ testing.expect(t, ok, "decode_sequence: 2a not ok")
+ testing.expectf(t,
+ b == '*',
+ "decode_sequence: 2a -> %c (should be: %c)",
+ b,
+ '*',
+ )
_, ok = hex.decode_sequence("1")
- expect(t, !ok, "decode_sequence: 1 should be too short")
+ testing.expect(t, !ok, "decode_sequence: 1 should be too short")
_, ok = hex.decode_sequence("123")
- expect(t, !ok, "decode_sequence: 123 should be too long")
-}
+ testing.expect(t, !ok, "decode_sequence: 123 should be too long")
+} \ No newline at end of file