aboutsummaryrefslogtreecommitdiff
path: root/tests/test_parsing.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_parsing.py')
-rw-r--r--tests/test_parsing.py67
1 files changed, 1 insertions, 66 deletions
diff --git a/tests/test_parsing.py b/tests/test_parsing.py
index 7463fe7..9b151ae 100644
--- a/tests/test_parsing.py
+++ b/tests/test_parsing.py
@@ -1,73 +1,8 @@
import unittest
-from crowbar_reference_compiler import parse_header, parse_implementation, scan
+from crowbar_reference_compiler import parse_header, scan
class TestParsing(unittest.TestCase):
def test_basic(self):
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"""
-struct str {
- (uint8[size])* str;
- uintsize len;
- uintsize size;
-}
-
-struct str *str_create();
-void str_free(struct str *str);
-void str_reset(struct str *str);
-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.hro";
-include "stdint.hro";
-include "str.hro";
-include "unicode.hro";
-
-bool ensure_capacity(struct str *str, intsize len) {
- if (len + 1 >= str->size) {
- (uint8[str->size * 2])* new = realloc(str->str, str->size * 2);
- if (!new) {
- return false;
- }
- str->str = new;
- str->size *= 2;
- }
- return true;
-}
-
-struct str *str_create() {
- struct str *str = calloc(1, sizeof(struct str));
- str->str = malloc(16);
- str->size = 16;
- str->len = 0;
- str->str[0] = '\0';
- return str;
-}
-
-void str_free(struct str *str) {
- if (!str) {
- return;
- }
- free(str->str);
- free(str);
-}
-
-intsize str_append_ch(struct str *str, uint32 ch) {
- intsize size = utf8_chsize(ch);
- if (size <= 0) {
- return -1;
- }
- if (!ensure_capacity(str, str->len + size)) {
- return -1;
- }
- utf8_encode(&str->str[str->len], ch);
- str->len += size;
- str->str[str->len] = '\0';
- return size;
-}
-""")))