diff options
Diffstat (limited to 'test/test-lace.compiler.lua')
-rw-r--r-- | test/test-lace.compiler.lua | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/test/test-lace.compiler.lua b/test/test-lace.compiler.lua index 106223b..ab2f12c 100644 --- a/test/test-lace.compiler.lua +++ b/test/test-lace.compiler.lua @@ -224,6 +224,125 @@ function suite.error_in_define() assert(line4 == " ^^^^^^^^^^^^^^", "The fourth line highlights relevant words") end +function suite.error_in_define_anyof1() + local result, msg = compiler.compile(comp_context, "errorindefineanyof1") + assert(result == false, "Errors compiling should return false") + assert(type(msg) == "string", "Compilation errors should be strings") + assert(msg:find("\n"), "Compilation errors are multiline") + -- This error should be on line 3 word 3 of 'errorindefine' + local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$") + assert(line1, "There is a line 1") + assert(line2, "There is a line 2") + assert(line3, "There is a line 3") + assert(line4, "There is a line 4") + assert(line1:find("at least"), "The first line must mention the error") + assert(line2 == "real-errorindefineanyof1 :: 3", "The second line is where the error happened") + assert(line3 == "define fish anyof", "The third line is the original line") + assert(line4 == " ^^^^^", "The fourth line highlights relevant words") +end + +function suite.error_in_define_anyof2() + local result, msg = compiler.compile(comp_context, "errorindefineanyof2") + assert(result == false, "Errors compiling should return false") + assert(type(msg) == "string", "Compilation errors should be strings") + assert(msg:find("\n"), "Compilation errors are multiline") + -- This error should be on line 3 word 3 of 'errorindefine' + local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$") + assert(line1, "There is a line 1") + assert(line2, "There is a line 2") + assert(line3, "There is a line 3") + assert(line4, "There is a line 4") + assert(line1:find("at least"), "The first line must mention the error") + assert(line2 == "real-errorindefineanyof2 :: 3", "The second line is where the error happened") + assert(line3 == "define fish anyof something", "The third line is the original line") + assert(line4 == " ^^^^^ ^^^^^^^^^", "The fourth line highlights relevant words") +end + +function suite.error_in_allow_or_deny() + local result, msg = compiler.compile(comp_context, "errorinallow") + assert(result == false, "Errors compiling should return false") + assert(type(msg) == "string", "Compilation errors should be strings") + assert(msg:find("\n"), "Compilation errors are multiline") + -- This error should be on line 3 word 3 of 'errorindefine' + local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$") + assert(line1, "There is a line 1") + assert(line2, "There is a line 2") + assert(line3, "There is a line 3") + assert(line4, "There is a line 4") + assert(line1:find("Expected reason"), "The first line must mention the error") + assert(line2 == "real-errorinallow :: 3", "The second line is where the error happened") + assert(line3 == "allow", "The third line is the original line") + assert(line4 == "^^^^^", "The fourth line highlights relevant words") +end + +function suite.error_in_define_default1() + local result, msg = compiler.compile(comp_context, "errorindefault1") + assert(result == false, "Errors compiling should return false") + assert(type(msg) == "string", "Compilation errors should be strings") + assert(msg:find("\n"), "Compilation errors are multiline") + -- This error should be on line 3 word 3 of 'errorindefine' + local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$") + assert(line1, "There is a line 1") + assert(line2, "There is a line 2") + assert(line3, "There is a line 3") + assert(line4, "There is a line 4") + assert(line1:find("Expected result"), "The first line must mention the error") + assert(line2 == "real-errorindefault1 :: 3", "The second line is where the error happened") + assert(line3 == "default", "The third line is the original line") + assert(line4 == "^^^^^^^", "The fourth line highlights relevant words") +end + +function suite.error_in_define_default2() + local result, msg = compiler.compile(comp_context, "errorindefault2") + assert(result == false, "Errors compiling should return false") + assert(type(msg) == "string", "Compilation errors should be strings") + assert(msg:find("\n"), "Compilation errors are multiline") + -- This error should be on line 3 word 3 of 'errorindefine' + local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$") + assert(line1, "There is a line 1") + assert(line2, "There is a line 2") + assert(line3, "There is a line 3") + assert(line4, "There is a line 4") + assert(line1:find("allow or deny"), "The first line must mention the error") + assert(line2 == "real-errorindefault2 :: 3", "The second line is where the error happened") + assert(line3 == "default fish", "The third line is the original line") + assert(line4 == " ^^^^", "The fourth line highlights relevant words") +end + +function suite.error_in_define_default3() + local result, msg = compiler.compile(comp_context, "errorindefault3") + assert(result == false, "Errors compiling should return false") + assert(type(msg) == "string", "Compilation errors should be strings") + assert(msg:find("\n"), "Compilation errors are multiline") + -- This error should be on line 3 word 3 of 'errorindefine' + local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$") + assert(line1, "There is a line 1") + assert(line2, "There is a line 2") + assert(line3, "There is a line 3") + assert(line4, "There is a line 4") + assert(line1:find("additional"), "The first line must mention the error") + assert(line2 == "real-errorindefault3 :: 3", "The second line is where the error happened") + assert(line3 == 'default allow "" extrashite', "The third line is the original line") + assert(line4 == " ^^^^^^^^^^", "The fourth line highlights relevant words") +end + +function suite.error_in_define_default4() + local result, msg = compiler.compile(comp_context, "errorindefault4") + assert(result == false, "Errors compiling should return false") + assert(type(msg) == "string", "Compilation errors should be strings") + assert(msg:find("\n"), "Compilation errors are multiline") + -- This error should be on line 3 word 3 of 'errorindefine' + local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$") + assert(line1, "There is a line 1") + assert(line2, "There is a line 2") + assert(line3, "There is a line 3") + assert(line4, "There is a line 4") + assert(line1:find("Cannot change"), "The first line must mention the error") + assert(line2 == "real-errorindefault4 :: 5", "The second line is where the error happened") + assert(line3 == 'default allow', "The third line is the original line") + assert(line4 == "^^^^^^^ ^^^^^", "The fourth line highlights relevant words") +end + local count_ok = 0 for _, testname in ipairs(testnames) do -- print("Run: " .. testname) |