/
thomas-king
/
IdentifierParser
Обзор
Документация
Войти
/
thomas-king
/
IdentifierParser
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
include/tests/parser_tests.h
142 строки
3 KB
AceRodstin
Add backticks parsing capability.
27 дек 2022, 17:56
27 дек 2022, 17:56
d72dba2
Код
Авторство
О чём код?
// // parser_tests.h // IdentifierParser // // Created by Ace Rodstin on 27 Dec 2022. // #ifndef PARSER_TESTS_HEADER_FILE #define PARSER_TESTS_HEADER_FILE #include "../Parser.h" namespace parser_tests { void test_identifier_header_digit() { // Given string input = "1identifier"; bool is_error_thrown = false; // When try { Identifier::Parser parser; auto output = parser.parse(input); } catch(...) { is_error_thrown = true; } // Then assert(is_error_thrown); } void test_identifier_header_uppercase() { // Given string input = "Identifier"; string expected = "Identifier"; // When Identifier::Parser parser; auto output = parser.parse(input); // Then assert(output == expected); } void test_identifier_header_lowercase() { // Given string input = "identifier"; string expected = "identifier"; // When Identifier::Parser parser; auto output = parser.parse(input); // Then assert(output == expected); } void test_identifier_header_underscore() { // Given string input = "_identifier"; string expected = "_identifier"; // When Identifier::Parser parser; auto output = parser.parse(input); // Then assert(output == expected); } void test_identifier_header_double_underscore() { // Given string input = "__identifier"; string expected = "__identifier"; // When Identifier::Parser parser; auto output = parser.parse(input); // Then assert(output == expected); } void test_identifier_contains_digits() { // Given string input = "i123dentifier"; string expected = "i123dentifier"; // When Identifier::Parser parser; auto output = parser.parse(input); // Then assert(output == expected); } void test_identifier_contains_underscore() { // Given string input = "snake_case"; string expected = "snake_case"; // When Identifier::Parser parser; auto output = parser.parse(input); // Then assert(output == expected); } void test_identifier_contains_backticks() { // Given string input = "`keyword`"; string expected = "`keyword`"; // When Identifier::Parser parser; auto output = parser.parse(input); // Then assert(output == expected); } void test_identifier_contains_invalid_character() { // Given string input = "iden*tifier"; bool is_error_thrown = false; // When try { Identifier::Parser parser; auto output = parser.parse(input); } catch(...) { is_error_thrown = true; } // Then assert(is_error_thrown); } } #endif