aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/struct_basics.sh
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-10-04 15:33:07 +0900
committernsfisis <nsfisis@gmail.com>2025-10-04 15:33:10 +0900
commit46e79e69ae866df88cb9442a7329c72662ed2db3 (patch)
tree13561c1e7273ed0311da37957e4a82d15b243ba4 /tests/struct_basics.sh
parent7e11675136edf8136f812c85cd45bc88ba405533 (diff)
downloadducc-46e79e69ae866df88cb9442a7329c72662ed2db3.tar.gz
ducc-46e79e69ae866df88cb9442a7329c72662ed2db3.tar.zst
ducc-46e79e69ae866df88cb9442a7329c72662ed2db3.zip
refactor: rename test files
Diffstat (limited to 'tests/struct_basics.sh')
-rw-r--r--tests/struct_basics.sh121
1 files changed, 121 insertions, 0 deletions
diff --git a/tests/struct_basics.sh b/tests/struct_basics.sh
new file mode 100644
index 0000000..74e2458
--- /dev/null
+++ b/tests/struct_basics.sh
@@ -0,0 +1,121 @@
+cat <<'EOF' > expected
+EOF
+test_diff <<'EOF'
+struct Token {
+ int kind;
+ char* value;
+};
+
+struct Define {
+ char* from;
+ struct Token* to;
+};
+
+struct AstNode;
+
+struct Type {
+ int kind;
+ struct Type* to;
+ struct AstNode* members;
+};
+
+struct AstNode {
+ int kind;
+ struct AstNode* next;
+ struct AstNode* last;
+ char* name;
+ struct AstNode* func_params;
+ struct AstNode* func_body;
+ int int_value;
+ struct AstNode* expr1;
+ struct AstNode* expr2;
+ struct AstNode* expr3;
+ int op;
+ struct Type* ty;
+ int var_index;
+ struct AstNode* node1;
+ struct AstNode* node2;
+ char** str_literals;
+};
+
+struct LVar {
+ char* name;
+ struct Type* ty;
+};
+
+struct Func {
+ char* name;
+ struct Type* ty;
+};
+
+struct Parser {
+ struct Token* tokens;
+ int pos;
+ struct LVar* locals;
+ int n_locals;
+ struct Func* funcs;
+ int n_funcs;
+ char** str_literals;
+ int n_str_literals;
+};
+
+struct CodeGen {
+ int next_label;
+ int* loop_labels;
+};
+
+int main() {
+ return 0;
+}
+EOF
+
+cat <<'EOF' > expected
+42
+123
+EOF
+test_diff <<'EOF'
+struct S {
+ int a;
+ int b;
+};
+
+int printf();
+void* calloc();
+
+int main() {
+ struct S* sp;
+ sp = calloc(1, sizeof(struct S));
+ sp->a = 42;
+ printf("%d\n", sp->a);
+ (*sp).b = 123;
+ printf("%d\n", (*sp).b);
+ return 0;
+}
+EOF
+
+cat <<'EOF' > expected
+42
+EOF
+test_diff <<'EOF'
+void* calloc();
+int printf();
+
+struct T;
+
+struct S {
+ struct T* a;
+};
+
+struct T {
+ int b;
+};
+
+int main() {
+ struct S* s = calloc(1, sizeof(struct S));
+ s->a = calloc(1, sizeof(struct T));
+ s->a->b = 42;
+ printf("%d\n", s->a->b);
+ return 0;
+}
+EOF
+