Added tests
This commit is contained in:
parent
6d51b8a92b
commit
c86f03ee3f
|
|
@ -12,7 +12,7 @@
|
|||
#include "sls/lexer.h"
|
||||
#include "tests/tests.h"
|
||||
|
||||
static const size_t NUM_OF_TESTS = 6;
|
||||
static const size_t NUM_OF_TESTS = 11;
|
||||
|
||||
static const double FLOAT_TEST_PRECISION = 0.01;
|
||||
|
||||
|
|
@ -629,6 +629,66 @@ static TestResult test_dup_and_mult_statement() {
|
|||
return pass_test(&test, result);
|
||||
}
|
||||
|
||||
static TestResult test_dup_statement() {
|
||||
LexerTest test = start_up_test("test_dup_statement", "5 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, 5)) return test.result;
|
||||
if (test_identifier_value(&test, result, i++, FALSE, 3, "dup")) return test.result;
|
||||
if (test_eof_value(&test, result, i++)) return test.result;
|
||||
return pass_test(&test, result);
|
||||
}
|
||||
|
||||
static TestResult test_swap_statement() {
|
||||
LexerTest test = start_up_test("test_swap_statement", "5 10 swap");
|
||||
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, 10)) return test.result;
|
||||
if (test_identifier_value(&test, result, i++, FALSE, 3, "swap")) return test.result;
|
||||
if (test_eof_value(&test, result, i++)) return test.result;
|
||||
return pass_test(&test, result);
|
||||
}
|
||||
|
||||
static TestResult test_over_statement() {
|
||||
LexerTest test = start_up_test("test_over_statement", "5 10 over");
|
||||
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, 10)) return test.result;
|
||||
if (test_identifier_value(&test, result, i++, FALSE, 3, "over")) return test.result;
|
||||
if (test_eof_value(&test, result, i++)) return test.result;
|
||||
return pass_test(&test, result);
|
||||
}
|
||||
|
||||
static TestResult test_rot_statement() {
|
||||
LexerTest test = start_up_test("test_rot_statement", "1 2 3 rot");
|
||||
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, 1)) return test.result;
|
||||
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, 3, "rot")) return test.result;
|
||||
if (test_eof_value(&test, result, i++)) return test.result;
|
||||
return pass_test(&test, result);
|
||||
}
|
||||
|
||||
static TestResult test_swap_and_rot_statement() {
|
||||
LexerTest test = start_up_test("test_swap_and_rot_statement", "swap rot rot");
|
||||
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_identifier_value(&test, result, i++, FALSE, 3, "swap")) return test.result;
|
||||
if (test_identifier_value(&test, result, i++, FALSE, 3, "rot")) return test.result;
|
||||
if (test_identifier_value(&test, result, i++, FALSE, 3, "rot")) 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() {
|
||||
|
|
@ -646,6 +706,11 @@ TestsReport run_lexer_tests() {
|
|||
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();
|
||||
test_report.tests[i++] = test_dup_statement();
|
||||
test_report.tests[i++] = test_swap_statement();
|
||||
test_report.tests[i++] = test_over_statement();
|
||||
test_report.tests[i++] = test_rot_statement();
|
||||
test_report.tests[i++] = test_swap_and_rot_statement();
|
||||
|
||||
return test_report;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue