summaryrefslogtreecommitdiff
path: root/npc/test/test1.txt
blob: 9fefe307c0a7b2c6bcd4ec222341a4a051728bf4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Evol scripts.
// Author:
//    4144
// Description:
//    script tests

function	script	test1function	{
    .var = .walkmask;
    if (.var != 3)
        mes "Error: testing test1 npc variables from function.";
    .var = getvariableofnpc(.walkmask, "test1");
    if (.var != 3)
        mes "Error: testing test1 npc variables from function.";
    .var = getvariableofnpc(.walkmask, "test2");
    if (.var != 4)
        mes "Error: testing test2 npc variables from function.";

    return;
}

test,10,5,0	script	test1	NPC_HAT_BOX,{

    function assert {
        if (getarg(0)) {
            .stats[1]++;
            // comment out the next line for less verbosity
            mesf("Success: %s.", getarg(1));
        } else {
            mesf("##BError##b: %s.", getarg(1));
        }
        return .stats[0]++;
    }

    function test_npc_vars {
        mes("##2Testing NPC variables...##0");
        .var = .walkmask;
        assert(.var == 3, "test1 npc variales");
        .var = getvariableofnpc(.walkmask, "test1");
        assert(.var == 3, "test1 npc variables from function");
        .var = getvariableofnpc(.walkmask, "test2");
        assert(.var == 4, "test2 npc variables");
        test1function();
        next();
    }

    function test_quest_vars {
        mes("##2Testing quest variables...##0");
        .@time = 1000;
        setq(Test_testing1, 1, 2, 3, .@time);
        assert(getq(Test_testing1) == 1, "getq1 = 1");
        assert(getq2(Test_testing1) == 2, "getq2 = 2");
        assert(getq3(Test_testing1) == 3, "getq3 = 3");
        assert(getqtime(Test_testing1) == .@time, "getqtime = 1000");
        next();
        .@time = 2000;
        setq(Test_testing1, 2, 3, 4, .@time);
        assert(getq(Test_testing1) == 2, "getq1 = 2");
        assert(getq2(Test_testing1) == 3, "getq2 = 3");
        assert(getq3(Test_testing1) == 4, "getq3 = 4");
        assert(getqtime(Test_testing1) == .@time, "getqtime = 2000");
        next();
        setq(Test_testing1, 0);
    }

    function test_translation_old {
        mes("##2Testing old translation system without gender...##0");
        assert(l("test @@", "") == "test ", "\"test @@\", \"\"");
        assert(l("test @@", "foo") == "test foo", "\"test @@\", \"foo\"");
        assert(l("@@", "") == "", "\"@@\", \"\"");
        assert(l("@@") == "@@", "\"@@\"");
        assert(l("@@ @@ @@", "this", "is", "test") == "this is test", "\"@@ @@ @@\", \"this\", \"is\", \"test\"");
        assert(l("data @@ @@ @@ data", "this", "is", "test") == "data this is test data", "\"data @@ @@ @@ data\", \"this\", \"is\", \"test\"");
        next();

        /*
        mesf("##2Testing old translation system as %s gender...##0", g("female", "male"));
        if (Sex == 1)
            assert(lg("test1 @@", "test2 @@", "line") == "test2 line#1", "\"test1 @@\", \"test2 @@\", \"line\"");
        else if (Sex == 0)
            assert(lg("test1 @@", "test2 @@", "line") == "test1 line#0", "\"test1 @@\", \"test2 @@\", \"line\"");
        */
        next();
    }

    function test_translation_new {
        mes("##2Testing new translation system without gender...##0");
        assert(l("") == "", "\"\"");
        assert(l("test") == "test", "\"test\"");
        assert(l("test %s", "") == "test ", "\"test %s\", \"\"");
        assert(l("test %s", "foo") == "test foo", "\"test %s\", \"foo\"");
        assert(l("%s", "") == "", "\"%s\", \"\"");
        assert(l("%s") == "%s", "\"%s\"");
        assert(l("%%") == "%%", "\"%##0%\""); // XXX: %% is reserved for emotes in manaplus, so we escape it with color
        assert(l("%d%%", 6) == "6%", "\"%d%##0%\", 6"); // XXX: %% is reserved for emotes in manaplus, so we escape it with color
        assert(l("%s %s %s", "this", "is", "test") == "this is test", "\"%s %s %s\", \"this\", \"is\", \"test\"");
        assert(l("%s %d %s", "foo", 69, "bar") == "foo 69 bar", "\"%s %d %s\", \"foo\", 69, \"bar\"");
        assert(l("data %s %s %s data", "this", "is", "test") == "data this is test data", "\"data %s %s %s data\", \"this\", \"is\", \"test\"");
        next();

        /*
        mesf("##2Testing new translation system as %s gender...##0", g("female", "male"));
        if (Sex == 1) {
            assert(lg("test") == "test#1", "\"test\"");
            assert(lg("test1", "test2") == "test2#1", "\"test1\", \"test2\"");
            assert(lg("test1 %s", "test2 %s", "line") == "test2 line#1", "\"test1 %s\", \"test2 %s\", \"line\"");
        } else if (Sex == 0) {
            assert(lg("test") == "test#0", "\"test\"");
            assert(lg("test1", "test2") == "test1#0", "\"test1\", \"test2\"");
            assert(lg("test1 %s", "test2 %s", "line") == "test1 line#0", "\"test1 %s\", \"test2 %s\", \"line\"");
        }
        */
        next();

        mes("##2Testing advanced translation...##0");
        assert(l("foo %2$s bar %1$s baz", "qux", "quux") == "foo quux bar qux baz", "\"foo %2$s bar %1$s baz\", \"qux\", \"quux\"");
        assert(l("%5d",   6) == "    6", "\"%5d\", 6");
        assert(l("%5d",  -6) == "   -6", "\"%5d\", -6");
        assert(l("%+5d",  6) == "   +6", "\"%+5d\", 6");
        assert(l("%+5d", -6) == "   -6", "\"%+5d\", -6");
        assert(l("%-5d",  6) == "6    ", "\"%-5d\", 6");
        assert(l("%-5d", -6) == "-6   ", "\"%-5d\", -6");
        assert(l("% 5d",  6) == "    6", "\"% 5d\", 6");
        assert(l("% 5d", -6) == "   -6", "\"% 5d\", -6");
        assert(l("%05d",  6) == "00006", "\"%05d\", 6");
        assert(l("%05d", -6) == "-0006", "\"%05d\", -6");
        assert(l("%10s", "test")  == "      test", "\"%10s\", \"test\"");
        assert(l("% 10s", "test") == "      test", "\"% 10s\", \"test\"");
        assert(l("%-10s", "test") == "test      ", "\"%-10s\", \"test\"");
        next();
    }


    do {
        mes("Please select a test:");
        select(
            "NPC variables",
            "quest variables",
            "translation (old)",
            "translation (new)",
            "everything");

        setarray(.stats[0], 0, 0); // make sure we have a clean state
        clear();

        switch (@menu) {
        case 1: test_npc_vars(); break;
        case 2: test_quest_vars(); break;
        case 3: test_translation_old(); break;
        case 4: test_translation_new(); break;
        default:
            test_translation_old();
            test_translation_new();
            test_npc_vars();
            test_quest_vars();
        }

        mesf("##BTests complete. [%02d/%02d]", .stats[1], .stats[0]);
        next();
    } while (true);
    close;

OnInit:
    .walkmask = 3;
    end;
}