diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-08-04 22:36:56 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-08-04 22:36:56 +0530 |
| commit | c7e105ee4254d00f591c4c002f32c223f4c2448a (patch) | |
| tree | 17ebadd5dc1a5e148c4b2f5ed1c70b7c7e54fe1a /spec/LuaRuntimeSpec.cpp | |
| parent | 0d1258aee3f39c8d5348588a87e804ec8cd27bd5 (diff) | |
| download | null-browser-c7e105ee4254d00f591c4c002f32c223f4c2448a.tar.gz null-browser-c7e105ee4254d00f591c4c002f32c223f4c2448a.zip | |
Add on_result callback for web.view.run_js
Diffstat (limited to '')
| -rw-r--r-- | spec/LuaRuntimeSpec.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/LuaRuntimeSpec.cpp b/spec/LuaRuntimeSpec.cpp index aeaaab2..4d9270c 100644 --- a/spec/LuaRuntimeSpec.cpp +++ b/spec/LuaRuntimeSpec.cpp @@ -1,7 +1,9 @@ #include <QtCore> +#include <qtestcase.h> #include <uv.h> #include "LuaRuntime.hpp" +#include "lua.h" #include "testUtils.h" // NOLINTBEGIN @@ -124,6 +126,58 @@ private slots: QVERIFY(wait_for_lua_to_be_true("return _G.spawn_exit_code == 0")); } } + + void test_push_qvariant() { + describe("LuaRuntime::push_qvariant"); + + context("when called with a QString"); + it("pushes lua string") { + auto &lua = LuaRuntime::instance(); + auto *state = lua.get_state(); + + LuaRuntime::push_qvariant(state, QString("hello")); + + QVERIFY(lua_isstring(state, 1)); + QCOMPARE(lua_tostring(state, 1), "hello"); + lua_pop(state, 1); + } + + context("when called with a QVariant int"); + it("pushes lua number") { + auto &lua = LuaRuntime::instance(); + auto *state = lua.get_state(); + + LuaRuntime::push_qvariant(state, QVariant(42)); + + QVERIFY(lua_isnumber(state, 1)); + QCOMPARE(lua_tointeger(state, 1), 42); + lua_pop(state, 1); + } + + context("when called with a QVariant double"); + it("pushes lua number") { + auto &lua = LuaRuntime::instance(); + auto *state = lua.get_state(); + + LuaRuntime::push_qvariant(state, QVariant(42.69)); + + QVERIFY(lua_isnumber(state, 1)); + QCOMPARE(lua_tonumber(state, 1), 42.69); + lua_pop(state, 1); + } + + context("when called with a QVariant bool"); + it("pushes lua boolean") { + auto &lua = LuaRuntime::instance(); + auto *state = lua.get_state(); + + LuaRuntime::push_qvariant(state, QVariant(true)); + + QVERIFY(lua_isboolean(state, 1)); + QCOMPARE(lua_toboolean(state, 1), true); + lua_pop(state, 1); + } + } }; QTEST_REGISTER(LuaRuntimeSpec) |
