summaryrefslogtreecommitdiff
path: root/npc/dev/test.txt
diff options
context:
space:
mode:
authorJedzkie <jedzkie13@rocketmail.com>2020-06-23 08:00:00 +0800
committerGitHub <noreply@github.com>2020-06-23 08:00:00 +0800
commit520863eaeda83da14b88d09f6378cd8abd5a5174 (patch)
tree2496ea36744dc2f51d264741a78699e719ceeb3b /npc/dev/test.txt
parent0b7768837bed2aa521de5b9b76b2348943d7db20 (diff)
parent9b89425550094f51d633e5b5d6e86af65bffbf39 (diff)
downloadhercules-520863eaeda83da14b88d09f6378cd8abd5a5174.tar.gz
hercules-520863eaeda83da14b88d09f6378cd8abd5a5174.tar.bz2
hercules-520863eaeda83da14b88d09f6378cd8abd5a5174.tar.xz
hercules-520863eaeda83da14b88d09f6378cd8abd5a5174.zip
Merge branch 'master' into jedzkie-pr03
Diffstat (limited to 'npc/dev/test.txt')
-rw-r--r--npc/dev/test.txt49
1 files changed, 49 insertions, 0 deletions
diff --git a/npc/dev/test.txt b/npc/dev/test.txt
index a9e78489a..291671913 100644
--- a/npc/dev/test.txt
+++ b/npc/dev/test.txt
@@ -116,12 +116,55 @@ function script F_TestVarOfAnotherNPC {
end;
}
+- script export test FAKE_NPC,{
+
+ function OnInit {
+ // functions labels should not be able to be called as events
+ // if a regression occurs, this function could end up being called when
+ // Hercules processes OnInit event calls (issue #2137)
+
+ // NOTE: If script_config.functions_as_events is enabled (defaults: off)
+ // and this this function is marked as public, it will trigger the
+ // warning and fail the unit test regardless.
+
+ $@something_bad_happened[0] = true;
+ end;
+ }
+
+ private function Private {
+ // function explicitly marked as private
+ return;
+ }
+
+ public function Public {
+ // this is for testing public local functions and ownership of the
+ // script
+
+ return getnpcid();
+ }
+
+ public function RefTest {
+ // this is to check if references are passed around properly
+
+ return set(getarg(0), 1337);
+ }
+}
+
function script HerculesSelfTestHelper {
if (.once > 0)
return .errors;
.once = 1;
.errors = 0;
+ // number literals
+ callsub(OnCheck, "decimal number literal", 255, 255);
+ callsub(OnCheck, "hexadecimal number literal", 0xFF, 255);
+ callsub(OnCheck, "octal number literal", 0o377, 255);
+ callsub(OnCheck, "binary number literal", 0b11111111, 255);
+ callsub(OnCheck, "binary literal bitwise OR", 0b11110000 | 0xF, 255);
+ callsub(OnCheck, "decimal literal with separator", 2_5_5, 255);
+ callsub(OnCheck, "binary literal with separator", 0b_1111_1111, 255);
+
// Callsub (basic)
callsub(OnCheck, "Callsub", 1, 1);
callsub(OnCheck, "Callsub (getarg default values)", 1);
@@ -785,6 +828,12 @@ function script HerculesSelfTestHelper {
callsub(OnCheck, "data_to_string (string variable)", data_to_string(.@x$), ".@x$");
callsub(OnCheck, "data_to_string (integer variable)", data_to_string(.@x), ".@x");
+ "export test"::RefTest(.@refTest = 69);
+ callsub(OnCheck, "function as event (regression)", $@something_bad_happened[0], false);
+ callsub(OnCheck, "public local function ownership", "export test"::Public(), getnpcid());
+ callsub(OnCheck, "public local function var reference test", .@refTest, 1337);
+ callsub(OnCheck, "programatic public local call", callfunctionofnpc("export test", "RefTest", .@refTest = 1), 1337);
+
if (.errors) {
consolemes(CONSOLEMES_DEBUG, "Script engine self-test [ \033[0;31mFAILED\033[0m ]");
consolemes(CONSOLEMES_DEBUG, "**** The test was completed with " + .errors + " errors. ****");