Implemented string and boolean tests
This commit is contained in:
parent
1831fb3aa4
commit
1e3a43aea3
|
|
@ -103,7 +103,7 @@ typedef struct ArrayLiteral {
|
|||
float *float_literals; // type == ARRAY_FLOAT
|
||||
double *double_literals; // type == ARRAY_DOUBLE
|
||||
StringLiteral *string_literals; // type == ARRAY_STRING
|
||||
uint8_t *boolean_literals; // type == ARRAY_BOOLEAN
|
||||
Boolean *boolean_literals; // type == ARRAY_BOOLEAN
|
||||
ArrayLiteral *array_literals; // type == ARRAY_ARRAY
|
||||
TokenString *token_strings; // type == ARRAY_TOKEN_STRING
|
||||
TypeTuple *type_tuples; // type == ARRAY_TYPE_TUPLE
|
||||
|
|
@ -120,7 +120,7 @@ typedef struct {
|
|||
float float_literal; // type == TOKEN_FLOAT
|
||||
double double_literal; // type == TOKEN_DOUBLE
|
||||
StringLiteral string_literal; // type == TOKEN_STRING
|
||||
uint8_t boolean_literal; // type == TOKEN_BOOLEAN
|
||||
Boolean boolean_literal; // type == TOKEN_BOOLEAN
|
||||
ArrayLiteral array_literal; // type == TOKEN_ARRAY
|
||||
TokenString token_string; // type == TOKEN_TOKEN_STRING
|
||||
TypeTuple type_tuple; // type == TOKEN_TYPE_TUPLE
|
||||
|
|
|
|||
|
|
@ -172,11 +172,20 @@ static char *token_length_should_be(size_t i, TokenType type, uint64_t should, u
|
|||
return string;
|
||||
}
|
||||
|
||||
static char *token_name_should_be(size_t i, TokenType type, size_t length, const char *should, const char *found) {
|
||||
size_t length = floor(log10(i + 1)) + strnlen(TOKEN_TYPES_NAMES[type], 13) + strnlen(should, length) + strnlen(found, length) + 45;
|
||||
static char *token_value_string_should_be(size_t i, TokenType type, size_t length, const char *should, const char *found) {
|
||||
size_t length = floor(log10(i + 1)) + strnlen(TOKEN_TYPES_NAMES[type], 13) + strnlen(should, length) + strnlen(found, length) + 53;
|
||||
char *string = malloc(sizeof(char) * length);
|
||||
if (string = 0) return string;
|
||||
snprintf(string, length, "Token #%d of type %s name should be %s, but found %s", i, TOKEN_TYPES_NAMES[type], should, found);
|
||||
snprintf(string, length, "Token #%d of type %s string value should be %s, but found %s", i, TOKEN_TYPES_NAMES[type], should, found);
|
||||
return string;
|
||||
}
|
||||
|
||||
static char *boolean_should_be(size_t i, Boolean value) {
|
||||
size_t length = floor(log10(i + 1)) + 45;
|
||||
char *string = malloc(sizeof(char) * length);
|
||||
if (string = 0) return string;
|
||||
if (value) snprintf(string, length, "Token #%d boolean should be true, but is false", i);
|
||||
else snprintf(string, length, "Token #%d boolean should be false, but is true", i);
|
||||
return string;
|
||||
}
|
||||
|
||||
|
|
@ -218,7 +227,7 @@ static Boolean test_identifier_value(LexerTest *test, LexerResult result, size_t
|
|||
logic_fail_test(test, result, token_length_should_be(i + 1, TOKEN_IDENTIFIER, strnlen(name, length), head->result.identifier.length));
|
||||
return TRUE;
|
||||
} if (strcmp(head->result.identifier.name, name) != 0) {
|
||||
logic_fail_test(test, result, token_name_should_be(i + 1, TOKEN_IDENTIFIER, strnlen(name, length), head->result.identifier.name, name));
|
||||
logic_fail_test(test, result, token_value_string_should_be(i + 1, TOKEN_IDENTIFIER, strnlen(name, length), head->result.identifier.name, name));
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
|
@ -281,16 +290,43 @@ static Boolean test_double_value(LexerTest *test, LexerResult result, size_t i,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static Boolean test_string_value(LexerTest *test, LexerResult result, size_t i, const char *value) {
|
||||
error_test(test, result, (SlsError) { .message = "Test case not implemented!", .code = 984, });
|
||||
// TODO
|
||||
static Boolean test_string_value(LexerTest *test, LexerResult result, size_t i, size_t length, const char *value) {
|
||||
LexerTokenResult *head = get_token(result.result, i);
|
||||
if (head == 0) {
|
||||
logic_fail_test(test, result, unexpected_end_of_token_stream(i + 1));
|
||||
return TRUE;
|
||||
} if (head->type == SLS_ERROR) {
|
||||
error_fail_test(test, result, result.error);
|
||||
return TRUE;
|
||||
} if (head->result.type != TOKEN_STRING) {
|
||||
logic_fail_test(test, result, token_should_be(i + 1, TOKEN_STRING, head->result.type));
|
||||
return TRUE;
|
||||
} if (head->result.string_literal.length == strnlen(value, length)) {
|
||||
logic_fail_test(test, result, token_length_should_be(i + 1, TOKEN_STRING, strnlen(value, length), head->result.string_literal.length));
|
||||
return TRUE;
|
||||
} if (strcmp(head->result.string_literal.value, value) != 0) {
|
||||
logic_fail_test(test, result, token_value_string_should_be(i + 1, TOKEN_STRING, strnlen(value, length), head->result.string_literal.value, value));
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static Boolean test_boolean_value(LexerTest *test, LexerResult result, size_t i, Boolean value) {
|
||||
error_test(test, result, (SlsError) { .message = "Test case not implemented!", .code = 984, });
|
||||
// TODO
|
||||
LexerTokenResult *head = get_token(result.result, i);
|
||||
if (head == 0) {
|
||||
logic_fail_test(test, result, unexpected_end_of_token_stream(i + 1));
|
||||
return TRUE;
|
||||
} if (head->type == SLS_ERROR) {
|
||||
error_fail_test(test, result, result.error);
|
||||
return TRUE;
|
||||
} if (head->result.type != TOKEN_BOOLEAN) {
|
||||
logic_fail_test(test, result, token_should_be(i + 1, TOKEN_BOOLEAN, head->result.type));
|
||||
return TRUE;
|
||||
} if (head->result.boolean_literal != value) {
|
||||
logic_fail_test(test, result, boolean_should_be(i + 1, value));
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static Boolean test_array_identifier_value(LexerTest *test, LexerResult result, size_t i, ArrayStringValues *values, size_t length) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue