Added more tests
This commit is contained in:
parent
01611bcde0
commit
19783bbe6b
|
|
@ -12,14 +12,14 @@
|
|||
#include "sls/lexer.h"
|
||||
#include "tests/tests.h"
|
||||
|
||||
static const size_t NUM_OF_TESTS = 2;
|
||||
static const size_t NUM_OF_TESTS = 6;
|
||||
|
||||
typedef struct {
|
||||
TestResult result;
|
||||
LexerInfo lexer_info;
|
||||
} LexerTest;
|
||||
|
||||
const char *TOKEN_TYPES_NAMES[] = {
|
||||
static const char *TOKEN_TYPES_NAMES[] = {
|
||||
"End of File",
|
||||
"Identifier",
|
||||
"Integer",
|
||||
|
|
@ -32,7 +32,7 @@ const char *TOKEN_TYPES_NAMES[] = {
|
|||
"Type Tuple",
|
||||
};
|
||||
|
||||
const char *INTEGER_TYPES_NAMES[] = {
|
||||
static const char *INTEGER_TYPES_NAMES[] = {
|
||||
"i64",
|
||||
"i32",
|
||||
"i16",
|
||||
|
|
@ -222,7 +222,7 @@ static TestResult test_add_statement() {
|
|||
}
|
||||
|
||||
static TestResult test_sub_statement() {
|
||||
LexerTest test = start_up_test("test_add_statement", "10 3 -");
|
||||
LexerTest test = start_up_test("test_sub_statement", "10 3 -");
|
||||
LexerResult result = lexical_analysis(&test.lexer_info);
|
||||
if (result.type == SLS_ERROR) return error_fail_test(&test, result, result.error);
|
||||
size_t i = 0;
|
||||
|
|
@ -233,6 +233,58 @@ static TestResult test_sub_statement() {
|
|||
return pass_test(&test, result);
|
||||
}
|
||||
|
||||
static TestResult test_mult_statement() {
|
||||
LexerTest test = start_up_test("test_mult_statement", "5 6 *");
|
||||
LexerResult result = lexical_analysis(&test.lexer_info);
|
||||
if (result.type == SLS_ERROR) return error_fail_test(&test, result, result.error);
|
||||
size_t i = 0;
|
||||
if (test_integer_value(&test, result, i++, INTEGER_I64, 5)) return test.result;
|
||||
if (test_integer_value(&test, result, i++, INTEGER_I64, 6)) return test.result;
|
||||
if (test_identifier_value(&test, result, i++, FALSE, "*")) return test.result;
|
||||
if (test_eof_value(&test, result, i++)) return test.result;
|
||||
return pass_test(&test, result);
|
||||
}
|
||||
|
||||
static TestResult test_div_statement() {
|
||||
LexerTest test = start_up_test("test_div_statement", "20 4 /");
|
||||
LexerResult result = lexical_analysis(&test.lexer_info);
|
||||
if (result.type == SLS_ERROR) return error_fail_test(&test, result, result.error);
|
||||
size_t i = 0;
|
||||
if (test_integer_value(&test, result, i++, INTEGER_I64, 20)) return test.result;
|
||||
if (test_integer_value(&test, result, i++, INTEGER_I64, 4)) return test.result;
|
||||
if (test_identifier_value(&test, result, i++, FALSE, "/")) return test.result;
|
||||
if (test_eof_value(&test, result, i++)) return test.result;
|
||||
return pass_test(&test, result);
|
||||
}
|
||||
|
||||
static TestResult test_add_and_mult_statement() {
|
||||
LexerTest test = start_up_test("test_add_and_mult_statement", "2 3 + 4 *");
|
||||
LexerResult result = lexical_analysis(&test.lexer_info);
|
||||
if (result.type == SLS_ERROR) return error_fail_test(&test, result, result.error);
|
||||
size_t i = 0;
|
||||
if (test_integer_value(&test, result, i++, INTEGER_I64, 2)) return test.result;
|
||||
if (test_integer_value(&test, result, i++, INTEGER_I64, 3)) return test.result;
|
||||
if (test_identifier_value(&test, result, i++, FALSE, "+")) return test.result;
|
||||
if (test_integer_value(&test, result, i++, INTEGER_I64, 4)) return test.result;
|
||||
if (test_identifier_value(&test, result, i++, FALSE, "*")) return test.result;
|
||||
if (test_eof_value(&test, result, i++)) return test.result;
|
||||
return pass_test(&test, result);
|
||||
}
|
||||
|
||||
static TestResult test_dup_and_mult_statement() {
|
||||
LexerTest test = start_up_test("test_dup_and_mult_statement", "10 dup *");
|
||||
LexerResult result = lexical_analysis(&test.lexer_info);
|
||||
if (result.type == SLS_ERROR) return error_fail_test(&test, result, result.error);
|
||||
size_t i = 0;
|
||||
if (test_integer_value(&test, result, i++, INTEGER_I64, 10)) return test.result;
|
||||
if (test_identifier_value(&test, result, i++, FALSE, "dup")) return test.result;
|
||||
if (test_identifier_value(&test, result, i++, FALSE, "*")) return test.result;
|
||||
if (test_eof_value(&test, result, i++)) return test.result;
|
||||
return pass_test(&test, result);
|
||||
}
|
||||
|
||||
// Lexer Tests Runner
|
||||
|
||||
TestsReport run_lexer_tests() {
|
||||
TestsReport test_report = (TestsReport) {
|
||||
.section = "lexer_tests",
|
||||
|
|
@ -244,6 +296,10 @@ TestsReport run_lexer_tests() {
|
|||
|
||||
test_report.tests[i++] = test_add_statement();
|
||||
test_report.tests[i++] = test_sub_statement();
|
||||
test_report.tests[i++] = test_mult_statement();
|
||||
test_report.tests[i++] = test_div_statement();
|
||||
test_report.tests[i++] = test_add_and_mult_statement();
|
||||
test_report.tests[i++] = test_dup_and_mult_statement();
|
||||
|
||||
return test_report;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue