Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
524 changes: 489 additions & 35 deletions doc/script_commands.txt

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions npc/scripts_test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@
npc: npc/test/infinite_warp.txt
npc: npc/test/OnInterInit.txt
npc: npc/test/npc_test_checkweight.txt

npc: npc/test/mdarray_dyn_literal_integer_key_tests.txt
npc: npc/test/mdarray_dyn_literal_empty_table_tests.txt
npc: npc/test/mdarray_dyn_dict_only_tests.txt
npc: npc/test/mdarray_dyn_empty_assignment_tests.txt
npc: npc/test/mdarray_dyn_string_debug_tests.txt
npc: npc/test/callnpcsub_multireturn_tests.txt
189 changes: 189 additions & 0 deletions npc/test/callnpcsub_multireturn_tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
//============================================================
// npc/custom/callnpcsub_multireturn_tests.txt
// Tests for callnpcsub and multiple return values.
//============================================================
// Load with:
// npc: npc/custom/callnpcsub_multireturn_tests.txt
//============================================================

function script MR_ASSERT {
.@ok = getarg(0);
.@msg$ = getarg(1);

if (.@ok)
debugmes "[OK] " + .@msg$;
else
debugmes "[FAIL] " + .@msg$;

return;
}

function script F_MR_Basic {
return "Bob", 20, "Knight";
}

function script F_MR_Empty {
return;
}

function script F_MR_One {
return 123;
}

prontera,158,184,4 script mr_test_runner 4_F_KAFRA1,{
mes "[mr_test_runner]";
mes "Runs callnpcsub / multiple-return tests.";
next;

OnInit:
callsub S_CallFuncMultiple;
callsub S_CallFunc1;
callsub S_CallSubMultiple;
callsub S_CallNpcSubMultiple;
callsub S_EmptyAndSingleReturn;
callsub S_ReturnOverwrite;
callsub S_CallNpc2;
callsub S_ManualErrorChecks;
end;

mes "Done. Check the console for [OK]/[FAIL].";
close;

S_CallFuncMultiple:
debugmes "-- S_CallFuncMultiple";

callfunc "F_MR_Basic";
.@count = getreturncount();
.@r0$ = getreturn(0);
.@r1 = getreturn(1);
.@r2$ = getreturn(2);

callfunc "MR_ASSERT", .@count == 3, "callfunc return count == 3";
callfunc "MR_ASSERT", .@r0$ == "Bob", "callfunc return[0] == Bob";
callfunc "MR_ASSERT", .@r1 == 20, "callfunc return[1] == 20";
callfunc "MR_ASSERT", .@r2$ == "Knight", "callfunc return[2] == Knight";

return;

S_CallFunc1:
debugmes "-- S_CallFunc1";

.@name$ = callfunc("F_MR_Basic");
.@count = getreturncount();
.@age = getreturn(1);

callfunc "MR_ASSERT", .@name$ == "Bob", "direct callfunc expression gets first return";
callfunc "MR_ASSERT", .@count == 3, "return buffer still has 3 values";
callfunc "MR_ASSERT", .@age == 20, "getreturn still reads second value";

return;

S_CallSubMultiple:
debugmes "-- S_CallSubMultiple";

callsub S_LocalInfo, "Prontera";
.@count = getreturncount();
.@r0$ = getreturn(0);
.@r1 = getreturn(1);
.@r2$ = getreturn(2);

callfunc "MR_ASSERT", .@count == 3, "callsub return count == 3";
callfunc "MR_ASSERT", .@r0$ == "Prontera", "callsub return[0]";
callfunc "MR_ASSERT", .@r1 == 100, "callsub return[1]";
callfunc "MR_ASSERT", .@r2$ == "local", "callsub return[2]";

return;

S_LocalInfo:
.@name$ = getarg(0);
return .@name$, 100, "local";

S_CallNpcSubMultiple:
debugmes "-- S_CallNpcSubMultiple";

callnpcsub "MR_TARGET", "S_GetInfo", "prtg_cas01";
.@count = getreturncount();
.@map$ = getreturn(0);
.@region$ = getreturn(1);
.@x = getreturn(2);
.@y = getreturn(3);

callfunc "MR_ASSERT", .@count == 4, "callnpcsub return count == 4";
callfunc "MR_ASSERT", .@map$ == "prtg_cas01", "callnpcsub return[0] map";
callfunc "MR_ASSERT", .@region$ == "Prontera", "callnpcsub return[1] region";
callfunc "MR_ASSERT", .@x == 134, "callnpcsub return[2] x";
callfunc "MR_ASSERT", .@y == 65, "callnpcsub return[3] y";

return;

S_EmptyAndSingleReturn:
debugmes "-- S_EmptyAndSingleReturn";

callfunc "F_MR_Empty";
.@empty_count = getreturncount();

callfunc "F_MR_One";
.@one_count = getreturncount();
.@one_value = getreturn(0);

callfunc "MR_ASSERT", .@empty_count == 0, "return; gives zero return values";
callfunc "MR_ASSERT", .@one_count == 1, "single return count == 1";
callfunc "MR_ASSERT", .@one_value == 123, "single return value == 123";

return;

S_ReturnOverwrite:
debugmes "-- S_ReturnOverwrite";

callfunc "F_MR_Basic";
.@first_count = getreturncount();

callfunc "F_MR_One";
.@second_count = getreturncount();
.@second_value = getreturn(0);

callfunc "MR_ASSERT", .@first_count == 3, "initial return count == 3";
callfunc "MR_ASSERT", .@second_count == 1, "second call overwrites return buffer";
callfunc "MR_ASSERT", .@second_value == 123, "second call return[0] == 123";

return;

S_CallNpc2:
debugmes "-- S_CallNpc2";

.@local_value = 10;
callnpcsub "MR_TARGET", "S_ScopeTest", .@local_value;
.@r0 = getreturn(0);
.@r1 = getreturn(1);

callfunc "MR_ASSERT", .@local_value == 10, "caller .@ scope was not modified";
callfunc "MR_ASSERT", .@r0 == 11, "target received argument and returned arg + 1";
callfunc "MR_ASSERT", .@r1 == 99, "target .@ local scope worked";

return;

S_ManualErrorChecks:
debugmes "-- S_ManualErrorChecks";
debugmes "Manual checks that should ERROR + stop script:";
debugmes " callnpcsub \"MR_TARGET\", \"OnInit\";";
debugmes " callnpcsub \"MissingNPC\", \"S_Label\";";
debugmes " callnpcsub \"MR_TARGET\", \"S_Missing\";";
debugmes " callfunc \"F_MR_One\"; getreturn(99);";
return;
}

- script MR_TARGET -1,{
end;

S_GetInfo:
.@map$ = getarg(0);
return .@map$, "Prontera", 134, 65;

S_ScopeTest:
.@v = getarg(0);
.@local_only = 99;
return .@v + 1, .@local_only;

OnInit:
end;
}
Loading
Loading