Consolidate return codes

This commit is contained in:
josh committed 2023-07-08 09:23:31 -04:00
1 parent 0232b204c6
commit ecef933255
13 files changed
+113 -111

No files matched your search

+17 -18
View File
@@ -8,37 +8,36 @@ int main()
unittest
{
alias Result = Testparser.Decoder.Result;
Result result;
size_t result;
Testparser.CodePoint code_point;
ubyte code_point_length;
result = Testparser.Decoder.decode_code_point("5", code_point, code_point_length);
assert(result == Result.SUCCESS);
assert(result == Testparser.P_SUCCESS);
assert(code_point == '5');
assert(code_point_length == 1u);
result = Testparser.Decoder.decode_code_point("", code_point, code_point_length);
assert(result == Result.EOF);
assert(result == Testparser.P_EOF);
result = Testparser.Decoder.decode_code_point("\xC2\xA9", code_point, code_point_length);
assert(result == Result.SUCCESS);
assert(result == Testparser.P_SUCCESS);
assert(code_point == 0xA9u);
assert(code_point_length == 2u);
result = Testparser.Decoder.decode_code_point("\xf0\x9f\xa7\xa1", code_point, code_point_length);
assert(result == Result.SUCCESS);
assert(result == Testparser.P_SUCCESS);
assert(code_point == 0x1F9E1u);
assert(code_point_length == 4u);
result = Testparser.Decoder.decode_code_point("\xf0\x9f\x27", code_point, code_point_length);
assert(result == Result.DECODE_ERROR);
assert(result == Testparser.P_DECODE_ERROR);
result = Testparser.Decoder.decode_code_point("\xf0\x9f\xa7\xFF", code_point, code_point_length);
assert(result == Result.DECODE_ERROR);
assert(result == Testparser.P_DECODE_ERROR);
result = Testparser.Decoder.decode_code_point("\xfe", code_point, code_point_length);
assert(result == Result.DECODE_ERROR);
assert(result == Testparser.P_DECODE_ERROR);
}
unittest
@@ -47,24 +46,24 @@ unittest
TokenInfo token_info;
string input = "5 + 4 * \n677 + 567";
Testparser.Lexer lexer = new Testparser.Lexer(input);
assert(lexer.lex_token(&token_info) == lexer.P_TOKEN);
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN);
assert(token_info == TokenInfo(0, 0, 1, Testparser.TOKEN_int));
assert(lexer.lex_token(&token_info) == lexer.P_TOKEN);
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN);
assert(token_info == TokenInfo(0, 2, 1, Testparser.TOKEN_plus));
assert(lexer.lex_token(&token_info) == lexer.P_TOKEN);
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN);
assert(token_info == TokenInfo(0, 4, 1, Testparser.TOKEN_int));
assert(lexer.lex_token(&token_info) == lexer.P_TOKEN);
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN);
assert(token_info == TokenInfo(0, 6, 1, Testparser.TOKEN_times));
assert(lexer.lex_token(&token_info) == lexer.P_TOKEN);
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN);
assert(token_info == TokenInfo(1, 0, 3, Testparser.TOKEN_int));
assert(lexer.lex_token(&token_info) == lexer.P_TOKEN);
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN);
assert(token_info == TokenInfo(1, 4, 1, Testparser.TOKEN_plus));
assert(lexer.lex_token(&token_info) == lexer.P_TOKEN);
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN);
assert(token_info == TokenInfo(1, 6, 3, Testparser.TOKEN_int));
assert(lexer.lex_token(&token_info) == lexer.P_TOKEN);
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN);
assert(token_info == TokenInfo(1, 9, 0, Testparser.TOKEN___EOF));
lexer = new Testparser.Lexer("");
assert(lexer.lex_token(&token_info) == lexer.P_TOKEN);
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN);
assert(token_info == TokenInfo(0, 0, 0, Testparser.TOKEN___EOF));
}
@@ -10,9 +10,9 @@ unittest
{
string input = "aba";
auto parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
input = "abb";
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
}
@@ -10,13 +10,13 @@ unittest
{
string input = "a";
auto parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_UNEXPECTED_TOKEN);
assert(parser.parse() == Testparser.P_UNEXPECTED_TOKEN);
input = "a b";
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
input = "bb";
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
}
+1 -1
View File
@@ -10,6 +10,6 @@ unittest
{
string input = `identifier_123`;
auto parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
writeln("pass1");
}
+2 -2
View File
@@ -10,11 +10,11 @@ unittest
{
string input = `abc "a string" def`;
auto parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
writeln("pass1");
input = `abc "abc def" def`;
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
writeln("pass2");
}
+2 -2
View File
@@ -10,11 +10,11 @@ unittest
{
string input = `x`;
auto parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
assert(parser.result == 1u);
input = `fabulous`;
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
assert(parser.result == 8u);
}
+1 -1
View File
@@ -10,5 +10,5 @@ unittest
{
string input = "ab";
auto parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
}
+7 -7
View File
@@ -11,33 +11,33 @@ unittest
{
string input = ``;
auto parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
input = `{}`;
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
assert(cast(JSONObject)parser.result);
input = `[]`;
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
assert(cast(JSONArray)parser.result);
input = `-45.6`;
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
assert(cast(JSONNumber)parser.result);
assert((cast(JSONNumber)parser.result).value == -45.6);
input = `2E-2`;
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
assert(cast(JSONNumber)parser.result);
assert((cast(JSONNumber)parser.result).value == 0.02);
input = `{"hi":true}`;
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
assert(cast(JSONObject)parser.result);
JSONObject o = cast(JSONObject)parser.result;
assert(o.value["hi"]);
@@ -45,7 +45,7 @@ unittest
input = `{"ff": false, "nn": null}`;
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
assert(cast(JSONObject)parser.result);
o = cast(JSONObject)parser.result;
assert(o.value["ff"]);
+3 -3
View File
@@ -10,16 +10,16 @@ unittest
{
string input = "a";
auto parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
assert(parser.result == 1u);
input = "";
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
assert(parser.result == 0u);
input = "aaaaaaaaaaaaaaaa";
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
assert(parser.result == 16u);
}
+2 -2
View File
@@ -10,11 +10,11 @@ unittest
{
string input = "abcdef";
auto parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
writeln("pass1");
input = "defabcdef";
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
writeln("pass2");
}
+1 -1
View File
@@ -10,5 +10,5 @@ unittest
{
string input = "defghidef";
auto parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
}
+2 -2
View File
@@ -10,11 +10,11 @@ unittest
{
string input = "abcdef";
auto parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
writeln("pass1");
input = "abcabcdef";
parser = new Testparser.Parser(input);
assert(parser.parse() == Testparser.Parser.P_SUCCESS);
assert(parser.parse() == Testparser.P_SUCCESS);
writeln("pass2");
}