From 723476a90cccc611f9c80f812f0b96541fab326e Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 5 Mar 2025 10:34:27 +0100 Subject: lanes.nameof internal code refacto + a few unit tests --- unit_tests/lane_tests.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'unit_tests') diff --git a/unit_tests/lane_tests.cpp b/unit_tests/lane_tests.cpp index 498c96e..77c7f61 100644 --- a/unit_tests/lane_tests.cpp +++ b/unit_tests/lane_tests.cpp @@ -1,6 +1,25 @@ #include "_pch.hpp" #include "shared.h" +// ################################################################################################# +// ################################################################################################# +TEST_CASE("lanes.nameof") +{ + LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } }; + S.requireSuccess("lanes = require 'lanes'.configure()"); + + // a constant is itself, stringified + S.requireReturnedString("local t, n = lanes.nameof('bob'); return t .. ': ' .. tostring(n)", "string: bob"); + S.requireReturnedString("local t, n = lanes.nameof(true); return t .. ': ' .. tostring(n)", "boolean: true"); + S.requireReturnedString("local t, n = lanes.nameof(42); return t .. ': ' .. tostring(n)", "number: 42"); + S.requireReturnedString("local t, n = lanes.nameof({}); return t .. ': ' .. tostring(n)", "table: nil"); + + // look for something in _G + S.requireReturnedString("local t, n = lanes.nameof(print); return t .. ': ' .. tostring(n)", "function: _G/print"); + S.requireReturnedString("local t, n = lanes.nameof(string); return t .. ': ' .. tostring(n)", "table: _G/string"); + S.requireReturnedString("local t, n = lanes.nameof(string.sub); return t .. ': ' .. tostring(n)", "function: _G/string/sub"); +} + // ################################################################################################# // ################################################################################################# -- cgit v1.2.3-55-g6feb