aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
Commit message (Expand)AuthorAge
...
* Stratum ore: Allow use with no noise for simple horizontal strataparamat2017-10-01
* Make Player::peer_id server-side only and add getters and setters (#6478)Loïc Blot2017-09-30
* Update JsonCPP to 1.8.3 (#6466)Loïc Blot2017-09-26
* Implement mod communication channels (#6351)Loïc Blot2017-09-26
* Set placer to nil instead of a non-functional one in item_OnPlace (#6449)DTA72017-09-21
* ServerEnv: Clean up object lifecycle handling (#6414)sfan52017-09-15
* Network: Remove large parts of deprecated legacy code (#6404)SmallJoker2017-09-12
* Make INodeDefManager::getIds return a vector, not a setKahrl2017-09-12
* Schematic decorations: Add 'place_offset_y' placement parameterparamat2017-09-10
* Ores: Add stratum ore (#6352)Paramat2017-09-03
* Fix animation frame_speed and blend loosing precision due to incorrec… (#6357)sapier2017-09-01
* Clientevent refactor (#6320)Loïc Blot2017-08-28
* core.get_objects_inside_radius: Omit removed objects (#6318)you2017-08-27
* Respect object property hp_max field for players (#6287)SmallJoker2017-08-23
* Minimap: Add new HUD flag for minimap radar modeparamat2017-08-20
* Modernize code: very last fixes (#6290)Loïc Blot2017-08-20
* Modernize source code: last part (#6285)Loïc Blot2017-08-20
* Code modernization: subfolders (#6283)Loïc Blot2017-08-19
* Optimize headers (part 2) (#6272)Loïc Blot2017-08-18
* C++ modernize: Pragma once (#6264)Loïc Blot2017-08-17
* l_server, clientenvironment, clientiface: code modernizationLoic Blot2017-08-17
* Cleanup various headers to reduce compilation times (#6255)Loïc Blot2017-08-16
* Clouds API: change speed from 'y' to 'z', ColorSpecs in Lua docs (#6164)Ben Deutsch2017-07-24
* [CSM] Add flavour limits controlled by server (#5930)Loïc Blot2017-07-18
* Chat protocol rewrite (#5117)Loïc Blot2017-07-16
* Revert "CSM: Revert "[CSM] Add send_chat_message and run_server_chatcommand""Loic Blot2017-07-15
* CSM: Revert "[CSM] Add send_chat_message and run_server_chatcommand"rubenwardy2017-07-15
* Remove remaining modstore code (#6120)Elijah Duffy2017-07-14
* Expose getPointedThing to LuaDániel Juhász2017-07-07
* Main Menu: Allow copying directories from non-Minetest locations (#6095)Elijah Duffy2017-07-04
* Create a filesystem abstraction layer for CSM and only allow accessing files ...red-0012017-06-30
* Isolate irrlicht references and use a singleton (#6041)Loïc Blot2017-06-26
* Fix CSM crash caused by move to C++11. (#6027)red-0012017-06-22
* Automatic item and node colorization (#5640)Dániel Juhász2017-06-20
* Fix 2 warnings reported by GCCLoic Blot2017-06-20
* C++11 cleanup on constructors (#6000)Vincent Glize2017-06-19
* find_nodes_in_area: Extend maximal count to U32_MAX (#5277)SmallJoker2017-06-19
* Client::makeScreenshot: remove device paramLoic Blot2017-06-19
* Sound: Add pitch option (#5960)Rui2017-06-11
* Improve the path select GUI (#5852)red-0012017-06-11
* [CSM] Add function to get player privileges (#5933)red-0012017-06-07
* Main Menu: Add get_clientmodpath API (#5912)Elijah Duffy2017-06-06
* C++11 patchset 2: remove util/cpp11.h and util/cpp11_container.h (#5821)Loïc Blot2017-06-04
* Minetest for C++11 (CMakeLists + Travis)Loic Blot2017-06-04
* Enhance ABM performance a little bit by removing two std::set copy (#5815)Loïc Blot2017-05-25
* Fix wrong return value in get_sky Lua call since ad9fcf859ec2347325830e09504a...Loic Blot2017-05-23
* LINT fix & check all files with clang-formatLoic Blot2017-05-22
* [CSM] Add send_chat_message and run_server_chatcommand API functions (#5747)Pierre-Adrien Langrognet2017-05-21
* Fix LINT broken by dfa0c15ce045705f05487d623dc7beca6c945b4bLoic Blot2017-05-21
* [CSM] Add function to get the definition of items (#5732)bigfoot5472017-05-21
testWrapRows(); void testIsNumber(); void testIsPowerOfTwo(); void testMyround(); }; static TestUtilities g_test_instance; void TestUtilities::runTests(IGameDef *gamedef) { TEST(testAngleWrapAround); TEST(testLowercase); TEST(testTrim); TEST(testIsYes); TEST(testRemoveStringEnd); TEST(testUrlEncode); TEST(testUrlDecode); TEST(testPadString); TEST(testStartsWith); TEST(testStrEqual); TEST(testStringTrim); TEST(testStrToIntConversion); TEST(testStringReplace); TEST(testStringAllowed); TEST(testAsciiPrintableHelper); TEST(testUTF8); TEST(testRemoveEscapes); TEST(testWrapRows); TEST(testIsNumber); TEST(testIsPowerOfTwo); TEST(testMyround); } //////////////////////////////////////////////////////////////////////////////// inline float ref_WrapDegrees180(float f) { // This is a slower alternative to the wrapDegrees_180() function; // used as a reference for testing float value = fmodf(f + 180, 360); if (value < 0) value += 360; return value - 180; } inline float ref_WrapDegrees_0_360(float f) { // This is a slower alternative to the wrapDegrees_0_360() function; // used as a reference for testing float value = fmodf(f, 360); if (value < 0) value += 360; return value < 0 ? value + 360 : value; } void TestUtilities::testAngleWrapAround() { UASSERT(fabs(modulo360f(100.0) - 100.0) < 0.001); UASSERT(fabs(modulo360f(720.5) - 0.5) < 0.001); UASSERT(fabs(modulo360f(-0.5) - (-0.5)) < 0.001); UASSERT(fabs(modulo360f(-365.5) - (-5.5)) < 0.001); for (float f = -720; f <= -360; f += 0.25) { UASSERT(fabs(modulo360f(f) - modulo360f(f + 360)) < 0.001); } for (float f = -1440; f <= 1440; f += 0.25) { UASSERT(fabs(modulo360f(f) - fmodf(f, 360)) < 0.001); UASSERT(fabs(wrapDegrees_180(f) - ref_WrapDegrees180(f)) < 0.001); UASSERT(fabs(wrapDegrees_0_360(f) - ref_WrapDegrees_0_360(f)) < 0.001); UASSERT(wrapDegrees_0_360(fabs(wrapDegrees_180(f) - wrapDegrees_0_360(f))) < 0.001); } } void TestUtilities::testLowercase() { UASSERT(lowercase("Foo bAR") == "foo bar"); } void TestUtilities::testTrim() { UASSERT(trim("") == ""); UASSERT(trim("dirt_with_grass") == "dirt_with_grass"); UASSERT(trim("\n \t\r Foo bAR \r\n\t\t ") == "Foo bAR"); UASSERT(trim("\n \t\r \r\n\t\t ") == ""); } void TestUtilities::testIsYes() { UASSERT(is_yes("YeS") == true); UASSERT(is_yes("") == false); UASSERT(is_yes("FAlse") == false); UASSERT(is_yes("-1") == true); UASSERT(is_yes("0") == false); UASSERT(is_yes("1") == true); UASSERT(is_yes("2") == true); } void TestUtilities::testRemoveStringEnd() { const char *ends[] = {"abc", "c", "bc", "", NULL}; UASSERT(removeStringEnd("abc", ends) == ""); UASSERT(removeStringEnd("bc", ends) == "b"); UASSERT(removeStringEnd("12c", ends) == "12"); UASSERT(removeStringEnd("foo", ends) == ""); } void TestUtilities::testUrlEncode() { UASSERT(urlencode("\"Aardvarks lurk, OK?\"") == "%22Aardvarks%20lurk%2C%20OK%3F%22"); } void TestUtilities::testUrlDecode() { UASSERT(urldecode("%22Aardvarks%20lurk%2C%20OK%3F%22") == "\"Aardvarks lurk, OK?\""); } void TestUtilities::testPadString() { UASSERT(padStringRight("hello", 8) == "hello "); } void TestUtilities::testStartsWith() { UASSERT(str_starts_with(std::string(), std::string()) == true); UASSERT(str_starts_with(std::string("the sharp pickaxe"), std::string()) == true); UASSERT(str_starts_with(std::string("the sharp pickaxe"), std::string("the")) == true); UASSERT(str_starts_with(std::string("the sharp pickaxe"), std::string("The")) == false); UASSERT(str_starts_with(std::string("the sharp pickaxe"), std::string("The"), true) == true); UASSERT(str_starts_with(std::string("T"), std::string("The")) == false); } void TestUtilities::testStrEqual() { UASSERT(str_equal(narrow_to_wide("abc"), narrow_to_wide("abc"))); UASSERT(str_equal(narrow_to_wide("ABC"), narrow_to_wide("abc"), true)); } void TestUtilities::testStringTrim() { UASSERT(trim(" a") == "a"); UASSERT(trim(" a ") == "a"); UASSERT(trim("a ") == "a"); UASSERT(trim("") == ""); } void TestUtilities::testStrToIntConversion() { UASSERT(mystoi("123", 0, 1000) == 123); UASSERT(mystoi("123", 0, 10) == 10); } void TestUtilities::testStringReplace() { std::string test_str; test_str = "Hello there"; str_replace(test_str, "there", "world"); UASSERT(test_str == "Hello world"); test_str = "ThisAisAaAtest"; str_replace(test_str, 'A', ' '); UASSERT(test_str == "This is a test"); } void TestUtilities::testStringAllowed() { UASSERT(string_allowed("hello", "abcdefghijklmno") == true); UASSERT(string_allowed("123", "abcdefghijklmno") == false); UASSERT(string_allowed_blacklist("hello", "123") == true); UASSERT(string_allowed_blacklist("hello123", "123") == false); } void TestUtilities::testAsciiPrintableHelper() { UASSERT(IS_ASCII_PRINTABLE_CHAR('e') == true); UASSERT(IS_ASCII_PRINTABLE_CHAR('\0') == false); // Ensures that there is no cutting off going on... // If there were, 331 would be cut to 75 in this example // and 73 is a valid ASCII char. int ch = 331; UASSERT(IS_ASCII_PRINTABLE_CHAR(ch) == false); } void TestUtilities::testUTF8() { UASSERT(wide_to_utf8(utf8_to_wide("")) == ""); UASSERT(wide_to_utf8(utf8_to_wide("the shovel dug a crumbly node!")) == "the shovel dug a crumbly node!"); } void TestUtilities::testRemoveEscapes() { UASSERT(unescape_enriched<wchar_t>( L"abc\x1bXdef") == L"abcdef"); UASSERT(unescape_enriched<wchar_t>( L"abc\x1b(escaped)def") == L"abcdef"); UASSERT(unescape_enriched<wchar_t>( L"abc\x1b((escaped with parenthesis\\))def") == L"abcdef"); UASSERT(unescape_enriched<wchar_t>( L"abc\x1b(incomplete") == L"abc"); UASSERT(unescape_enriched<wchar_t>( L"escape at the end\x1b") == L"escape at the end"); // Nested escapes not supported UASSERT(unescape_enriched<wchar_t>( L"abc\x1b(outer \x1b(inner escape)escape)def") == L"abcescape)def"); } void TestUtilities::testWrapRows() { UASSERT(wrap_rows("12345678",4) == "1234\n5678"); // test that wrap_rows doesn't wrap inside multibyte sequences { const unsigned char s[] = { 0x2f, 0x68, 0x6f, 0x6d, 0x65, 0x2f, 0x72, 0x61, 0x70, 0x74, 0x6f, 0x72, 0x2f, 0xd1, 0x82, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82, 0x2f, 0x6d, 0x69, 0x6e, 0x65, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x2e, 0x2e, 0}; std::string str((char *)s); UASSERT(utf8_to_wide(wrap_rows(str, 20)) != L"<invalid UTF-8 string>"); }; { const unsigned char s[] = { 0x74, 0x65, 0x73, 0x74, 0x20, 0xd1, 0x82, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82, 0x20, 0xd1, 0x82, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82, 0x20, 0xd1, 0x82, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82, 0}; std::string str((char *)s); UASSERT(utf8_to_wide(wrap_rows(str, 8)) != L"<invalid UTF-8 string>"); } } void TestUtilities::testIsNumber() { UASSERT(is_number("123") == true); UASSERT(is_number("") == false); UASSERT(is_number("123a") == false); } void TestUtilities::testIsPowerOfTwo() { UASSERT(is_power_of_two(0) == false); UASSERT(is_power_of_two(1) == true); UASSERT(is_power_of_two(2) == true); UASSERT(is_power_of_two(3) == false); for (int exponent = 2; exponent <= 31; ++exponent) { UASSERT(is_power_of_two((1 << exponent) - 1) == false); UASSERT(is_power_of_two((1 << exponent)) == true); UASSERT(is_power_of_two((1 << exponent) + 1) == false); } UASSERT(is_power_of_two(U32_MAX) == false); } void TestUtilities::testMyround() { UASSERT(myround(4.6f) == 5); UASSERT(myround(1.2f) == 1); UASSERT(myround(-3.1f) == -3); UASSERT(myround(-6.5f) == -7); }