Renamed Node to ASTNode

This commit is contained in:
2022-09-18 19:14:37 +01:00
parent 2458996ee7
commit 6a086395be
13 changed files with 495 additions and 495 deletions

57
test/test_ast_node.c Normal file
View File

@@ -0,0 +1,57 @@
#include "ast_node.h"
#include "memory.h"
#include "console_colors.h"
#include <stdio.h>
int main() {
{
//test literals
char* str = "foobar";
Literal literal = TO_STRING_LITERAL(copyString(str, strlen(str)), strlen(str));
ASTNode* node;
emitASTNodeLiteral(&node, literal);
freeLiteral(literal);
freeNode(node);
}
{
//test compound (dictionary)
char* idn = "foobar";
char* str = "hello world";
ASTNode* dictionary;
ASTNode* left;
ASTNode* right;
Literal identifier = TO_IDENTIFIER_LITERAL(copyString(idn, strlen(idn)), strlen(idn));
Literal string = TO_STRING_LITERAL(copyString(str, strlen(str)), strlen(str));
emitASTNodeCompound(&dictionary, LITERAL_DICTIONARY);
emitASTNodeLiteral(&left, identifier);
emitASTNodeLiteral(&right, string);
//grow the node if needed
if (dictionary->compound.capacity < dictionary->compound.count + 1) {
int oldCapacity = dictionary->compound.capacity;
dictionary->compound.capacity = GROW_CAPACITY(oldCapacity);
dictionary->compound.nodes = GROW_ARRAY(ASTNode, dictionary->compound.nodes, oldCapacity, dictionary->compound.capacity);
}
//store the left and right in the node
setASTNodePair(&dictionary->compound.nodes[dictionary->compound.count++], left, right);
//the real test
freeNode(dictionary);
freeLiteral(identifier);
freeLiteral(string);
}
printf(NOTICE "All good\n" RESET);
return 0;
}