commit 72f4f7ea045055936cfb3e65480ae0f5aeb50ec8
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Fri Jan 2 11:46:32 2026 -0700
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Fri Jan 2 11:46:32 2026 -0700
add end to end tests for ord/chr/peek fixes
---
test/carts/chr_large_args.p8 | 54 ++++++++++++++++++++
test/carts/ord_nil_arg.p8 | 63 ++++++++++++++++++++++++
test/carts/peek_large_count.p8 | 58 ++++++++++++++++++++++
test/carts/screenshots/chr_large_args_f01.png | Bin 0 -> 722 bytes
test/carts/screenshots/ord_nil_arg_f01.png | Bin 0 -> 866 bytes
test/carts/screenshots/peek_large_count_f01.png | Bin 0 -> 805 bytes
test/endtoendtests.cpp | 48 ++++++++++++++++++
7 files changed, 223 insertions(+)
diff --git a/test/carts/chr_large_args.p8 b/test/carts/chr_large_args.p8
new file mode 100644
index 0000000..266029f
--- /dev/null
+++ b/test/carts/chr_large_args.p8
@@ -0,0 +1,54 @@
+pico-8 cartridge // http://www.pico-8.com
+version 35
+__lua__
+-- test chr with large number of arguments
+-- this tests the fix for chr buffer size limit
+
+results = {}
+
+function _init()
+ -- write test pattern to memory at 0x1000
+ for i=0,999 do
+ poke(0x1000+i, i%256)
+ end
+
+ -- read 1000 bytes and convert to string using chr
+ local str = chr(peek(0x1000, 1000))
+
+ -- verify the string length
+ if #str == 1000 then
+ add(results, {true, "chr handled 1000 args"})
+ add(results, {true, "length: "..#str})
+ else
+ add(results, {false, "expected 1000, got "..#str})
+ end
+
+ -- verify first and last bytes
+ local first = ord(str, 1)
+ local last = ord(str, 1000)
+
+ if first == 0 then
+ add(results, {true, "first byte: "..first})
+ else
+ add(results, {false, "first byte: "..tostr(first).." (expected 0)"})
+ end
+
+ if last == 231 then
+ add(results, {true, "last byte: "..last})
+ else
+ add(results, {false, "last byte: "..tostr(last).." (expected 231)"})
+ end
+end
+
+function _draw()
+ cls()
+ print("chr large args test", 0, 0, 7)
+ print("-------------------", 0, 8, 6)
+
+ for i, r in ipairs(results) do
+ local pass, msg = r[1], r[2]
+ local col = pass and 11 or 8
+ local prefix = pass and "pass: " or "fail: "
+ print(prefix..msg, 0, 8 + i*8, col)
+ end
+end
diff --git a/test/carts/ord_nil_arg.p8 b/test/carts/ord_nil_arg.p8
new file mode 100644
index 0000000..6d69836
--- /dev/null
+++ b/test/carts/ord_nil_arg.p8
@@ -0,0 +1,63 @@
+pico-8 cartridge // http://www.pico-8.com
+version 35
+__lua__
+-- test ord with nil argument
+-- per PICO-8 docs: "When str is not a string, ORD returns nil"
+
+results = {}
+
+function _init()
+ -- test ord with nil first argument
+ local result = ord(nil)
+ if result == nil then
+ add(results, {true, "ord(nil) returns nil"})
+ else
+ add(results, {false, "ord(nil) returned "..tostr(result)})
+ end
+
+ -- test ord with nil and extra args
+ local result2 = ord(nil, 1, 50)
+ if result2 == nil then
+ add(results, {true, "ord(nil,1,50) returns nil"})
+ else
+ add(results, {false, "ord(nil,1,50) returned "..tostr(result2)})
+ end
+
+ -- test ord with number (converts to string first)
+ -- ord(123) treats it as "123", returns ord('1') = 49
+ local result3 = ord(123)
+ if result3 == 49 then
+ add(results, {true, "ord(123) = 49"})
+ else
+ add(results, {false, "ord(123) returned "..tostr(result3).." (expected 49)"})
+ end
+
+ -- test ord with table (not a string)
+ local result4 = ord({})
+ if result4 == nil then
+ add(results, {true, "ord({}) returns nil"})
+ else
+ add(results, {false, "ord({}) returned "..tostr(result4)})
+ end
+
+ -- verify ord still works with valid string
+ local result5 = ord("hello")
+ if result5 == 104 then -- 'h' = 104
+ add(results, {true, "ord('hello') = 104"})
+ else
+ add(results, {false, "ord('hello') returned "..tostr(result5)})
+ end
+end
+
+function _draw()
+ cls()
+ print("ord nil arg test", 0, 0, 7)
+ print("----------------", 0, 8, 6)
+
+ for i, r in ipairs(results) do
+ local pass, msg = r[1], r[2]
+ local col = pass and 11 or 8
+ local prefix = pass and "pass: " or "fail: "
+ print(prefix..msg, 0, 8 + i*8, col)
+ end
+end
diff --git a/test/carts/peek_large_count.p8 b/test/carts/peek_large_count.p8
new file mode 100644
index 0000000..ca94324
--- /dev/null
+++ b/test/carts/peek_large_count.p8
@@ -0,0 +1,58 @@
+pico-8 cartridge // http://www.pico-8.com
+version 35
+__lua__
+-- test peek with large count
+-- tests lua_checkstack fix for returning many values
+
+results = {}
+
+function _init()
+ -- write test pattern to memory at 0x1000
+ for i=0,999 do
+ poke(0x1000+i, i%256)
+ end
+
+ -- peek 1000 values at once
+ local vals = {peek(0x1000, 1000)}
+
+ -- verify count
+ if #vals == 1000 then
+ add(results, {true, "peek returned 1000 values"})
+ else
+ add(results, {false, "expected 1000, got "..#vals})
+ end
+
+ -- verify first value
+ if vals[1] == 0 then
+ add(results, {true, "first value is 0"})
+ else
+ add(results, {false, "first value is "..tostr(vals[1])})
+ end
+
+ -- verify last value (999 % 256 = 231)
+ if vals[1000] == 231 then
+ add(results, {true, "last value is 231"})
+ else
+ add(results, {false, "last value is "..tostr(vals[1000])})
+ end
+
+ -- verify middle value (500 % 256 = 244)
+ if vals[501] == 244 then
+ add(results, {true, "middle value is 244"})
+ else
+ add(results, {false, "middle value is "..tostr(vals[501])})
+ end
+end
+
+function _draw()
+ cls()
+ print("peek large count test", 0, 0, 7)
+ print("--------------------", 0, 8, 6)
+
+ for i, r in ipairs(results) do
+ local pass, msg = r[1], r[2]
+ local col = pass and 11 or 8
+ local prefix = pass and "pass: " or "fail: "
+ print(prefix..msg, 0, 8 + i*8, col)
+ end
+end
diff --git a/test/carts/screenshots/chr_large_args_f01.png b/test/carts/screenshots/chr_large_args_f01.png
new file mode 100644
index 0000000..771bd8f
Binary files /dev/null and b/test/carts/screenshots/chr_large_args_f01.png differ
diff --git a/test/carts/screenshots/ord_nil_arg_f01.png b/test/carts/screenshots/ord_nil_arg_f01.png
new file mode 100644
index 0000000..8b05c7e
Binary files /dev/null and b/test/carts/screenshots/ord_nil_arg_f01.png differ
diff --git a/test/carts/screenshots/peek_large_count_f01.png b/test/carts/screenshots/peek_large_count_f01.png
new file mode 100644
index 0000000..5f9bb31
Binary files /dev/null and b/test/carts/screenshots/peek_large_count_f01.png differ
diff --git a/test/endtoendtests.cpp b/test/endtoendtests.cpp
index 5b6371b..b2dc7a3 100644
--- a/test/endtoendtests.cpp
+++ b/test/endtoendtests.cpp
@@ -906,6 +906,54 @@ TEST_CASE("Loading and running carts") {
vm->CloseCart();
}
+ SUBCASE("peek with large count test"){
+ vm->LoadCart("peek_large_count.p8", false);
+ vm->vm_run();
+ vm->Step();
+
+ SUBCASE("No error reported"){
+ CHECK(vm->GetBiosError() == "");
+ }
+ SUBCASE("screen matches screenshot"){
+ vm->Step();
+
+ CHECK(verifyScreenshot(vm, host, "carts/screenshots/peek_large_count_f01.png"));
+ }
+
+ vm->CloseCart();
+ }
+ SUBCASE("chr with large args test"){
+ vm->LoadCart("chr_large_args.p8", false);
+ vm->vm_run();
+ vm->Step();
+
+ SUBCASE("No error reported"){
+ CHECK(vm->GetBiosError() == "");
+ }
+ SUBCASE("screen matches screenshot"){
+ vm->Step();
+
+ CHECK(verifyScreenshot(vm, host, "carts/screenshots/chr_large_args_f01.png"));
+ }
+
+ vm->CloseCart();
+ }
+ SUBCASE("ord with nil arg test"){
+ vm->LoadCart("ord_nil_arg.p8", false);
+ vm->vm_run();
+ vm->Step();
+
+ SUBCASE("No error reported"){
+ CHECK(vm->GetBiosError() == "");
+ }
+ SUBCASE("screen matches screenshot"){
+ vm->Step();
+
+ CHECK(verifyScreenshot(vm, host, "carts/screenshots/ord_nil_arg_f01.png"));
+ }
+
+ vm->CloseCart();
+ }
delete vm;
delete host;