summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-section.jsx
blob: 0c37afeaad7831affbd2ba41a01d58a711905df3 (plain)
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/**
 * This is a JSX version of shellinford library:
 * https://code.google.com/p/shellinford/
 *
 * License: http://shibu.mit-license.org/
 */

import "test-case.jsx";
import "oktavia.jsx";
import "metadata.jsx";

class _Test extends TestCase
{
    var oktavia : Oktavia;
    var section : Section;

    override function setUp () : void
    {
        this.oktavia = new Oktavia();
        this.section = this.oktavia.addSection('document');
        this.oktavia.addWord("abracadabra");
        this.section.setTail("doc1");
        this.oktavia.addWord("mississippi");
        this.section.setTail("doc2");
        this.oktavia.addWord("abracadabra mississippi");
        this.section.setTail("doc3");
        this.oktavia.build(25, false);
    }

    function test_doc_sizes () : void
    {
        this.expect(this.section.size()).toBe(3);
    }

    function test_get_section_index () : void
    {
        this.expect(this.section.getSectionIndex(0)).toBe(0);
        this.expect(this.section.getSectionIndex(10)).toBe(0);
        this.expect(this.section.getSectionIndex(11)).toBe(1);
        this.expect(this.section.getSectionIndex(21)).toBe(1);
        this.expect(this.section.getSectionIndex(22)).toBe(2);
        this.expect(this.section.getSectionIndex(44)).toBe(2);
    }

    function test_get_section_index_boundary () : void
    {
        try
        {
            this.section.getSectionIndex(-1);
            this.fail("fm.getSectionIndex()");
        }
        catch (e : Error)
        {
        }
        try
        {
            this.section.getSectionIndex(45);
            this.fail("fm.getSectionIndex()");
        }
        catch (e : Error)
        {
        }
    }

    function test_get_section_content () : void
    {
        this.expect(this.section.getContent(0)).toBe("abracadabra");
        this.expect(this.section.getContent(1)).toBe("mississippi");
        this.expect(this.section.getContent(2)).toBe("abracadabra mississippi");
    }

    function test_get_section_content_boundary () : void
    {
        try
        {
            this.section.getContent(3);
            this.fail("fm.getContent()");
        }
        catch (e : Error)
        {
        }
        try
        {
            this.section.getContent(-1);
            this.fail("fm.getContent()");
        }
        catch (e : Error)
        {
        }
    }

    function test_get_section_name () : void
    {
        this.expect(this.section.getName(0)).toBe("doc1");
        this.expect(this.section.getName(1)).toBe("doc2");
        this.expect(this.section.getName(2)).toBe("doc3");
    }

    function test_get_section_name_boundary () : void
    {
        try
        {
            this.section.getName(3);
            this.fail("fm.getName()");
        }
        catch (e : Error)
        {
        }
        try
        {
            this.section.getName(-1);
            this.fail("fm.getName()");
        }
        catch (e : Error)
        {
        }
    }

    function test_load_dump_and_doc_sizes () : void
    {
        var dump = this.oktavia.dump();
        this.oktavia.load(dump);
        this.section = this.oktavia.getSection('document');

        this.expect(this.section.size()).toBe(3);
    }

    function test_load_dump_and_get_section_index () : void
    {
        var dump = this.oktavia.dump();
        this.oktavia.load(dump);
        this.section = this.oktavia.getSection('document');

        this.expect(this.section.getSectionIndex(0)).toBe(0);
        this.expect(this.section.getSectionIndex(10)).toBe(0);
        this.expect(this.section.getSectionIndex(11)).toBe(1);
        this.expect(this.section.getSectionIndex(21)).toBe(1);
        this.expect(this.section.getSectionIndex(22)).toBe(2);
        this.expect(this.section.getSectionIndex(44)).toBe(2);
    }

    function test_load_dump_and_get_section_index_boundary () : void
    {
        var dump = this.oktavia.dump();
        this.oktavia.load(dump);
        this.section = this.oktavia.getSection('document');

        try
        {
            this.section.getSectionIndex(-1);
            this.fail("fm.getSectionIndex()");
        }
        catch (e : Error)
        {
        }
        try
        {
            this.section.getSectionIndex(45);
            this.fail("fm.getSectionIndex()");
        }
        catch (e : Error)
        {
        }
    }

    function test_load_dump_and_get_section_content () : void
    {
        var dump = this.oktavia.dump();
        this.oktavia.load(dump);
        this.section = this.oktavia.getSection('document');

        this.expect(this.section.getContent(0)).toBe("abracadabra");
        this.expect(this.section.getContent(1)).toBe("mississippi");
        this.expect(this.section.getContent(2)).toBe("abracadabra mississippi");
    }

    function test_load_dump_and_get_section_content_boundary () : void
    {
        var dump = this.oktavia.dump();
        this.oktavia.load(dump);
        this.section = this.oktavia.getSection('document');

        try
        {
            this.section.getContent(3);
            this.fail("fm.getContent()");
        }
        catch (e : Error)
        {
        }
        try
        {
            this.section.getContent(-1);
            this.fail("fm.getContent()");
        }
        catch (e : Error)
        {
        }
    }

    function test_load_dump_and_get_section_name () : void
    {
        var dump = this.oktavia.dump();
        this.oktavia.load(dump);
        this.section = this.oktavia.getSection('document');

        this.expect(this.section.getName(0)).toBe("doc1");
        this.expect(this.section.getName(1)).toBe("doc2");
        this.expect(this.section.getName(2)).toBe("doc3");
    }

    function test_load_dump_and_get_section_name_boundary () : void
    {
        var dump = this.oktavia.dump();
        this.oktavia.load(dump);
        this.section = this.oktavia.getSection('document');

        try
        {
            this.section.getName(3);
            this.fail("fm.getName()");
        }
        catch (e : Error)
        {
        }
        try
        {
            this.section.getName(-1);
            this.fail("fm.getName()");
        }
        catch (e : Error)
        {
        }
    }
}