Skip to content

Commit

Permalink
is_null turned into has_value
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Apr 8, 2024
1 parent eace1a6 commit 3291d08
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions cleo_plugins/Math/Math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -418,20 +418,20 @@ 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();

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;
98 changes: 49 additions & 49 deletions tests/cleo_tests/Math/2704.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3291d08

Please sign in to comment.