From aaef96a2faeb761b2a8b893158899f48c39cbf4b Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Fri, 7 Mar 2025 17:44:59 +0100 Subject: Revamped lanes.nameof --- unit_tests/lane_tests.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'unit_tests') diff --git a/unit_tests/lane_tests.cpp b/unit_tests/lane_tests.cpp index 77c7f61..63626ae 100644 --- a/unit_tests/lane_tests.cpp +++ b/unit_tests/lane_tests.cpp @@ -8,16 +8,25 @@ TEST_CASE("lanes.nameof") LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } }; S.requireSuccess("lanes = require 'lanes'.configure()"); + // no argument is not good + S.requireFailure("local t, n = lanes.nameof()"); + + // more than one argument is not good + S.requireFailure("local t, n = lanes.nameof(true, false)"); + // 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"); + + // a temporary object has no name S.requireReturnedString("local t, n = lanes.nameof({}); return t .. ': ' .. tostring(n)", "table: nil"); + S.requireReturnedString("local t, n = lanes.nameof(function() end); return t .. ': ' .. tostring(n)", "function: 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"); + 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