Added another test
This commit is contained in:
parent
2810a9eb14
commit
01611bcde0
|
|
@ -12,7 +12,7 @@
|
|||
#include "sls/lexer.h"
|
||||
#include "tests/tests.h"
|
||||
|
||||
static const size_t NUM_OF_TESTS = 1;
|
||||
static const size_t NUM_OF_TESTS = 2;
|
||||
|
||||
typedef struct {
|
||||
TestResult result;
|
||||
|
|
@ -211,22 +211,25 @@ static Boolean test_eof_value(LexerTest *test, LexerResult result, size_t i) {
|
|||
|
||||
static TestResult test_add_statement() {
|
||||
LexerTest test = start_up_test("test_add_statement", "3 4 +");
|
||||
|
||||
LexerResult result = lexical_analysis(&test.lexer_info);
|
||||
|
||||
if (result.type == SLS_ERROR)
|
||||
return error_fail_test(&test, result, result.error);
|
||||
|
||||
LexerTokenResult *head = result.result;
|
||||
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, 3)) 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);
|
||||
}
|
||||
|
||||
if (test_integer_value(&test, result, i, INTEGER_I64, 3)) return test.result;
|
||||
i++;
|
||||
if (test_integer_value(&test, result, i, INTEGER_I64, 4)) return test.result;
|
||||
i++;
|
||||
if (test_identifier_value(&test, result, i, FALSE, "+")) return test.result;
|
||||
i++;
|
||||
if (test_eof_value(&test, result, i)) return test.result;
|
||||
static TestResult test_sub_statement() {
|
||||
LexerTest test = start_up_test("test_add_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;
|
||||
if (test_integer_value(&test, result, i++, INTEGER_I64, 10)) 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_eof_value(&test, result, i++)) return test.result;
|
||||
return pass_test(&test, result);
|
||||
}
|
||||
|
||||
|
|
@ -237,7 +240,10 @@ TestsReport run_lexer_tests() {
|
|||
.tests = malloc(sizeof(TestResult) * NUM_OF_TESTS),
|
||||
};
|
||||
|
||||
test_report.tests[0] = test_add_statement();
|
||||
size_t i = 0;
|
||||
|
||||
test_report.tests[i++] = test_add_statement();
|
||||
test_report.tests[i++] = test_sub_statement();
|
||||
|
||||
return test_report;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue