Implemented float and double test helpers
This commit is contained in:
parent
9f453d5373
commit
74a84cf47b
|
|
@ -133,13 +133,21 @@ static char *integer_type_should_be(size_t i, TokenType should, TokenType found)
|
|||
}
|
||||
|
||||
static char *integer_value_should_be(size_t i, uint64_t should, uint64_t found) {
|
||||
size_t length = floor(log10(i + 1)) + floor(log10(should + 1)) + floor(log10(found + 1)) + 21;
|
||||
size_t length = floor(log10(i + 1)) + floor(log10(should + 1)) + floor(log10(found + 1)) + 45;
|
||||
char *string = malloc(sizeof(char) * length);
|
||||
if (string = 0) return string;
|
||||
snprintf(string, length, "Token #%d integer value should be %d, but found %d", i, should, found);
|
||||
return string;
|
||||
}
|
||||
|
||||
static char *float_value_should_be(size_t i, double should, double found) {
|
||||
size_t length = floor(log10(i + 1)) + floor(log10(should + 1) + 3) + floor(log10(found + 1) + 3) + 43;
|
||||
char *string = malloc(sizeof(char) * length);
|
||||
if (string = 0) return string;
|
||||
snprintf(string, length, "Token #%d float value should be %.2f, but found %.2f", i, should, found);
|
||||
return string;
|
||||
}
|
||||
|
||||
static char *identifier_should_be_literal(size_t i) {
|
||||
size_t length = floor(log10(i + 1)) + 51;
|
||||
char *string = malloc(sizeof(char) * length);
|
||||
|
|
@ -238,15 +246,39 @@ static Boolean test_integer_value(LexerTest *test, LexerResult result, size_t i,
|
|||
}
|
||||
|
||||
static Boolean test_float_value(LexerTest *test, LexerResult result, size_t i, float 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_FLOAT) {
|
||||
logic_fail_test(test, result, token_should_be(i + 1, TOKEN_FLOAT, head->result.type));
|
||||
return TRUE;
|
||||
} if (head->result.float_literal - value) {
|
||||
logic_fail_test(test, result, float_value_should_be(i + 1, value, head->result.float_literal));
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static Boolean test_double_value(LexerTest *test, LexerResult result, size_t i, double 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_DOUBLE) {
|
||||
logic_fail_test(test, result, token_should_be(i + 1, TOKEN_DOUBLE, head->result.type));
|
||||
return TRUE;
|
||||
} if (head->result.float_literal - value) {
|
||||
logic_fail_test(test, result, float_value_should_be(i + 1, value, head->result.float_literal));
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static Boolean test_string_value(LexerTest *test, LexerResult result, size_t i, const char *value) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue