mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Reworked Toy_String as a union, enabled -Wpedantic
Toy now fits into the C spec. Fixed #158 Addendum: MacOS test caught an error: error: a function declaration without a prototype is deprecated in all versions of C That took 3 attempts to fix correctly. Addendum: 'No new line at the end of file' are you shitting me?
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#compiler settings
|
||||
CC=gcc
|
||||
CFLAGS+=-std=c17 -g -Wall -Werror -Wextra -Wpointer-arith -Wformat=2
|
||||
CFLAGS+=-std=c17 -g -Wall -Werror -Wextra -Wpedantic -Wformat=2
|
||||
LIBS+=-lm
|
||||
LDFLAGS+=
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int test_array() {
|
||||
int test_array(void) {
|
||||
//test allocation and free
|
||||
{
|
||||
Toy_Array* array = TOY_ARRAY_ALLOCATE();
|
||||
@@ -35,7 +35,7 @@ int test_array() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
//run each test set, returning the total errors given
|
||||
int total = 0, res = 0;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int test_sizeof_ast_64bit() {
|
||||
int test_sizeof_ast_64bit(void) {
|
||||
//NOTE: This could've covered both bitness sizes as TEST_SIZEOF(type, bit32, bit32)
|
||||
#define TEST_SIZEOF(type, size) \
|
||||
if (sizeof(type) != size) { \
|
||||
@@ -44,7 +44,7 @@ int test_sizeof_ast_64bit() {
|
||||
return -err;
|
||||
}
|
||||
|
||||
int test_sizeof_ast_32bit() {
|
||||
int test_sizeof_ast_32bit(void) {
|
||||
#define TEST_SIZEOF(type, size) \
|
||||
if (sizeof(type) != size) { \
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: sizeof(" #type ") is %d, expected %d\n" TOY_CC_RESET, (int)sizeof(type), size); \
|
||||
@@ -376,8 +376,8 @@ int test_type_emission(Toy_Bucket** bucketHandle) {
|
||||
ast->type != TOY_AST_VAR_DECLARE ||
|
||||
|
||||
ast->varDeclare.name == NULL ||
|
||||
ast->varDeclare.name->type != TOY_STRING_NAME ||
|
||||
strcmp(ast->varDeclare.name->as.name.data, "foobar") != 0 ||
|
||||
ast->varDeclare.name->info.type != TOY_STRING_NAME ||
|
||||
strcmp(ast->varDeclare.name->name.data, "foobar") != 0 ||
|
||||
|
||||
ast->varDeclare.expr != NULL)
|
||||
{
|
||||
@@ -408,10 +408,10 @@ int test_type_emission(Toy_Bucket** bucketHandle) {
|
||||
ast->varAssign.target == NULL ||
|
||||
ast->varAssign.target->type != TOY_AST_VALUE ||
|
||||
TOY_VALUE_IS_STRING(ast->varAssign.target->value.value) != true ||
|
||||
TOY_VALUE_AS_STRING(ast->varAssign.target->value.value)->type != TOY_STRING_NAME ||
|
||||
strcmp(TOY_VALUE_AS_STRING(ast->varAssign.target->value.value)->as.name.data, "foobar") != 0 ||
|
||||
TOY_VALUE_AS_STRING(ast->varAssign.target->value.value)->info.type != TOY_STRING_NAME ||
|
||||
strcmp(TOY_VALUE_AS_STRING(ast->varAssign.target->value.value)->name.data, "foobar") != 0 ||
|
||||
|
||||
TOY_VALUE_AS_STRING(ast->varAssign.target->value.value)->as.name.type != TOY_VALUE_INTEGER ||
|
||||
TOY_VALUE_AS_STRING(ast->varAssign.target->value.value)->name.varType != TOY_VALUE_INTEGER ||
|
||||
|
||||
ast->varAssign.expr->type != TOY_AST_VALUE ||
|
||||
TOY_VALUE_AS_INTEGER(ast->varAssign.expr->value.value) != 69)
|
||||
@@ -436,9 +436,9 @@ int test_type_emission(Toy_Bucket** bucketHandle) {
|
||||
ast->varAccess.child == NULL ||
|
||||
ast->varAccess.child->type != TOY_AST_VALUE ||
|
||||
TOY_VALUE_IS_STRING(ast->varAccess.child->value.value) != true ||
|
||||
TOY_VALUE_AS_STRING(ast->varAccess.child->value.value)->type != TOY_STRING_NAME ||
|
||||
strcmp(TOY_VALUE_AS_STRING(ast->varAccess.child->value.value)->as.name.data, "foobar") != 0 ||
|
||||
TOY_VALUE_AS_STRING(ast->varAccess.child->value.value)->as.name.type != TOY_VALUE_INTEGER)
|
||||
TOY_VALUE_AS_STRING(ast->varAccess.child->value.value)->info.type != TOY_STRING_NAME ||
|
||||
strcmp(TOY_VALUE_AS_STRING(ast->varAccess.child->value.value)->name.data, "foobar") != 0 ||
|
||||
TOY_VALUE_AS_STRING(ast->varAccess.child->value.value)->name.varType != TOY_VALUE_INTEGER)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: failed to emit an access as 'Toy_Ast', state unknown\n" TOY_CC_RESET);
|
||||
return -1;
|
||||
@@ -491,7 +491,7 @@ int test_type_emission(Toy_Bucket** bucketHandle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
//run each test set, returning the total errors given
|
||||
int total = 0, res = 0;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int test_buckets() {
|
||||
int test_buckets(void) {
|
||||
//test initializing and freeing a bucket
|
||||
{
|
||||
//init
|
||||
@@ -72,7 +72,7 @@ int test_buckets() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
//run each test set, returning the total errors given
|
||||
int total = 0, res = 0;
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ int test_bytecode_from_source(Toy_Bucket** bucketHandle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
//run each test set, returning the total errors given
|
||||
int total = 0, res = 0;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
{
|
||||
//source code sample to operate on
|
||||
char* source = "print null;";
|
||||
|
||||
@@ -114,8 +114,8 @@ int test_var_declare(Toy_Bucket** bucketHandle) {
|
||||
ast->block.child->type != TOY_AST_VAR_DECLARE ||
|
||||
|
||||
ast->block.child->varDeclare.name == NULL ||
|
||||
ast->block.child->varDeclare.name->type != TOY_STRING_NAME ||
|
||||
strcmp(ast->block.child->varDeclare.name->as.name.data, "answer") != 0 ||
|
||||
ast->block.child->varDeclare.name->info.type != TOY_STRING_NAME ||
|
||||
strcmp(ast->block.child->varDeclare.name->name.data, "answer") != 0 ||
|
||||
|
||||
ast->block.child->varDeclare.expr == NULL ||
|
||||
ast->block.child->varDeclare.expr->type != TOY_AST_VALUE ||
|
||||
@@ -141,8 +141,8 @@ int test_var_declare(Toy_Bucket** bucketHandle) {
|
||||
ast->block.child->type != TOY_AST_VAR_DECLARE ||
|
||||
|
||||
ast->block.child->varDeclare.name == NULL ||
|
||||
ast->block.child->varDeclare.name->type != TOY_STRING_NAME ||
|
||||
strcmp(ast->block.child->varDeclare.name->as.name.data, "empty") != 0 ||
|
||||
ast->block.child->varDeclare.name->info.type != TOY_STRING_NAME ||
|
||||
strcmp(ast->block.child->varDeclare.name->name.data, "empty") != 0 ||
|
||||
|
||||
ast->block.child->varDeclare.expr == NULL ||
|
||||
ast->block.child->varDeclare.expr->type != TOY_AST_VALUE ||
|
||||
@@ -173,8 +173,8 @@ int test_var_assign(Toy_Bucket** bucketHandle) {
|
||||
ast->block.child->varAssign.target == NULL || \
|
||||
ast->block.child->varAssign.target->type != TOY_AST_VALUE || \
|
||||
TOY_VALUE_IS_STRING(ast->block.child->varAssign.target->value.value) != true ||\
|
||||
TOY_VALUE_AS_STRING(ast->block.child->varAssign.target->value.value)->type != TOY_STRING_NAME ||\
|
||||
strcmp(TOY_VALUE_AS_STRING(ast->block.child->varAssign.target->value.value)->as.name.data, ARG_NAME) != 0 || \
|
||||
TOY_VALUE_AS_STRING(ast->block.child->varAssign.target->value.value)->info.type != TOY_STRING_NAME ||\
|
||||
strcmp(TOY_VALUE_AS_STRING(ast->block.child->varAssign.target->value.value)->name.data, ARG_NAME) != 0 || \
|
||||
ast->block.child->varAssign.expr == NULL || \
|
||||
ast->block.child->varAssign.expr->type != TOY_AST_VALUE || \
|
||||
TOY_VALUE_IS_INTEGER(ast->block.child->varAssign.expr->value.value) == false || \
|
||||
@@ -316,8 +316,8 @@ int test_values(Toy_Bucket** bucketHandle) {
|
||||
ast->block.child == NULL ||
|
||||
ast->block.child->type != TOY_AST_VALUE ||
|
||||
TOY_VALUE_IS_STRING(ast->block.child->value.value) == false ||
|
||||
TOY_VALUE_AS_STRING(ast->block.child->value.value)->type != TOY_STRING_LEAF ||
|
||||
strcmp(TOY_VALUE_AS_STRING(ast->block.child->value.value)->as.leaf.data, "Hello world!") != 0)
|
||||
TOY_VALUE_AS_STRING(ast->block.child->value.value)->info.type != TOY_STRING_LEAF ||
|
||||
strcmp(TOY_VALUE_AS_STRING(ast->block.child->value.value)->leaf.data, "Hello world!") != 0)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: failed to run the parser with string value 'Hello world!'\n" TOY_CC_RESET);
|
||||
return -1;
|
||||
@@ -517,8 +517,8 @@ int test_aggregate(Toy_Bucket** bucketHandle) {
|
||||
ast->block.child->aggregate.left->varAccess.child == NULL ||
|
||||
ast->block.child->aggregate.left->varAccess.child->type != TOY_AST_VALUE ||
|
||||
TOY_VALUE_IS_STRING(ast->block.child->aggregate.left->varAccess.child->value.value) != true ||
|
||||
TOY_VALUE_AS_STRING(ast->block.child->aggregate.left->varAccess.child->value.value)->type != TOY_STRING_NAME ||
|
||||
strcmp(TOY_VALUE_AS_STRING(ast->block.child->aggregate.left->varAccess.child->value.value)->as.name.data, "name") != 0 ||
|
||||
TOY_VALUE_AS_STRING(ast->block.child->aggregate.left->varAccess.child->value.value)->info.type != TOY_STRING_NAME ||
|
||||
strcmp(TOY_VALUE_AS_STRING(ast->block.child->aggregate.left->varAccess.child->value.value)->name.data, "name") != 0 ||
|
||||
|
||||
ast->block.child->aggregate.right->type != TOY_AST_VALUE ||
|
||||
TOY_VALUE_IS_INTEGER(ast->block.child->aggregate.right->value.value) != true ||
|
||||
@@ -551,9 +551,9 @@ int test_aggregate(Toy_Bucket** bucketHandle) {
|
||||
ast->block.child->aggregate.left->varAccess.child == NULL ||
|
||||
ast->block.child->aggregate.left->varAccess.child->type != TOY_AST_VALUE ||
|
||||
TOY_VALUE_IS_STRING(ast->block.child->aggregate.left->varAccess.child->value.value) != true ||
|
||||
TOY_VALUE_AS_STRING(ast->block.child->aggregate.left->varAccess.child->value.value)->type != TOY_STRING_NAME ||
|
||||
TOY_VALUE_AS_STRING(ast->block.child->aggregate.left->varAccess.child->value.value)->info.type != TOY_STRING_NAME ||
|
||||
|
||||
strcmp(TOY_VALUE_AS_STRING(ast->block.child->aggregate.left->varAccess.child->value.value)->as.name.data, "name") != 0 ||
|
||||
strcmp(TOY_VALUE_AS_STRING(ast->block.child->aggregate.left->varAccess.child->value.value)->name.data, "name") != 0 ||
|
||||
|
||||
ast->block.child->aggregate.right->type != TOY_AST_AGGREGATE ||
|
||||
ast->block.child->aggregate.right->aggregate.flag != TOY_AST_FLAG_COLLECTION ||
|
||||
@@ -622,8 +622,8 @@ int test_keywords(Toy_Bucket** bucketHandle) {
|
||||
ast->block.child->assert.message == NULL ||
|
||||
ast->block.child->assert.message->type != TOY_AST_VALUE ||
|
||||
TOY_VALUE_IS_STRING(ast->block.child->assert.message->value.value) == false ||
|
||||
TOY_VALUE_AS_STRING(ast->block.child->assert.message->value.value)->type != TOY_STRING_LEAF ||
|
||||
strncmp(TOY_VALUE_AS_STRING(ast->block.child->assert.message->value.value)->as.leaf.data, "foo", 3) != 0)
|
||||
TOY_VALUE_AS_STRING(ast->block.child->assert.message->value.value)->info.type != TOY_STRING_LEAF ||
|
||||
strncmp(TOY_VALUE_AS_STRING(ast->block.child->assert.message->value.value)->leaf.data, "foo", 3) != 0)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: failed to run the parser, source: %s\n" TOY_CC_RESET, source);
|
||||
return -1;
|
||||
@@ -645,8 +645,8 @@ int test_keywords(Toy_Bucket** bucketHandle) {
|
||||
ast->block.child->print.child == NULL ||
|
||||
ast->block.child->print.child->type != TOY_AST_VALUE ||
|
||||
TOY_VALUE_IS_STRING(ast->block.child->print.child->value.value) == false ||
|
||||
TOY_VALUE_AS_STRING(ast->block.child->print.child->value.value)->type != TOY_STRING_LEAF ||
|
||||
strncmp(TOY_VALUE_AS_STRING(ast->block.child->print.child->value.value)->as.leaf.data, "foo", 3) != 0)
|
||||
TOY_VALUE_AS_STRING(ast->block.child->print.child->value.value)->info.type != TOY_STRING_LEAF ||
|
||||
strncmp(TOY_VALUE_AS_STRING(ast->block.child->print.child->value.value)->leaf.data, "foo", 3) != 0)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: failed to run the parser, source: %s\n" TOY_CC_RESET, source);
|
||||
return -1;
|
||||
@@ -678,8 +678,8 @@ int test_keywords(Toy_Bucket** bucketHandle) {
|
||||
ast->block.child->ifThenElse.thenBranch->block.child->print.child == NULL ||
|
||||
ast->block.child->ifThenElse.thenBranch->block.child->print.child->type != TOY_AST_VALUE ||
|
||||
TOY_VALUE_IS_STRING(ast->block.child->ifThenElse.thenBranch->block.child->print.child->value.value) == false ||
|
||||
TOY_VALUE_AS_STRING(ast->block.child->ifThenElse.thenBranch->block.child->print.child->value.value)->type != TOY_STRING_LEAF ||
|
||||
strncmp(TOY_VALUE_AS_STRING(ast->block.child->ifThenElse.thenBranch->block.child->print.child->value.value)->as.leaf.data, "foo", 3) != 0 ||
|
||||
TOY_VALUE_AS_STRING(ast->block.child->ifThenElse.thenBranch->block.child->print.child->value.value)->info.type != TOY_STRING_LEAF ||
|
||||
strncmp(TOY_VALUE_AS_STRING(ast->block.child->ifThenElse.thenBranch->block.child->print.child->value.value)->leaf.data, "foo", 3) != 0 ||
|
||||
|
||||
ast->block.child->ifThenElse.elseBranch != NULL)
|
||||
{
|
||||
@@ -713,8 +713,8 @@ int test_keywords(Toy_Bucket** bucketHandle) {
|
||||
ast->block.child->ifThenElse.thenBranch->block.child->print.child == NULL ||
|
||||
ast->block.child->ifThenElse.thenBranch->block.child->print.child->type != TOY_AST_VALUE ||
|
||||
TOY_VALUE_IS_STRING(ast->block.child->ifThenElse.thenBranch->block.child->print.child->value.value) == false ||
|
||||
TOY_VALUE_AS_STRING(ast->block.child->ifThenElse.thenBranch->block.child->print.child->value.value)->type != TOY_STRING_LEAF ||
|
||||
strncmp(TOY_VALUE_AS_STRING(ast->block.child->ifThenElse.thenBranch->block.child->print.child->value.value)->as.leaf.data, "foo", 3) != 0 ||
|
||||
TOY_VALUE_AS_STRING(ast->block.child->ifThenElse.thenBranch->block.child->print.child->value.value)->info.type != TOY_STRING_LEAF ||
|
||||
strncmp(TOY_VALUE_AS_STRING(ast->block.child->ifThenElse.thenBranch->block.child->print.child->value.value)->leaf.data, "foo", 3) != 0 ||
|
||||
|
||||
ast->block.child->ifThenElse.elseBranch == NULL ||
|
||||
ast->block.child->ifThenElse.elseBranch->type != TOY_AST_BLOCK ||
|
||||
@@ -723,8 +723,8 @@ int test_keywords(Toy_Bucket** bucketHandle) {
|
||||
ast->block.child->ifThenElse.elseBranch->block.child->print.child == NULL ||
|
||||
ast->block.child->ifThenElse.elseBranch->block.child->print.child->type != TOY_AST_VALUE ||
|
||||
TOY_VALUE_IS_STRING(ast->block.child->ifThenElse.elseBranch->block.child->print.child->value.value) == false ||
|
||||
TOY_VALUE_AS_STRING(ast->block.child->ifThenElse.elseBranch->block.child->print.child->value.value)->type != TOY_STRING_LEAF ||
|
||||
strncmp(TOY_VALUE_AS_STRING(ast->block.child->ifThenElse.elseBranch->block.child->print.child->value.value)->as.leaf.data, "bar", 3) != 0 ||
|
||||
TOY_VALUE_AS_STRING(ast->block.child->ifThenElse.elseBranch->block.child->print.child->value.value)->info.type != TOY_STRING_LEAF ||
|
||||
strncmp(TOY_VALUE_AS_STRING(ast->block.child->ifThenElse.elseBranch->block.child->print.child->value.value)->leaf.data, "bar", 3) != 0 ||
|
||||
|
||||
false)
|
||||
{
|
||||
@@ -881,7 +881,7 @@ int test_precedence(Toy_Bucket** bucketHandle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
//run each test set, returning the total errors given
|
||||
int total = 0, res = 0;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ void count(const char* msg) {
|
||||
counter++;
|
||||
}
|
||||
|
||||
int test_callbacks() {
|
||||
int test_callbacks(void) {
|
||||
//set a custom print callback, invoke it, and reset
|
||||
{
|
||||
//setup
|
||||
@@ -95,7 +95,7 @@ int test_callbacks() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
//run each test set, returning the total errors given
|
||||
int total = 0, res = 0;
|
||||
|
||||
|
||||
@@ -1307,7 +1307,7 @@ int test_routine_keywords(Toy_Bucket** bucketHandle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
//run each test set, returning the total errors given
|
||||
int total = 0, res = 0;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
|
||||
|
||||
int test_scope_allocation() {
|
||||
int test_scope_allocation(void) {
|
||||
//allocate and free a scope
|
||||
{
|
||||
//setup
|
||||
@@ -297,7 +297,7 @@ int test_scope_allocation() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_scope_elements() {
|
||||
int test_scope_elements(void) {
|
||||
//allocate, access and assign an element
|
||||
{
|
||||
//setup
|
||||
@@ -489,7 +489,7 @@ int test_scope_elements() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
//run each test set, returning the total errors given
|
||||
int total = 0, res = 0;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int test_stack_basics() {
|
||||
int test_stack_basics(void) {
|
||||
//allocate and free the stack
|
||||
{
|
||||
Toy_Stack* stack = Toy_allocateStack();
|
||||
@@ -82,7 +82,7 @@ int test_stack_basics() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_stack_stress() {
|
||||
int test_stack_stress(void) {
|
||||
//stress the stack's contents
|
||||
{
|
||||
Toy_Stack* stack = Toy_allocateStack();
|
||||
@@ -109,7 +109,7 @@ int test_stack_stress() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
//run each test set, returning the total errors given
|
||||
int total = 0, res = 0;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int test_sizeof_string_64bit() {
|
||||
int test_sizeof_string_64bit(void) {
|
||||
//test for the correct size
|
||||
{
|
||||
if (sizeof(Toy_String) != 32) {
|
||||
@@ -19,7 +19,7 @@ int test_sizeof_string_64bit() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_sizeof_string_32bit() {
|
||||
int test_sizeof_string_32bit(void) {
|
||||
//test for the correct size
|
||||
{
|
||||
if (sizeof(Toy_String) != 24) {
|
||||
@@ -31,7 +31,7 @@ int test_sizeof_string_32bit() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_string_allocation() {
|
||||
int test_string_allocation(void) {
|
||||
//allocate a single string from a c-string
|
||||
{
|
||||
//setup
|
||||
@@ -41,10 +41,10 @@ int test_string_allocation() {
|
||||
Toy_String* str = Toy_createString(&bucket, cstring);
|
||||
|
||||
//check
|
||||
if (str->type != TOY_STRING_LEAF ||
|
||||
str->length != 11 ||
|
||||
str->refCount != 1 ||
|
||||
strcmp(str->as.leaf.data, "Hello world") != 0)
|
||||
if (str->info.type != TOY_STRING_LEAF ||
|
||||
str->info.length != 11 ||
|
||||
str->info.refCount != 1 ||
|
||||
strcmp(str->leaf.data, "Hello world") != 0)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: Failed to allocate a Toy_String with a private bucket\n" TOY_CC_RESET);
|
||||
Toy_freeBucket(&bucket);
|
||||
@@ -88,9 +88,9 @@ int test_string_allocation() {
|
||||
|
||||
if (str != shallow ||
|
||||
str == deep ||
|
||||
shallow->refCount != 2 ||
|
||||
deep->refCount != 1 ||
|
||||
strcmp(shallow->as.leaf.data, deep->as.leaf.data) != 0)
|
||||
shallow->info.refCount != 2 ||
|
||||
deep->info.refCount != 1 ||
|
||||
strcmp(shallow->leaf.data, deep->leaf.data) != 0)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: Failed to copy a string correctly\n" TOY_CC_RESET);
|
||||
Toy_freeBucket(&bucket);
|
||||
@@ -114,9 +114,9 @@ int test_string_allocation() {
|
||||
|
||||
if (str != shallow ||
|
||||
str == deep ||
|
||||
shallow->refCount != 2 ||
|
||||
deep->refCount != 1 ||
|
||||
strcmp(shallow->as.name.data, deep->as.name.data) != 0)
|
||||
shallow->info.refCount != 2 ||
|
||||
deep->info.refCount != 1 ||
|
||||
strcmp(shallow->name.data, deep->name.data) != 0)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: Failed to copy a name string correctly\n" TOY_CC_RESET);
|
||||
Toy_freeBucket(&bucket);
|
||||
@@ -135,10 +135,10 @@ int test_string_allocation() {
|
||||
Toy_String* str = Toy_createString(&bucket, cstring);
|
||||
|
||||
//check
|
||||
if (str->type != TOY_STRING_LEAF ||
|
||||
str->length != 0 ||
|
||||
str->refCount != 1 ||
|
||||
strcmp(str->as.leaf.data, "") != 0)
|
||||
if (str->info.type != TOY_STRING_LEAF ||
|
||||
str->info.length != 0 ||
|
||||
str->info.refCount != 1 ||
|
||||
strcmp(str->leaf.data, "") != 0)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: Failed to allocate a Toy_String with zero length\n" TOY_CC_RESET);
|
||||
Toy_freeBucket(&bucket);
|
||||
@@ -154,7 +154,7 @@ int test_string_allocation() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_string_concatenation() {
|
||||
int test_string_concatenation(void) {
|
||||
//one big bucket o' fun
|
||||
Toy_Bucket* bucket = Toy_allocateBucket(1024);
|
||||
|
||||
@@ -168,10 +168,10 @@ int test_string_concatenation() {
|
||||
Toy_String* result = Toy_concatStrings(&bucket, first, second);
|
||||
|
||||
//check the refcounts
|
||||
if (first->refCount != 2 ||
|
||||
second->refCount != 2 ||
|
||||
result->refCount != 1 ||
|
||||
result->length != 11)
|
||||
if (first->info.refCount != 2 ||
|
||||
second->info.refCount != 2 ||
|
||||
result->info.refCount != 1 ||
|
||||
result->info.length != 11)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: Unexpected state for string refcounts after concatenation\n" TOY_CC_RESET);
|
||||
Toy_freeBucket(&bucket);
|
||||
@@ -183,10 +183,10 @@ int test_string_concatenation() {
|
||||
Toy_freeString(second);
|
||||
|
||||
//check the refcounts again
|
||||
if (first->refCount != 1 ||
|
||||
second->refCount != 1 ||
|
||||
result->refCount != 1 ||
|
||||
result->length != 11)
|
||||
if (first->info.refCount != 1 ||
|
||||
second->info.refCount != 1 ||
|
||||
result->info.refCount != 1 ||
|
||||
result->info.length != 11)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: Unexpected state for string refcounts after concatenation and free\n" TOY_CC_RESET);
|
||||
Toy_freeBucket(&bucket);
|
||||
@@ -228,7 +228,7 @@ int test_string_concatenation() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_string_with_stressed_bucket() {
|
||||
int test_string_with_stressed_bucket(void) {
|
||||
//how much is that dog in the window?
|
||||
{
|
||||
//test data: 36 characters total, 44 with spaces
|
||||
@@ -256,8 +256,8 @@ int test_string_with_stressed_bucket() {
|
||||
}
|
||||
|
||||
//check
|
||||
if (ptr->refCount != 9 ||
|
||||
str->length != 36)
|
||||
if (ptr->info.refCount != 9 ||
|
||||
str->info.length != 36)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: Unexpected state of the string after stress test\n" TOY_CC_RESET);
|
||||
Toy_freeBucket(&bucket);
|
||||
@@ -293,7 +293,7 @@ int test_string_with_stressed_bucket() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_string_equality() {
|
||||
int test_string_equality(void) {
|
||||
//simple string equality (no concats)
|
||||
{
|
||||
//setup
|
||||
@@ -700,7 +700,7 @@ int test_string_equality() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_string_diffs() {
|
||||
int test_string_diffs(void) {
|
||||
//simple string diffs (no concats)
|
||||
{
|
||||
//setup
|
||||
@@ -791,7 +791,7 @@ int test_string_diffs() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_string_fragmenting() {
|
||||
int test_string_fragmenting(void) {
|
||||
//allocate a long string
|
||||
{
|
||||
//setup
|
||||
@@ -803,9 +803,9 @@ int test_string_fragmenting() {
|
||||
Toy_String* str = Toy_createString(&bucket, cstring);
|
||||
|
||||
//check
|
||||
if (str->type != TOY_STRING_NODE ||
|
||||
str->length != 445 ||
|
||||
str->refCount != 1)
|
||||
if (str->info.type != TOY_STRING_NODE ||
|
||||
str->info.length != 445 ||
|
||||
str->info.refCount != 1)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: Failed to fragment a string within Toy_String\n" TOY_CC_RESET);
|
||||
Toy_freeString(str);
|
||||
@@ -821,7 +821,7 @@ int test_string_fragmenting() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
//run each test set, returning the total errors given
|
||||
int total = 0, res = 0;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int test_table_allocation() {
|
||||
int test_table_allocation(void) {
|
||||
//allocate and free a table
|
||||
{
|
||||
//setup
|
||||
@@ -24,7 +24,7 @@ int test_table_allocation() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_table_simple_insert_lookup_and_remove() {
|
||||
int test_table_simple_insert_lookup_and_remove(void) {
|
||||
//simple insert
|
||||
{
|
||||
//setup
|
||||
@@ -86,7 +86,7 @@ int test_table_simple_insert_lookup_and_remove() {
|
||||
TOY_VALUE_AS_INTEGER(table->data[i].value) != v || \
|
||||
table->data[i].psl != p
|
||||
|
||||
int test_table_contents_no_expansion() {
|
||||
int test_table_contents_no_expansion(void) {
|
||||
//single insert
|
||||
{
|
||||
//setup
|
||||
@@ -302,7 +302,7 @@ int test_table_contents_no_expansion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_table_contents_with_expansions() {
|
||||
int test_table_contents_with_expansions(void) {
|
||||
//simple expansion
|
||||
{
|
||||
//setup
|
||||
@@ -569,7 +569,7 @@ int test_table_contents_with_expansions() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_table_expansions_under_stress() {
|
||||
int test_table_expansions_under_stress(void) {
|
||||
//multiple expansions, find one value
|
||||
{
|
||||
//setup
|
||||
@@ -605,7 +605,7 @@ int test_table_expansions_under_stress() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
//run each test set, returning the total errors given
|
||||
int total = 0, res = 0;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int test_value_creation() {
|
||||
int test_value_creation(void) {
|
||||
//test for the correct size
|
||||
{
|
||||
#if TOY_BITNESS == 64
|
||||
@@ -52,8 +52,8 @@ int test_value_creation() {
|
||||
Toy_Value greeting = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "Hello world!"));
|
||||
|
||||
if (TOY_VALUE_IS_STRING(greeting) == false ||
|
||||
TOY_VALUE_AS_STRING(greeting)->type != TOY_STRING_LEAF ||
|
||||
strcmp(TOY_VALUE_AS_STRING(greeting)->as.leaf.data, "Hello world!") != 0
|
||||
TOY_VALUE_AS_STRING(greeting)->info.type != TOY_STRING_LEAF ||
|
||||
strcmp(TOY_VALUE_AS_STRING(greeting)->leaf.data, "Hello world!") != 0
|
||||
)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: 'string' value failed\n" TOY_CC_RESET);
|
||||
@@ -95,7 +95,7 @@ int test_value_creation() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_value_copying() {
|
||||
int test_value_copying(void) {
|
||||
//test simple integer copy
|
||||
{
|
||||
Toy_Value original = TOY_VALUE_FROM_INTEGER(42);
|
||||
@@ -118,9 +118,9 @@ int test_value_copying() {
|
||||
Toy_Value result = Toy_copyValue(original);
|
||||
|
||||
if (TOY_VALUE_IS_STRING(result) == false ||
|
||||
TOY_VALUE_AS_STRING(result)->type != TOY_STRING_LEAF ||
|
||||
strcmp(TOY_VALUE_AS_STRING(result)->as.leaf.data, "Hello world!") != 0 ||
|
||||
TOY_VALUE_AS_STRING(result)->refCount != 2
|
||||
TOY_VALUE_AS_STRING(result)->info.type != TOY_STRING_LEAF ||
|
||||
strcmp(TOY_VALUE_AS_STRING(result)->leaf.data, "Hello world!") != 0 ||
|
||||
TOY_VALUE_AS_STRING(result)->info.refCount != 2
|
||||
)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: copy a string value failed\n" TOY_CC_RESET);
|
||||
@@ -172,7 +172,7 @@ int test_value_copying() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_value_hashing() {
|
||||
int test_value_hashing(void) {
|
||||
//test value hashing
|
||||
{
|
||||
//setup
|
||||
@@ -197,7 +197,7 @@ int test_value_hashing() {
|
||||
Toy_hashValue(f) != 0 ||
|
||||
Toy_hashValue(i) != 4147366645 ||
|
||||
Toy_hashValue(s) != 994097935 ||
|
||||
TOY_VALUE_AS_STRING(s)->cachedHash == 0 ||
|
||||
TOY_VALUE_AS_STRING(s)->info.cachedHash == 0 ||
|
||||
Toy_hashValue(a) != 2544446955
|
||||
)
|
||||
{
|
||||
@@ -215,7 +215,7 @@ int test_value_hashing() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_value_equality() {
|
||||
int test_value_equality(void) {
|
||||
//test value equality
|
||||
{
|
||||
Toy_Value answer = TOY_VALUE_FROM_INTEGER(42);
|
||||
@@ -290,7 +290,7 @@ int test_value_equality() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_value_comparison() {
|
||||
int test_value_comparison(void) {
|
||||
//test value comparable
|
||||
{
|
||||
Toy_Value answer = TOY_VALUE_FROM_INTEGER(42);
|
||||
@@ -353,7 +353,7 @@ int test_value_comparison() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_value_stringify() {
|
||||
int test_value_stringify(void) {
|
||||
//stringify null
|
||||
{
|
||||
//setup
|
||||
@@ -364,8 +364,8 @@ int test_value_stringify() {
|
||||
Toy_String* string = Toy_stringifyValue(&bucket, value);
|
||||
|
||||
//check
|
||||
if (string->type != TOY_STRING_LEAF ||
|
||||
strcmp(string->as.leaf.data, "null") != 0)
|
||||
if (string->info.type != TOY_STRING_LEAF ||
|
||||
strcmp(string->leaf.data, "null") != 0)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: stringify 'null' failed\n" TOY_CC_RESET);
|
||||
Toy_freeString(string);
|
||||
@@ -390,8 +390,8 @@ int test_value_stringify() {
|
||||
Toy_String* string = Toy_stringifyValue(&bucket, value);
|
||||
|
||||
//check
|
||||
if (string->type != TOY_STRING_LEAF ||
|
||||
strcmp(string->as.leaf.data, "true") != 0)
|
||||
if (string->info.type != TOY_STRING_LEAF ||
|
||||
strcmp(string->leaf.data, "true") != 0)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: stringify boolean 'true' failed\n" TOY_CC_RESET);
|
||||
Toy_freeString(string);
|
||||
@@ -416,8 +416,8 @@ int test_value_stringify() {
|
||||
Toy_String* string = Toy_stringifyValue(&bucket, value);
|
||||
|
||||
//check
|
||||
if (string->type != TOY_STRING_LEAF ||
|
||||
strcmp(string->as.leaf.data, "false") != 0)
|
||||
if (string->info.type != TOY_STRING_LEAF ||
|
||||
strcmp(string->leaf.data, "false") != 0)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: stringify boolean 'false' failed\n" TOY_CC_RESET);
|
||||
Toy_freeString(string);
|
||||
@@ -442,8 +442,8 @@ int test_value_stringify() {
|
||||
Toy_String* string = Toy_stringifyValue(&bucket, value);
|
||||
|
||||
//check
|
||||
if (string->type != TOY_STRING_LEAF ||
|
||||
strcmp(string->as.leaf.data, "42") != 0)
|
||||
if (string->info.type != TOY_STRING_LEAF ||
|
||||
strcmp(string->leaf.data, "42") != 0)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: stringify integer '42' failed\n" TOY_CC_RESET);
|
||||
Toy_freeString(string);
|
||||
@@ -468,8 +468,8 @@ int test_value_stringify() {
|
||||
Toy_String* string = Toy_stringifyValue(&bucket, value);
|
||||
|
||||
//check
|
||||
if (string->type != TOY_STRING_LEAF ||
|
||||
strcmp(string->as.leaf.data, "3.1415") != 0)
|
||||
if (string->info.type != TOY_STRING_LEAF ||
|
||||
strcmp(string->leaf.data, "3.1415") != 0)
|
||||
{
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: stringify float '3.1415' failed\n" TOY_CC_RESET);
|
||||
Toy_freeString(string);
|
||||
@@ -539,7 +539,7 @@ int test_value_stringify() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
//run each test set, returning the total errors given
|
||||
int total = 0, res = 0;
|
||||
|
||||
|
||||
@@ -806,7 +806,7 @@ int test_vm_reuse(Toy_Bucket** bucketHandle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
//run each test set, returning the total errors given
|
||||
int total = 0, res = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user