From 3291d088037a776dc6dc7f02994ec3d50659aa50 Mon Sep 17 00:00:00 2001 From: Miran Date: Mon, 8 Apr 2024 20:14:50 +0200 Subject: [PATCH] is_null turned into has_value --- CHANGELOG.md | 2 +- cleo_plugins/Math/Math.cpp | 8 +-- tests/cleo_tests/Math/2704.txt | 98 +++++++++++++++++----------------- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca9b71e7..d9f61d62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,7 +42,7 @@ - new opcode **2701 ([set_bit](https://library.sannybuilder.com/#/sa/math/2701))** - new opcode **2702 ([clear_bit](https://library.sannybuilder.com/#/sa/math/2702))** - new opcode **2703 ([toggle_bit](https://library.sannybuilder.com/#/sa/math/2703))** - - new opcode **2704 ([is_null](https://library.sannybuilder.com/#/sa/math/2704))** + - new opcode **2704 ([has_value](https://library.sannybuilder.com/#/sa/math/2704))** - new [MemoryOperations](https://github.com/cleolibrary/CLEO5/tree/master/cleo_plugins/MemoryOperations) plugin - memory related opcodes moved from CLEO core into separated plugin - validation of input and output parameters for all opcodes diff --git a/cleo_plugins/Math/Math.cpp b/cleo_plugins/Math/Math.cpp index 3f9cf802..2d0bfa0d 100644 --- a/cleo_plugins/Math/Math.cpp +++ b/cleo_plugins/Math/Math.cpp @@ -47,7 +47,7 @@ class Math CLEO_RegisterOpcode(0x2701, opcode_2701); // set_bit CLEO_RegisterOpcode(0x2702, opcode_2702); // clear_bit CLEO_RegisterOpcode(0x2703, opcode_2703); // toggle_bit - CLEO_RegisterOpcode(0x2704, opcode_2704); // is_null + CLEO_RegisterOpcode(0x2704, opcode_2704); // has_value } //0A8E=3,%3d% = %1d% + %2d% ; int @@ -418,7 +418,7 @@ class Math return OR_CONTINUE; } - //2704=1, is_null value %1d% + //2704=1, has_value value %1d% static OpcodeResult WINAPI opcode_2704(CScriptThread* thread) { auto paramType = OPCODE_PEEK_PARAM_TYPE(); @@ -426,12 +426,12 @@ class Math if(IsImmString(paramType) || IsVarString(paramType)) { OPCODE_READ_PARAM_STRING_LEN(text, 1); // one character is all we need - OPCODE_CONDITION_RESULT(text[0] == '\0'); + OPCODE_CONDITION_RESULT(text[0] != '\0'); return OR_CONTINUE; } auto value = OPCODE_READ_PARAM_ANY32(); - OPCODE_CONDITION_RESULT(value == 0); + OPCODE_CONDITION_RESULT(value != 0); return OR_CONTINUE; } } Math; diff --git a/tests/cleo_tests/Math/2704.txt b/tests/cleo_tests/Math/2704.txt index 3d354f28..860ca385 100644 --- a/tests/cleo_tests/Math/2704.txt +++ b/tests/cleo_tests/Math/2704.txt @@ -2,103 +2,103 @@ {$INCLUDE_ONCE ../cleo_tester.inc} script_name '2704' -test("2704 (is_null)", tests) +test("2704 (has_value)", tests) terminate_this_custom_script function tests - it("should test null", test1) - it("should test NOT null", test2) + it("should has NOT value", test1) + it("should has value", test2) return function test1 // int - 2704: is_null {value} 0 - assert_result_true() + 2704: has_value {value} 0 + assert_result_false() 0@ = 0 - 2704: is_null {value} 0@ - assert_result_true() + 2704: has_value {value} 0@ + assert_result_false() // float - 2704: is_null {value} 0.0 - assert_result_true() + 2704: has_value {value} 0.0 + assert_result_false() 0@ = 0.0 - 2704: is_null {value} 0@ - assert_result_true() + 2704: has_value {value} 0@ + assert_result_false() // short string - 2704: is_null {value} '' - assert_result_true() + 2704: has_value {value} '' + assert_result_false() 0@s = '' - 2704: is_null {value} 0@s - assert_result_true() + 2704: has_value {value} 0@s + assert_result_false() // long string - 2704: is_null {value} "" - assert_result_true() + 2704: has_value {value} "" + assert_result_false() 0@v = "" - 2704: is_null {value} 0@v - assert_result_true() + 2704: has_value {value} 0@v + assert_result_false() end function test2 // int - 2704: is_null {value} 1 - assert_result_false() + 2704: has_value {value} 1 + assert_result_true() 0@ = 1 - 2704: is_null {value} 0@ - assert_result_false() + 2704: has_value {value} 0@ + assert_result_true() - 2704: is_null {value} 0x00001000 - assert_result_false() + 2704: has_value {value} 0x00001000 + assert_result_true() - 2704: is_null {value} -1 - assert_result_false() + 2704: has_value {value} -1 + assert_result_true() - 2704: is_null {value} 1.0 - assert_result_false() + 2704: has_value {value} 1.0 + assert_result_true() // float - 0@ = 0.0 - 2704: is_null {value} 0@ + 0@ = 0.000001 + 2704: has_value {value} 0@ assert_result_true() - 2704: is_null {value} 0.000001 - assert_result_false() + 2704: has_value {value} 0.000001 + assert_result_true() // short string - 2704: is_null {value} 'a' - assert_result_false() + 2704: has_value {value} 'a' + assert_result_true() 0@s = 'a' - 2704: is_null {value} 0@s - assert_result_false() + 2704: has_value {value} 0@s + assert_result_true() - 2704: is_null {value} ' ' - assert_result_false() + 2704: has_value {value} ' ' + assert_result_true() - 2704: is_null {value} 'null' - assert_result_false() + 2704: has_value {value} 'null' + assert_result_true() // long string - 2704: is_null {value} "a" + 2704: has_value {value} "a" assert_result_true() 0@v = "a" - 2704: is_null {value} 0@v + 2704: has_value {value} 0@v assert_result_true() - 2704: is_null {value} " " - assert_result_false() + 2704: has_value {value} " " + assert_result_true() - 2704: is_null {value} "null" - assert_result_false() + 2704: has_value {value} "null" + assert_result_true() - 2704: is_null {value} "some very long testing string" - assert_result_false() + 2704: has_value {value} "some very long testing string" + assert_result_true() end end