commit ccff5c15d1f0c1ce91c4b03387fd897bbc45c4e7
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sun Jan 11 20:43:48 2026 -0700
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sun Jan 11 20:43:48 2026 -0700
Improve tests
Add new test file specifically for custom lua language functions
add to e2e test for shortprint
---
test/carts/return_assign_shortprint_test.p8 | 6 +-
.../return_assign_shortprint_test_f01.png | Bin 573 -> 642 bytes
test/customLuaTests.cpp | 323 +++++++++++++++++++++
3 files changed, 327 insertions(+), 2 deletions(-)
diff --git a/test/carts/return_assign_shortprint_test.p8 b/test/carts/return_assign_shortprint_test.p8
index 0b3f5cb..0cc67c4 100644
--- a/test/carts/return_assign_shortprint_test.p8
+++ b/test/carts/return_assign_shortprint_test.p8
@@ -14,8 +14,10 @@ end
function _draw()
cls()
- outlined_text("all levels unlocked!", 12, 106, 4, 13)
- ?"all levels unlocked!", 0, 0, 4, 13
+ local res1=outlined_text("all levels unlocked!", 12, 106, 4, 13)
+ print(res1)
+ local res2=?"all levels unlocked!", 0, 0, 4, 13
+ print(res2)
end
__gfx__
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
diff --git a/test/carts/screenshots/return_assign_shortprint_test_f01.png b/test/carts/screenshots/return_assign_shortprint_test_f01.png
index 503ff81..b279150 100644
Binary files a/test/carts/screenshots/return_assign_shortprint_test_f01.png and b/test/carts/screenshots/return_assign_shortprint_test_f01.png differ
diff --git a/test/customLuaTests.cpp b/test/customLuaTests.cpp
new file mode 100644
index 0000000..0f1f27f
--- /dev/null
+++ b/test/customLuaTests.cpp
@@ -0,0 +1,323 @@
+#include "doctest.h"
+#include "doctest.h"
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+TEST_CASE("shortprint (?)") {
+ lua_State *L = luaL_newstate();
+ luaL_openlibs(L);
+
+ //define a fake print function - returns the args (note this is different
+ //from Pico-8 which returns the new x value)
+ luaL_dostring(L, "function print(...) return ... end");
+
+ SUBCASE("shortprint as assignment") {
+ const char* code =
+ "local a= ?'test'\n"
+ "return a";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TSTRING);
+ CHECK_EQ(std::string(lua_tostring(L, -1)), "test");
+ }
+ }
+
+ SUBCASE("shortprint as return") {
+ const char* code = "return ?'ret'";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TSTRING);
+ CHECK_EQ(std::string(lua_tostring(L, -1)), "ret");
+ }
+ }
+
+ SUBCASE("shortprint nested") {
+ const char* code =
+ "local a = ?('nested')\n"
+ "return a";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(std::string(lua_tostring(L, -1)), "nested");
+ }
+ }
+
+ lua_close(L);
+}
+
+//IF (NOT B) I=1 J=2
+TEST_CASE("IF and WHILE shorthand") {
+ lua_State *L = luaL_newstate();
+ luaL_openlibs(L);
+
+ SUBCASE("short if") {
+ const char* code =
+ "b=false\n"
+ "if (not b) i=1 j=2\n"
+ "return j\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 2);
+ }
+ }
+
+ SUBCASE("short while") {
+ const char* code =
+ "x=5\n"
+ "y=4\n"
+ "while (x<7) x=x+1 y=y*2\n"
+ "return y\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 16);
+ }
+ }
+
+ lua_close(L);
+}
+
+//"+=", "-=", "*=", "/=", "%=", "^=", "\\=", "&=", "|=",
+// "^^=", "<<=", ">>=", ">>>=", "<<>=", ">><=", "..=",
+TEST_CASE("Assignment operators") {
+ lua_State *L = luaL_newstate();
+ luaL_openlibs(L);
+
+ SUBCASE("addition assignment (+=)") {
+ const char* code =
+ "x=6\n"
+ "x+=10\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 16);
+ }
+ }
+ SUBCASE("subtraction assignment (-=)") {
+ const char* code =
+ "x=6\n"
+ "x-=3\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 3);
+ }
+ }
+ SUBCASE("multiplication assignment (*=)") {
+ const char* code =
+ "x=6\n"
+ "x*=7\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 42);
+ }
+ }
+ SUBCASE("division assignment (*=)") {
+ const char* code =
+ "x=6\n"
+ "x/=3\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 2);
+ }
+ }
+ SUBCASE("mod assignment (%=)") {
+ const char* code =
+ "x=6\n"
+ "x%=5\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 1);
+ }
+ }
+ SUBCASE("pow assignment (^=)") {
+ const char* code =
+ "x=6\n"
+ "x^=3\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 216);
+ }
+ }
+ SUBCASE("int division assignment (\\=)") {
+ const char* code =
+ "x=33\n"
+ "x\\=8\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 4);
+ }
+ }
+ SUBCASE("bitwise and assignment (&=)") {
+ const char* code =
+ "x=10\n"
+ "x&=3\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 2);
+ }
+ }
+ SUBCASE("bitwise or assignment (|=)") {
+ const char* code =
+ "x=10\n"
+ "x|=3\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 11);
+ }
+ }
+ SUBCASE("bitwise xor assignment (^^=)") {
+ const char* code =
+ "x=3\n"
+ "x^^=5\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 6);
+ }
+ }
+ SUBCASE("bitwise shift left assignment (<<=)") {
+ const char* code =
+ "x=5\n"
+ "x<<=2\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 20);
+ }
+ }
+ SUBCASE("bitwise shift right assignment (>>=)") {
+ const char* code =
+ "x=210\n"
+ "x>>=2\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 52);
+ }
+ }
+ SUBCASE("logical shift right assignment (>>>=)") {
+ const char* code =
+ "x=12\n"
+ "x>>>=2\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 3);
+ }
+ }
+ SUBCASE("rotate left assignment (<<>=)") {
+ const char* code =
+ "x=11\n"
+ "x<<>=3\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 88);
+ }
+ }
+ SUBCASE("rotate right assignment (>><=)") {
+ const char* code =
+ "x=480\n"
+ "x>><=3\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 60);
+ }
+ }
+ SUBCASE("concat assignment operator (..=)") {
+ const char* code =
+ "x='hello'\n"
+ "x..='world'\n"
+ "return x\n";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TSTRING);
+ CHECK_EQ(std::string(lua_tostring(L, -1)), "helloworld");
+ }
+ }
+
+
+ lua_close(L);
+}
+
+TEST_CASE("Alternative xor operator") {
+ lua_State *L = luaL_newstate();
+ luaL_openlibs(L);
+
+ SUBCASE("alt xor (~)") {
+ const char* code =
+ "return 10~2";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TNUMBER);
+ CHECK_EQ(lua_tointeger(L, -1), 8);
+ }
+ }
+
+ lua_close(L);
+}
+
+TEST_CASE("Alternative not equal (!=)") {
+ lua_State *L = luaL_newstate();
+ luaL_openlibs(L);
+
+ SUBCASE("alt not equal (!=)") {
+ const char* code =
+ "return 10!=2";
+ int result = luaL_dostring(L, code);
+ CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+ if (result == LUA_OK) {
+ CHECK_EQ(lua_type(L, -1), LUA_TBOOLEAN);
+ CHECK_EQ(lua_toboolean(L, -1), true);
+ }
+ }
+
+ lua_close(L);
+}
\ No newline at end of file