From 85a5b567b2167fb7495f51c6dc10df0c81103878 Mon Sep 17 00:00:00 2001 From: starnakin Date: Sun, 18 Jun 2023 20:03:27 +0200 Subject: [PATCH] core: all int is now num --- src/{atoi.🗿 => aton.🗿} | 9 ++------- tests/aton.🗿 | 9 +++++++++ tests/galloc.🗿 | 6 +++--- tests/strchri.🗿 | 6 +++--- tests/strcmp.🗿 | 8 ++++---- tests/strlen.🗿 | 4 ++-- tests/strncmp.🗿 | 14 +++++++------- tests/test.🗿 | 2 +- 8 files changed, 31 insertions(+), 27 deletions(-) rename src/{atoi.🗿 => aton.🗿} (58%) create mode 100644 tests/aton.🗿 diff --git a/src/atoi.🗿 b/src/aton.🗿 similarity index 58% rename from src/atoi.🗿 rename to src/aton.🗿 index 207c6ca..7ca9464 100644 --- a/src/atoi.🗿 +++ b/src/aton.🗿 @@ -1,13 +1,10 @@ -atoi(str) +aton(str) { local i = 0; - local sign = 0; local out = 0; loop { - if ([str + i] == '-') - sign = sign == 0; - else if ([str + i] != '+') + if ([str + i] != '+') break; i++; } @@ -17,7 +14,5 @@ atoi(str) out = out * 10 + [str + i] - '0'; i++; } - if (sign) - return (0 - out); return out; } diff --git a/tests/aton.🗿 b/tests/aton.🗿 new file mode 100644 index 0000000..583bffe --- /dev/null +++ b/tests/aton.🗿 @@ -0,0 +1,9 @@ +main() +{ + name = "aton"; + + test_num(aton("33"), 33, ""); + test_num(aton(""), 0, ""); + test_num(aton("40"), 40, ""); + test_num(aton("1"), 1, ""); +} diff --git a/tests/galloc.🗿 b/tests/galloc.🗿 index e041042..dd18585 100644 --- a/tests/galloc.🗿 +++ b/tests/galloc.🗿 @@ -7,13 +7,13 @@ main() name = "galloc"; ptr1 = galloc(1); - test_int(ptr1, heap + LOCATION_DATA, ""); + test_num(ptr1, heap + LOCATION_DATA, ""); free(ptr1); ptr1 = galloc(1); - test_int(ptr1, heap + LOCATION_DATA, "alloc after free"); + test_num(ptr1, heap + LOCATION_DATA, "alloc after free"); free(ptr1); ptr2 = galloc(0x9000); - test_int(ptr2, 0, "alloc too big"); + test_num(ptr2, 0, "alloc too big"); } diff --git a/tests/strchri.🗿 b/tests/strchri.🗿 index abf177d..77aa08d 100644 --- a/tests/strchri.🗿 +++ b/tests/strchri.🗿 @@ -2,7 +2,7 @@ main() { name = "strchri"; - test_int(strchri("bozoman", 'm'), 4, ""); - test_int(strchri("bozoman", 'v'), 0 - 1, ""); - test_int(strchri("", 'v'), 0 - 1, ""); + test_num(strchri("bozoman", 'm'), 4, ""); + test_num(strchri("bozoman", 'v'), 0 - 1, ""); + test_num(strchri("", 'v'), 0 - 1, ""); } diff --git a/tests/strcmp.🗿 b/tests/strcmp.🗿 index 81bfd9b..0458094 100644 --- a/tests/strcmp.🗿 +++ b/tests/strcmp.🗿 @@ -2,8 +2,8 @@ main() { name = "strcmp"; - test_int(strcmp("test", "test"), 0, "same chars"); - test_int(strcmp("s", "b"), 17, ""); - test_int(strcmp("", ""), 0, "empty strings"); - test_int(strcmp("", "a"), 65439, ""); + test_num(strcmp("test", "test"), 0, "same chars"); + test_num(strcmp("s", "b"), 17, ""); + test_num(strcmp("", ""), 0, "empty strings"); + test_num(strcmp("", "a"), 65439, ""); } diff --git a/tests/strlen.🗿 b/tests/strlen.🗿 index 4524a3a..4aaca3b 100644 --- a/tests/strlen.🗿 +++ b/tests/strlen.🗿 @@ -2,6 +2,6 @@ main() { name = "strlen"; - test_int(strlen("bozoman du 36"), 13, ""); - test_int(strlen(""), 0, "Empty string"); + test_num(strlen("bozoman du 36"), 13, ""); + test_num(strlen(""), 0, "Empty string"); } diff --git a/tests/strncmp.🗿 b/tests/strncmp.🗿 index 514fbe0..8e9867f 100644 --- a/tests/strncmp.🗿 +++ b/tests/strncmp.🗿 @@ -2,11 +2,11 @@ main() { name = "strncmp"; - test_int(strncmp("test", "test", 4), 0, "same chars"); - test_int(strncmp("s", "b", 4), 17, ""); - test_int(strncmp("", "", 4), 0, "empty strings"); - test_int(strncmp("", "a", 0), 0, ""); - test_int(strncmp("ab", "ac", 1), 0, ""); - test_int(strncmp("aq", "a", 1), 0, ""); - test_int(strncmp("aq", "a", 2), 113, ""); + test_num(strncmp("test", "test", 4), 0, "same chars"); + test_num(strncmp("s", "b", 4), 17, ""); + test_num(strncmp("", "", 4), 0, "empty strings"); + test_num(strncmp("", "a", 0), 0, ""); + test_num(strncmp("ab", "ac", 1), 0, ""); + test_num(strncmp("aq", "a", 1), 0, ""); + test_num(strncmp("aq", "a", 2), 113, ""); } diff --git a/tests/test.🗿 b/tests/test.🗿 index 7788236..f59f76b 100644 --- a/tests/test.🗿 +++ b/tests/test.🗿 @@ -22,7 +22,7 @@ test_str(value, reach_value, description) wrt '\n'; } -test_int(value, reach_value, description) +test_num(value, reach_value, description) { putstr(name); if (value != reach_value)