#include "test_utils.h" UnittestTestResult_t* test_lexer_basic_class(void) { UNITTEST_BEGIN_TEST("TestLexer", "test_lexer_basic_class"); RAVA_TEST_LEXER_OK(_unittest_result, "public class HelloWorld {\n" " public static void main(String[] args) {\n" " int x = 42;\n" " return;\n" " }\n" "}\n", "basic class should tokenize successfully"); UNITTEST_END_TEST(); } UnittestTestResult_t* test_lexer_keywords(void) { UNITTEST_BEGIN_TEST("TestLexer", "test_lexer_keywords"); RAVA_TEST_LEXER_OK(_unittest_result, "public class Test {\n" " private static final int x = 0;\n" " protected void method() {\n" " if (true) { return; }\n" " else { break; }\n" " while (false) { continue; }\n" " for (int i = 0; i < 10; i++) {}\n" " }\n" "}\n", "keywords should tokenize successfully"); UNITTEST_END_TEST(); } UnittestTestResult_t* test_lexer_literals(void) { UNITTEST_BEGIN_TEST("TestLexer", "test_lexer_literals"); RAVA_TEST_LEXER_OK(_unittest_result, "public class Test {\n" " public static void main() {\n" " int a = 42;\n" " long b = 100L;\n" " double c = 3.14;\n" " String s = \"Hello, World!\";\n" " char ch = 'x';\n" " boolean t = true;\n" " boolean f = false;\n" " Object n = null;\n" " }\n" "}\n", "literals should tokenize successfully"); UNITTEST_END_TEST(); } UnittestTestResult_t* test_lexer_operators(void) { UNITTEST_BEGIN_TEST("TestLexer", "test_lexer_operators"); RAVA_TEST_LEXER_OK(_unittest_result, "public class Test {\n" " public static int main() {\n" " int a = 1 + 2 - 3 * 4 / 5 % 6;\n" " boolean b = a < 10 && a > 0 || a == 5;\n" " int c = a & 0xFF | 0x0F ^ 0x01;\n" " int d = a << 2 >> 1 >>> 0;\n" " a += 1; a -= 1; a *= 2; a /= 2;\n" " return a;\n" " }\n" "}\n", "operators should tokenize successfully"); UNITTEST_END_TEST(); } UnittestTestResult_t* test_lexer_control_flow(void) { UNITTEST_BEGIN_TEST("TestLexer", "test_lexer_control_flow"); RAVA_TEST_LEXER_OK(_unittest_result, "public class Test {\n" " public static int main() {\n" " if (true) {\n" " return 1;\n" " } else {\n" " return 0;\n" " }\n" " switch (x) {\n" " case 1: break;\n" " default: break;\n" " }\n" " try {\n" " throw new Exception();\n" " } catch (Exception e) {\n" " } finally {\n" " }\n" " }\n" "}\n", "control flow should tokenize successfully"); UNITTEST_END_TEST(); } int main(int argc, char **argv) { UnittestConfig_t *config = unittest_config_create(); config->verbosity = 2; if (argc > 1 && strcmp(argv[1], "--json") == 0) { config->output_format = UNITTEST_FORMAT_JSON; config->use_colors = false; } UnittestTestSuite_t *suite = unittest_test_suite_create("Lexer Tests"); UnittestTestCase_t *tc = unittest_test_case_create("TestLexer"); unittest_test_case_add_result(tc, test_lexer_basic_class()); unittest_test_case_add_result(tc, test_lexer_keywords()); unittest_test_case_add_result(tc, test_lexer_literals()); unittest_test_case_add_result(tc, test_lexer_operators()); unittest_test_case_add_result(tc, test_lexer_control_flow()); unittest_test_suite_add_test_case(suite, tc); unittest_generate_report(suite, config); int failures = suite->total_failed + suite->total_errors; unittest_test_suite_destroy(suite); unittest_config_destroy(config); return failures > 0 ? 1 : 0; }