summaryrefslogtreecommitdiff
path: root/test/test-lace.error.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/test-lace.error.lua')
-rw-r--r--test/test-lace.error.lua59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/test-lace.error.lua b/test/test-lace.error.lua
index 4c15acd..471935b 100644
--- a/test/test-lace.error.lua
+++ b/test/test-lace.error.lua
@@ -38,6 +38,65 @@ function suite.error_formation()
assert(ret2.words == words, "Words should be passed through")
end
+function suite.error_offset()
+ local words = {3,5}
+ local f, err = error.error("msg", words)
+ local nerr = error.offset(err, 2)
+ assert(nerr == err, "Offset should return the same error it was given")
+ assert(words[1] == 5, "Offset should alter the first word")
+ assert(words[2] == 7, "Offset should alter all the words")
+end
+
+function suite.error_augmentation()
+ local f, err = error.error("msg")
+ local src = {}
+ error.augment(err, src, 10)
+ assert(err.source == src, "Augmented errors should contain their source data")
+ assert(err.linenr == 10, "Augmented errors should contain their error line")
+end
+
+function suite.error_render()
+ local f, err = error.error("msg", {1, 3})
+ local src = { source = "SOURCE", lines = {
+ {
+ original = " ORIG LINE FISH",
+ content = {
+ { spos = 3, epos = 6, str = "ORIG" },
+ { spos = 8, epos = 11, str = "LINE" },
+ { spos = 13, epos = 16, str = "FISH" },
+ }
+ }
+ }
+ }
+ error.augment(err, src, 1)
+ local estr = error.render(err)
+ local line1, line2, line3, line4 = estr: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 == "msg", "The first line should be the error message")
+ assert(line2 == "SOURCE :: 1", "The second line is where the error happened")
+ assert(line3 == src.lines[1].original, "The third line is the original line")
+ assert(line4 == " ^^^^ ^^^^", "The fourth line highlights relevant words")
+end
+
+function suite.error_render_bad_line()
+ local f, err = error.error("msg", {1, 3})
+ local src = { source = "SOURCE", lines = { } }
+ error.augment(err, src, 1)
+ local estr = error.render(err)
+ local line1, line2, line3, line4 = estr: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 == "msg", "The first line should be the error message")
+ assert(line2 == "SOURCE :: 1", "The second line is where the error happened")
+ assert(line3 == "???", "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)