diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_hello_world.py | 2 | ||||
-rw-r--r-- | tests/test_parsing.py | 34 |
2 files changed, 17 insertions, 19 deletions
diff --git a/tests/test_hello_world.py b/tests/test_hello_world.py index ec1ccdd..594ab4f 100644 --- a/tests/test_hello_world.py +++ b/tests/test_hello_world.py @@ -8,7 +8,7 @@ class TestHelloWorld(unittest.TestCase): code = r""" include "stdio.hro"; -int main() { +int32 main() { printf("Hello, world!\n"); return 0; } diff --git a/tests/test_parsing.py b/tests/test_parsing.py index 91787a6..7463fe7 100644 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -5,41 +5,39 @@ from crowbar_reference_compiler import parse_header, parse_implementation, scan class TestParsing(unittest.TestCase): def test_basic(self): - print(parse_header(scan("int x();"))) + print(parse_header(scan("int8 x();"))) def test_scdoc_str(self): # adapted from https://git.sr.ht/~sircmpwn/scdoc/tree/master/include/str.h print(parse_header(scan(r""" -include "stdint.h"; - struct str { - char *str; - typedef size_t len; - typedef size_t size; -}; + (uint8[size])* str; + uintsize len; + uintsize size; +} struct str *str_create(); void str_free(struct str *str); void str_reset(struct str *str); -int str_append_ch(struct str *str, typedef uint32_t ch); +intsize str_append_ch(struct str *str, uint32 ch); """))) # adapted from https://git.sr.ht/~sircmpwn/scdoc/tree/master/src/string.c print(parse_implementation(scan(r""" -include "stdlib.h"; -include "stdint.h"; -include "str.h"; -include "unicode.h"; +include "stdlib.hro"; +include "stdint.hro"; +include "str.hro"; +include "unicode.hro"; -int ensure_capacity(struct str *str, typedef size_t len) { +bool ensure_capacity(struct str *str, intsize len) { if (len + 1 >= str->size) { - char *new = realloc(str->str, str->size * 2); + (uint8[str->size * 2])* new = realloc(str->str, str->size * 2); if (!new) { - return 0; + return false; } str->str = new; str->size *= 2; } - return 1; + return true; } struct str *str_create() { @@ -59,8 +57,8 @@ void str_free(struct str *str) { free(str); } -int str_append_ch(struct str *str, typedef uint32_t ch) { - int size = utf8_chsize(ch); +intsize str_append_ch(struct str *str, uint32 ch) { + intsize size = utf8_chsize(ch); if (size <= 0) { return -1; } |