summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/misc/oktavia/test
diff options
context:
space:
mode:
Diffstat (limited to 'web/server/h2o/libh2o/misc/oktavia/test')
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-binary-util.jsx190
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-bit-vector.jsx131
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-burrows-wheeler-transform.jsx24
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-fm-index.jsx250
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-getopt.jsx84
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-block.jsx226
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-section.jsx235
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-splitter.jsx173
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-stemming.jsx55
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-table.jsx213
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-query-parser.jsx92
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-query-string-parser.jsx94
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-sax.jsx147
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-search-result.jsx159
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/test/test-wavelet-matrix.jsx143
15 files changed, 2216 insertions, 0 deletions
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-binary-util.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-binary-util.jsx
new file mode 100644
index 000000000..25882e340
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-binary-util.jsx
@@ -0,0 +1,190 @@
+import "test-case.jsx";
+import "binary-util.jsx";
+
+class _Test extends TestCase
+{
+ function test_16bit_number() : void
+ {
+ this.expect(Binary.load16bitNumber(Binary.dump16bitNumber(0), 0)).toBe(0);
+ this.expect(Binary.load16bitNumber(Binary.dump16bitNumber(65535), 0)).toBe(65535);
+ this.expect(Binary.load16bitNumber(Binary.dump16bitNumber(65536), 0)).notToBe(65536);
+ }
+
+ function test_32bit_number() : void
+ {
+ this.expect(Binary.load32bitNumber(Binary.dump32bitNumber(0), 0)).toBe(0);
+ this.expect(Binary.load32bitNumber(Binary.dump32bitNumber(4294967295), 0)).toBe(4294967295);
+ this.expect(Binary.load32bitNumber(Binary.dump32bitNumber(4294967296), 0)).notToBe(4294967296);
+ }
+
+ function test_string() : void
+ {
+ var str = Binary.loadString(Binary.dumpString('hello world'), 0);
+ this.expect(str.result).toBe('hello world');
+
+ // 7bit safe charactes will be compressed
+ this.expect(Binary.dumpString('hello world').length).toBeLE('hello world'.length);
+ this.expect(Binary.dumpString('').length).toBe(''.length + 1);
+
+ // 7bit unsafe charactes will not be compressed
+ this.expect(Binary.dumpString('\u1111\u1111').length).toBe('\u1111\u1111'.length + 1);
+ }
+
+ function test_string_list() : void
+ {
+ var list = Binary.loadStringList(Binary.dumpStringList(['hello', 'world']), 0);
+ this.expect(list.result[0]).toBe('hello');
+ this.expect(list.result[1]).toBe('world');
+
+ var list = Binary.loadStringList(Binary.dumpStringList(['\u1111', '\u2222']), 0);
+ this.expect(list.result[0]).toBe('\u1111');
+ this.expect(list.result[1]).toBe('\u2222');
+ }
+
+ function test_string_list_map() : void
+ {
+ var src = {'hello': ['HELLO'], 'world': ['WORLD']};
+ var list = Binary.loadStringListMap(Binary.dumpStringListMap(src), 0);
+ this.expect(list.result['hello'][0]).toBe('HELLO');
+ this.expect(list.result['world'][0]).toBe('WORLD');
+ }
+
+ function test_32bit_number_list_blank() : void
+ {
+ var list = [0, 0, 0, 0, 0, 0];
+ var dumped = Binary.dump32bitNumberList(list);
+ this.expect(dumped.length).toBe(2 + 1);
+ var loaded = Binary.load32bitNumberList(dumped, 0);
+ this.expect(loaded.result.length).toBe(6);
+ this.expect(loaded.result[0]).toBe(0);
+ this.expect(loaded.result[5]).toBe(0);
+ this.expect(loaded.offset).toBe(2 + 1);
+ }
+
+ function test_32bit_number_list_non_blank() : void
+ {
+ var list = [1, 1, 1, 1, 1, 1];
+ var dumped = Binary.dump32bitNumberList(list);
+ this.expect(dumped.length).toBe(2 * 6 + 2 + 1);
+ var loaded = Binary.load32bitNumberList(dumped, 0);
+ this.expect(loaded.result.length).toBe(6);
+ this.expect(loaded.result[0]).toBe(1);
+ this.expect(loaded.result[5]).toBe(1);
+ this.expect(loaded.offset).toBe(2 * 6 + 2 + 1);
+ }
+
+ function test_32bit_number_list_zebra() : void
+ {
+ var list = [1, 0, 1, 0, 1, 0];
+ var dumped = Binary.dump32bitNumberList(list);
+ this.expect(dumped.length).toBe(2 * 3 + 2 + 1);
+ var loaded = Binary.load32bitNumberList(dumped, 0);
+ this.expect(loaded.result.length).toBe(6);
+ this.expect(loaded.result[0]).toBe(1);
+ this.expect(loaded.result[1]).toBe(0);
+ this.expect(loaded.result[2]).toBe(1);
+ this.expect(loaded.result[3]).toBe(0);
+ this.expect(loaded.result[4]).toBe(1);
+ this.expect(loaded.result[5]).toBe(0);
+ this.expect(loaded.offset).toBe(2 * 3 + 2 + 1);
+ }
+
+ function test_32bit_number_list_combo1() : void
+ {
+ // non-blank + blank
+ var list = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0];
+ var dumped = Binary.dump32bitNumberList(list);
+ this.expect(dumped.length).toBe(2 + 1 + 2 * 17 + 1);
+ var loaded = Binary.load32bitNumberList(dumped, 0);
+ this.expect(loaded.result.length).toBe(list.length);
+ this.expect(loaded.result[0]).toBe(1);
+ this.expect(loaded.result[15]).toBe(1);
+ this.expect(loaded.result[17]).toBe(0);
+ this.expect(loaded.result[19]).toBe(0);
+ this.expect(loaded.offset).toBe(2 + 1 + 2 * 17 + 1);
+ }
+
+ function test_32bit_number_list_combo2() : void
+ {
+ // blank + non-blank
+ var list = [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
+ var dumped = Binary.dump32bitNumberList(list);
+ this.expect(dumped.length).toBe(2 + 1 + 1 + 2 * 17);
+ var loaded = Binary.load32bitNumberList(dumped, 0);
+ this.expect(loaded.result.length).toBe(list.length);
+ this.expect(loaded.result[0]).toBe(0);
+ this.expect(loaded.result[2]).toBe(0);
+ this.expect(loaded.result[3]).toBe(1);
+ this.expect(loaded.result[19]).toBe(1);
+ this.expect(loaded.offset).toBe(2 + 1 + 1 + 2 * 17);
+ }
+
+ function test_32bit_number_list_combo3() : void
+ {
+ // non-blank + zebra
+ var list = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0];
+ var dumped = Binary.dump32bitNumberList(list);
+ this.expect(dumped.length).toBe(2 + 1 + 2 * 16 + 1 + 1 + 2 * 3);
+ var loaded = Binary.load32bitNumberList(dumped, 0);
+ this.expect(loaded.result.length).toBe(list.length);
+ this.expect(loaded.result[0]).toBe(1);
+ this.expect(loaded.result[9]).toBe(1);
+ this.expect(loaded.result[16]).toBe(0);
+ this.expect(loaded.result[18]).toBe(1);
+ this.expect(loaded.offset).toBe(2 + 1 + 2 * 16 + 1 + 1 + 2 * 3);
+ }
+
+ function test_32bit_number_list_combo4() : void
+ {
+ // zebra + non-block
+ var list = [1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2];
+ var dumped = Binary.dump32bitNumberList(list);
+ this.expect(dumped.length).toBe(2 + 1 + 2 * 11 + 1 + 2 * 16);
+ var loaded = Binary.load32bitNumberList(dumped, 0);
+ this.expect(loaded.result.length).toBe(list.length);
+ this.expect(loaded.result[0]).toBe(1);
+ this.expect(loaded.result[14]).toBe(0);
+ this.expect(loaded.result[15]).toBe(1);
+ this.expect(loaded.result[30]).toBe(2);
+ this.expect(loaded.offset).toBe(2 + 1 + 2 * 11 + 1 + 2 * 16);
+ }
+
+ function test_32bit_number_list_combo5() : void
+ {
+ // zero + zebra
+ var list = [0, 0, 0, 0, 0, 0, 1];
+ var dumped = Binary.dump32bitNumberList(list);
+ this.expect(dumped.length).toBe(2 + 1 + 1 + 2);
+ var loaded = Binary.load32bitNumberList(dumped, 0);
+ this.expect(loaded.result.length).toBe(7);
+ this.expect(loaded.result[0]).toBe(0);
+ this.expect(loaded.result[6]).toBe(1);
+ this.expect(loaded.offset).toBe(2 + 1 + 1 + 2);
+ }
+
+ function test_32bit_number_list_combo6() : void
+ {
+ // zebra + zero
+ var list = [1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0];
+ var dumped = Binary.dump32bitNumberList(list);
+ this.expect(dumped.length).toBe(2 + 1 + 2 * 12 + 1);
+ var loaded = Binary.load32bitNumberList(dumped, 0);
+ this.expect(loaded.result.length).toBe(list.length);
+ this.expect(loaded.result[0]).toBe(1);
+ this.expect(loaded.result[14]).toBe(1);
+ this.expect(loaded.result[15]).toBe(0);
+ this.expect(loaded.result[23]).toBe(0);
+ this.expect(loaded.offset).toBe(2 + 1 + 2 * 12 + 1);
+ }
+
+ function test_base64_encode_decode() : void
+ {
+ var allChars = [] : string[];
+ for (var i = 256; i < 65536; i++)
+ {
+ allChars.push(String.fromCharCode(i));
+ }
+ var allCharSource = allChars.join('');
+ this.expect(Binary.base64decode(Binary.base64encode(allCharSource))).toBe(allCharSource);
+ }
+}
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-bit-vector.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-bit-vector.jsx
new file mode 100644
index 000000000..18f80b645
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-bit-vector.jsx
@@ -0,0 +1,131 @@
+import "test-case.jsx";
+import "bit-vector.jsx";
+import "console.jsx";
+
+class _Test extends TestCase
+{
+ var src_values : int[];
+ var bv0 : BitVector;
+ var bv1 : BitVector;
+
+ override function setUp () : void
+ {
+ this.bv0 = new BitVector();
+ this.bv1 = new BitVector();
+
+ this.src_values = [0, 511, 512, 1000, 2000, 3000] : int[];
+
+ for (var i = 0; i <= this.src_values[this.src_values.length - 1]; i++)
+ {
+ this.bv0.set(i, true);
+ }
+
+ for (var i = 0; i < this.src_values.length; i++)
+ {
+ var v = this.src_values[i];
+ this.bv1.set(v, true);
+ this.bv0.set(v, false);
+ }
+ this.bv1.build();
+ this.bv0.build();
+ }
+
+ function test_size () : void
+ {
+ this.expect(this.bv1.size()).toBe(this.src_values[this.src_values.length - 1] + 1); // == 3001
+ this.expect(this.bv1.size(true)).toBe(this.src_values.length); // == 6
+ this.expect(this.bv0.size()).toBe(this.src_values[this.src_values.length - 1] + 1); // == 3001
+ this.expect(this.bv0.size(false)).toBe(this.src_values.length); // == 6
+ }
+
+ function test_get () : void
+ {
+ for (var i = 0; i < this.src_values.length; i++)
+ {
+ var v = this.src_values[i];
+ this.expect(this.bv1.get(v)).toBe(true);
+ this.expect(this.bv0.get(v)).toBe(false);
+ }
+ }
+
+ function test_rank () : void
+ {
+ for (var i = 0; i < this.src_values.length; i++)
+ {
+ var v = this.src_values[i];
+ this.expect(this.bv1.rank(v, true)).toBe(i);
+ this.expect(this.bv0.rank(v, false)).toBe(i);
+ }
+ }
+
+ function test_select () : void
+ {
+ for (var i = 0; i < this.src_values.length; i++)
+ {
+ var v = this.src_values[i];
+ this.expect(this.bv1.select(i, true)).toBe(v);
+ this.expect(this.bv0.select(i, false)).toBe(v);
+ }
+ }
+
+ function test_load_dump_and_size () : void
+ {
+ console.log('dump1');
+ var dump1 = this.bv1.dump();
+ console.log('dump0');
+ var dump0 = this.bv0.dump();
+ console.log('load1');
+ this.bv1.load(dump1);
+ console.log('load0');
+ this.bv0.load(dump0);
+
+ this.expect(this.bv1.size()).toBe(this.src_values[this.src_values.length - 1] + 1); // == 3001
+ this.expect(this.bv1.size(true)).toBe(this.src_values.length); // == 6
+ this.expect(this.bv0.size()).toBe(this.src_values[this.src_values.length - 1] + 1); // == 3001
+ this.expect(this.bv0.size(false)).toBe(this.src_values.length); // == 6
+ }
+
+ function test_load_dump_and_get () : void
+ {
+ var dump1 = this.bv1.dump();
+ var dump0 = this.bv0.dump();
+ this.bv1.load(dump1);
+ this.bv0.load(dump0);
+
+ for (var i = 0; i < this.src_values.length; i++)
+ {
+ var v = this.src_values[i];
+ this.expect(this.bv1.get(v)).toBe(true);
+ this.expect(this.bv0.get(v)).toBe(false);
+ }
+ }
+
+ function test_load_dump_and_rank () : void
+ {
+ var dump1 = this.bv1.dump();
+ var dump0 = this.bv0.dump();
+ this.bv1.load(dump1);
+ this.bv0.load(dump0);
+
+ for (var i = 0; i < this.src_values.length; i++)
+ {
+ var v = this.src_values[i];
+ this.expect(this.bv1.rank(v, true)).toBe(i);
+ this.expect(this.bv0.rank(v, false)).toBe(i);
+ }
+ }
+
+ function test_load_dump_and_select () : void
+ {
+ var dump1 = this.bv1.dump();
+ var dump0 = this.bv0.dump();
+ this.bv1.load(dump1);
+ this.bv0.load(dump0);
+ for (var i = 0; i < this.src_values.length; i++)
+ {
+ var v = this.src_values[i];
+ this.expect(this.bv1.select(i, true)).toBe(v);
+ this.expect(this.bv0.select(i, false)).toBe(v);
+ }
+ }
+}
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-burrows-wheeler-transform.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-burrows-wheeler-transform.jsx
new file mode 100644
index 000000000..6a033e589
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-burrows-wheeler-transform.jsx
@@ -0,0 +1,24 @@
+/**
+ * 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 "burrows-wheeler-transform.jsx";
+
+class _Test extends TestCase
+{
+ var bwt : BurrowsWheelerTransform;
+ override function setUp() : void
+ {
+ this.bwt = new BurrowsWheelerTransform();
+ this.bwt.build('abracadabra' + BurrowsWheelerTransform.END_MARKER);
+ }
+
+ function test_get() : void
+ {
+ this.expect(this.bwt.get("$")).toBe("ard$rcaaaabb");
+ }
+}
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-fm-index.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-fm-index.jsx
new file mode 100644
index 000000000..80035a61f
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-fm-index.jsx
@@ -0,0 +1,250 @@
+/**
+ * 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 "fm-index.jsx";
+
+class Pair
+{
+ var first : string;
+ var second : int;
+ function constructor (_first : string, _second : int)
+ {
+ this.first = _first;
+ this.second = _second;
+ }
+}
+
+class _Test extends TestCase
+{
+ var str : string;
+ var rd : Map.<int>;
+ var pd : int[];
+ var sd : string[];
+ var didd : int[];
+ var docd : string[];
+ var fm : FMIndex;
+ var end_marker : string;
+
+ override function setUp () : void
+ {
+ this.str = "";
+ this.sd = [] : string[];
+ this.rd = {} : Map.<int>;
+ this.pd = [] : int[];
+ this.didd = [] : int[];
+ this.docd = [] : string[];
+ this.fm = new FMIndex();
+ this.end_marker = String.fromCharCode(1);
+
+ this.docd.push("abracadabra");
+ this.docd.push("mississippi");
+ this.docd.push("abracadabra mississippi");
+
+ var did = 0;
+ for (var i in this.docd)
+ {
+ var doc = this.docd[i];
+ this.str += doc;
+ for (var j = 0; j < doc.length; j++){
+ this.didd.push(did);
+ }
+ this.fm.push(doc);
+ did++;
+ }
+
+ this.didd.push(did);
+ this.str += this.end_marker;
+ this.fm.build(this.end_marker, 3, false);
+
+ for (var i = 0; i < this.str.length; i++)
+ {
+ for (var j = 1; j <= (this.str.length - i); j++)
+ {
+ var s = this.str.slice(i, i + j);
+ if (this.rd[s] == null)
+ {
+ this.rd[s] = 1;
+ }
+ else
+ {
+ this.rd[s]++;
+ }
+ }
+ }
+
+ var v = [] : Pair[];
+ for (var i = 0; i < this.str.length; i++)
+ {
+ var s = this.str.slice(i) + this.str.slice(0, i);
+ v.push(new Pair(s, i));
+ }
+ v.sort(function (a: Pair, b: Pair) : number {
+ if (a.first < b.first)
+ {
+ return -1;
+ }
+ else if (a.first > b.first)
+ {
+ return 1;
+ }
+ return a.second - b.second;
+ });
+ for (var i in v)
+ {
+ this.pd.push(v[i].second);
+ }
+ for (var i = 0; i < this.str.length; i++)
+ {
+ this.sd.push(this.str.slice(i));
+ }
+ }
+
+ function test_size () : void
+ {
+ this.expect(this.fm.size()).toBe(this.str.length);
+ }
+
+ function test_getRows () : void
+ {
+ for (var i = 0; i < this.fm.size(); i++)
+ {
+ for (var j = i + 1; j < this.fm.size(); j++)
+ {
+ var s = this.str.slice(i, j);
+ this.expect(this.fm.getRows(s)).toBe(this.rd[s]);
+ }
+ }
+ }
+
+ function test_getPosition () : void
+ {
+ for (var i = 0; i < this.fm.size(); i++)
+ {
+ this.expect(this.fm.getPosition(i)).toBe(this.pd[i]);
+ }
+ }
+
+ function test_getSubstring () : void
+ {
+ for (var i = 0; i < this.fm.size(); i++)
+ {
+ this.expect(this.fm.getSubstring(i, this.fm.size())).toBe(this.sd[i]);
+ }
+ }
+
+ function test_getSubstring2 () : void
+ {
+ this.fm = new FMIndex();
+ this.fm.push("abracadabra");
+ this.fm.push("mississippi");
+ this.fm.push("abracadabra mississippi");
+ this.fm.build(this.end_marker, 3, false);
+ this.expect(this.fm.getSubstring(0, 11)).toBe('abracadabra');
+ this.expect(this.fm.getSubstring(11, 11)).toBe('mississippi');
+ this.expect(this.fm.getSubstring(22, 23)).toBe('abracadabra mississippi');
+ }
+
+ function test_getPosition_boundary () : void
+ {
+ try
+ {
+ this.fm.getPosition(this.fm.size());
+ this.fail("fm.getPosition()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+
+ function test_getSubstring_boundary () : void
+ {
+ try
+ {
+ this.fm.getSubstring(this.fm.size(), 0);
+ this.fail("fm.getSubstring()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+
+ function test_dump_load_and_size () : void
+ {
+ var dump = this.fm.dump();
+ this.fm.load(dump);
+
+ this.expect(this.fm.size()).toBe(this.str.length);
+ }
+
+ function test_dump_load_and_getRows () : void
+ {
+ var dump = this.fm.dump();
+ this.fm.load(dump);
+
+ for (var i = 0; i < this.fm.size(); i++)
+ {
+ for (var j = i + 1; j < this.fm.size(); j++)
+ {
+ var s = this.str.slice(i, j);
+ this.expect(this.fm.getRows(s)).toBe(this.rd[s]);
+ }
+ }
+ }
+
+ function test_dump_load_and_getPosition () : void
+ {
+ var dump = this.fm.dump();
+ this.fm.load(dump);
+
+ for (var i = 0; i < this.fm.size(); i++)
+ {
+ this.expect(this.fm.getPosition(i)).toBe(this.pd[i]);
+ }
+ }
+
+ function test_dump_load_and_getSubstring () : void
+ {
+ var dump = this.fm.dump();
+ this.fm.load(dump);
+
+ for (var i = 0; i < this.fm.size(); i++)
+ {
+ this.expect(this.fm.getSubstring(i, this.fm.size())).toBe(this.sd[i]);
+ }
+ }
+
+ function test_dump_load_and_getPosition_boundary () : void
+ {
+ var dump = this.fm.dump();
+ this.fm.load(dump);
+
+ try
+ {
+ this.fm.getPosition(this.fm.size());
+ this.fail("fm.getPosition()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+
+ function test_dump_load_and_getSubstring_boundary () : void
+ {
+ var dump = this.fm.dump();
+ this.fm.load(dump);
+
+ try
+ {
+ this.fm.getSubstring(this.fm.size(), 0);
+ this.fail("fm.getSubstring()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+}
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-getopt.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-getopt.jsx
new file mode 100644
index 000000000..63731b924
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-getopt.jsx
@@ -0,0 +1,84 @@
+import "test-case.jsx";
+import "getopt.jsx";
+
+class _Test extends TestCase
+{
+ function test_empty () : void
+ {
+ var parser = new BasicParser('', [] : string[]);
+ this.expect(parser.getopt()).toBe(null);
+ }
+
+ function test_silent () : void
+ {
+ var parser = new BasicParser(':', [] : string[]);
+ this.expect(parser.getopt()).toBe(null);
+ }
+
+ function test_args_without_param_01 () : void
+ {
+ var parser = new BasicParser(':l', [] : string[]);
+ this.expect(parser.getopt()).toBe(null);
+ }
+
+ function test_args_without_param_02 () : void
+ {
+ var parser = new BasicParser(':l:', [] : string[]);
+ this.expect(parser.getopt()).toBe(null);
+ }
+
+ function test_args_without_param_03 () : void
+ {
+ var parser = new BasicParser(':las', [] : string[]);
+ this.expect(parser.getopt()).toBe(null);
+ }
+
+ function test_args_without_param_04 () : void
+ {
+ var parser = new BasicParser(':l:a:s:', [] : string[]);
+ this.expect(parser.getopt()).toBe(null);
+ }
+
+ function test_long_args_without_param () : void
+ {
+ var parser = new BasicParser(':l:(long)', [] : string[]);
+ this.expect(parser.getopt()).toBe(null);
+ }
+
+ function test_args () : void
+ {
+ var parser = new BasicParser(':l:(long)', ['-l', 'arg1', '--long=q', 'b', '--long', 'foo']);
+ var opt = parser.getopt();
+ this.expect(opt.option).toBe('l');
+ this.expect(opt.optarg).toBe('arg1');
+ opt = parser.getopt();
+ this.expect(opt.option).toBe('l');
+ this.expect(opt.optarg).toBe('q');
+ opt = parser.getopt();
+ this.expect(opt.option).toBe('b');
+ opt = parser.getopt();
+ this.expect(opt.option).toBe('--long');
+ opt = parser.getopt();
+ this.expect(opt.option).toBe('foo');
+ }
+
+ function test_aliased_long_args_without_param_01 () : void
+ {
+ var parser = new BasicParser(':l:(long)(longer)', [] : string[]);
+ this.expect(parser.getopt()).toBe(null);
+ }
+
+ function test_aliased_long_args_without_param_02 () : void
+ {
+ var parser = new BasicParser(':la:r(recurse)(recur)f:(file)(filename)q', [] : string[]);
+ this.expect(parser.getopt()).toBe(null);
+ }
+
+ function test_extra_options () : void
+ {
+ var parser = new BasicParser('la:r(recurse)(recur)f:(file)(filename)q', ['extra1', 'extra2']);
+ this.expect(parser.getopt().option).toBe('extra1');
+ this.expect(parser.getopt().option).toBe('extra2');
+ this.expect(parser.getopt()).toBe(null);
+ }
+}
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-block.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-block.jsx
new file mode 100644
index 000000000..f5f562c7d
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-block.jsx
@@ -0,0 +1,226 @@
+/**
+ * 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 block : Block;
+
+ override function setUp () : void
+ {
+ this.oktavia = new Oktavia();
+ this.block = this.oktavia.addBlock('document');
+ this.oktavia.addWord("abracadabra");
+ this.block.startBlock("river");
+ this.oktavia.addWord("mississippi");
+ this.block.endBlock();
+ this.oktavia.addWord("abracadabra mississippi");
+ this.oktavia.build();
+ }
+
+ function test_doc_sizes () : void
+ {
+ this.expect(this.block.size()).toBe(1);
+ }
+
+ function test_in_block () : void
+ {
+ this.expect(this.block.inBlock(0)).toBe(false);
+ this.expect(this.block.inBlock(10)).toBe(false);
+ this.expect(this.block.inBlock(11)).toBe(true);
+ this.expect(this.block.inBlock(21)).toBe(true);
+ this.expect(this.block.inBlock(22)).toBe(false);
+ this.expect(this.block.inBlock(44)).toBe(false);
+ }
+
+ function test_in_block_boundary () : void
+ {
+ try
+ {
+ this.block.inBlock(-1);
+ this.fail("fm.inBlock() 1");
+ }
+ catch (e : Error)
+ {
+ }
+ try
+ {
+ this.block.inBlock(45);
+ this.fail("fm.inBlock() 2");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+
+ function test_get_block_content () : void
+ {
+ this.expect(this.block.getBlockContent(11)).toBe("mississippi");
+ }
+
+ function test_get_block_content_boundary () : void
+ {
+ try
+ {
+ this.block.getBlockContent(45);
+ this.fail("fm.getContent()");
+ }
+ catch (e : Error)
+ {
+ }
+ try
+ {
+ this.block.getBlockContent(-1);
+ this.fail("fm.getContent()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+
+ function test_get_block_name () : void
+ {
+ this.expect(this.block.getBlockName(11)).toBe("river");
+ }
+
+ function test_get_block_name_boundary () : void
+ {
+ try
+ {
+ this.block.getBlockName(45);
+ this.fail("fm.getName()");
+ }
+ catch (e : Error)
+ {
+ }
+ try
+ {
+ this.block.getBlockName(-1);
+ this.fail("fm.getName()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+
+ function test_dump_load_and_doc_sizes () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.block = this.oktavia.getBlock('document');
+
+ this.expect(this.block.size()).toBe(1);
+ }
+
+ function test_load_dump_and_in_block () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.block = this.oktavia.getBlock('document');
+
+ this.expect(this.block.inBlock(0)).toBe(false);
+ this.expect(this.block.inBlock(10)).toBe(false);
+ this.expect(this.block.inBlock(11)).toBe(true);
+ this.expect(this.block.inBlock(21)).toBe(true);
+ this.expect(this.block.inBlock(22)).toBe(false);
+ this.expect(this.block.inBlock(44)).toBe(false);
+ }
+
+ function test_load_dump_and_in_block_boundary () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.block = this.oktavia.getBlock('document');
+
+ try
+ {
+ this.block.inBlock(-1);
+ this.fail("fm.inBlock() 1");
+ }
+ catch (e : Error)
+ {
+ }
+ try
+ {
+ this.block.inBlock(45);
+ this.fail("fm.inBlock() 2");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+
+ function test_load_dump_and_get_block_content () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.block = this.oktavia.getBlock('document');
+
+ this.expect(this.block.getBlockContent(11)).toBe("mississippi");
+ }
+
+ function test_load_dump_and_get_block_content_boundary () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.block = this.oktavia.getBlock('document');
+
+ try
+ {
+ this.block.getBlockContent(45);
+ this.fail("fm.getContent()");
+ }
+ catch (e : Error)
+ {
+ }
+ try
+ {
+ this.block.getBlockContent(-1);
+ this.fail("fm.getContent()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+
+ function test_load_dump_and_get_block_name () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.block = this.oktavia.getBlock('document');
+
+ this.expect(this.block.getBlockName(11)).toBe("river");
+ }
+
+ function test_load_dump_and_get_block_name_boundary () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.block = this.oktavia.getBlock('document');
+
+ try
+ {
+ this.block.getBlockName(45);
+ this.fail("fm.getName()");
+ }
+ catch (e : Error)
+ {
+ }
+ try
+ {
+ this.block.getBlockName(-1);
+ this.fail("fm.getName()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+}
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-section.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-section.jsx
new file mode 100644
index 000000000..0c37afeaa
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-section.jsx
@@ -0,0 +1,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)
+ {
+ }
+ }
+}
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-splitter.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-splitter.jsx
new file mode 100644
index 000000000..859eb9112
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-splitter.jsx
@@ -0,0 +1,173 @@
+/**
+ * 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 splitter : Splitter;
+
+ override function setUp () : void
+ {
+ this.oktavia = new Oktavia();
+ this.splitter = this.oktavia.addSplitter('document');
+ this.oktavia.addWord("abracadabra");
+ this.splitter.split();
+ this.oktavia.addWord("mississippi");
+ this.splitter.split();
+ this.oktavia.addWord("abracadabra mississippi");
+ this.splitter.split();
+ this.oktavia.build(25, false);
+ }
+
+ function test_count () : void
+ {
+ this.expect(this.splitter.size()).toBe(3);
+ }
+
+ function test_get_splitter_index () : void
+ {
+ this.expect(this.splitter.getIndex(0)).toBe(0);
+ this.expect(this.splitter.getIndex(10)).toBe(0);
+ this.expect(this.splitter.getIndex(11)).toBe(1);
+ this.expect(this.splitter.getIndex(21)).toBe(1);
+ this.expect(this.splitter.getIndex(22)).toBe(2);
+ this.expect(this.splitter.getIndex(44)).toBe(2);
+ }
+
+ function test_get_splitter_index_boundary () : void
+ {
+ try
+ {
+ this.splitter.getIndex(-1);
+ this.fail("fm.getIndex()");
+ }
+ catch (e : Error)
+ {
+ }
+ try
+ {
+ this.splitter.getIndex(45);
+ this.fail("fm.getIndex()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+
+ function test_get_splitter_content () : void
+ {
+ this.expect(this.splitter.getContent(2)).toBe("abracadabra mississippi");
+ this.expect(this.splitter.getContent(1)).toBe("mississippi");
+ this.expect(this.splitter.getContent(0)).toBe("abracadabra");
+ }
+
+ function test_get_splitter_content_boundary () : void
+ {
+ try
+ {
+ this.splitter.getContent(3);
+ this.fail("fm.getContent()");
+ }
+ catch (e : Error)
+ {
+ }
+ try
+ {
+ this.splitter.getContent(-1);
+ this.fail("fm.getContent()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+
+ function test_load_dump_and_count () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.splitter = this.oktavia.getSplitter('document');
+
+ this.expect(this.splitter.size()).toBe(3);
+ }
+
+ function test_load_dump_and_get_splitter_index () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.splitter = this.oktavia.getSplitter('document');
+
+ this.expect(this.splitter.getIndex(0)).toBe(0);
+ this.expect(this.splitter.getIndex(10)).toBe(0);
+ this.expect(this.splitter.getIndex(11)).toBe(1);
+ this.expect(this.splitter.getIndex(21)).toBe(1);
+ this.expect(this.splitter.getIndex(22)).toBe(2);
+ this.expect(this.splitter.getIndex(44)).toBe(2);
+ }
+
+ function test_load_dump_and_get_splitter_index_boundary () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.splitter = this.oktavia.getSplitter('document');
+
+ try
+ {
+ this.splitter.getIndex(-1);
+ this.fail("fm.getIndex()");
+ }
+ catch (e : Error)
+ {
+ }
+ try
+ {
+ this.splitter.getIndex(45);
+ this.fail("fm.getIndex()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+
+ function test_load_dump_and_get_splitter_content () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.splitter = this.oktavia.getSplitter('document');
+
+ this.expect(this.splitter.getContent(2)).toBe("abracadabra mississippi");
+ this.expect(this.splitter.getContent(1)).toBe("mississippi");
+ this.expect(this.splitter.getContent(0)).toBe("abracadabra");
+ }
+
+ function test_load_dump_and_get_splitter_content_boundary () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.splitter = this.oktavia.getSplitter('document');
+
+ try
+ {
+ this.splitter.getContent(3);
+ this.fail("fm.getContent()");
+ }
+ catch (e : Error)
+ {
+ }
+ try
+ {
+ this.splitter.getContent(-1);
+ this.fail("fm.getContent()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+}
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-stemming.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-stemming.jsx
new file mode 100644
index 000000000..d8d1d74eb
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-stemming.jsx
@@ -0,0 +1,55 @@
+import "test-case.jsx";
+import "oktavia.jsx";
+import "metadata.jsx";
+import "stemmer/english-stemmer.jsx";
+import "console.jsx";
+
+class _Test extends TestCase
+{
+ var oktavia : Oktavia;
+ var section : Section;
+
+ override function setUp () : void
+ {
+ this.oktavia = new Oktavia();
+ this.oktavia.setStemmer(new EnglishStemmer());
+ this.section = this.oktavia.addSection('document');
+ this.oktavia.addWord("stemming baby", true);
+ this.section.setTail("doc1");
+ this.oktavia.addWord("stemmed babies", true);
+ this.section.setTail("doc2");
+ this.oktavia.build();
+ }
+
+ function test_search_without_stemming () : void
+ {
+ var results = this.oktavia.rawSearch('baby', false);
+ this.expect(results.length).toBe(1);
+ }
+
+ function test_search_with_stemming () : void
+ {
+ var results = this.oktavia.rawSearch('baby', true);
+ this.expect(results.length).toBe(1);
+ }
+
+ function test_load_dump_and_search_without_stemming () : void
+ {
+ var dump = this.oktavia.dump();
+ var oktavia = new Oktavia();
+ oktavia.setStemmer(new EnglishStemmer());
+ oktavia.load(dump);
+ var results = oktavia.rawSearch('baby', false);
+ this.expect(results.length).toBe(1);
+ }
+
+ function test_load_dump_and_search_with_stemming () : void
+ {
+ var dump = this.oktavia.dump();
+ var oktavia = new Oktavia();
+ oktavia.setStemmer(new EnglishStemmer());
+ oktavia.load(dump);
+ var results = oktavia.rawSearch('baby', true);
+ this.expect(results.length).toBe(1);
+ }
+}
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-table.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-table.jsx
new file mode 100644
index 000000000..ee2aa0975
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-oktavia-table.jsx
@@ -0,0 +1,213 @@
+import "test-case.jsx";
+import "oktavia.jsx";
+import "metadata.jsx";
+
+class _Test extends TestCase
+{
+ var oktavia : Oktavia;
+ var table : Table;
+
+ override function setUp () : void
+ {
+ this.oktavia = new Oktavia();
+ this.table = this.oktavia.addTable('address book', ['zip', 'city', 'area code']);
+
+ this.oktavia.addWord("94101"); // 5
+ this.table.setColumnTail();
+ this.oktavia.addWord("San Francisco"); // 13
+ this.table.setColumnTail();
+ this.oktavia.addWord("415"); // 3
+ this.table.setColumnTail();
+ this.table.setRowTail();
+
+ this.oktavia.addWord("94607"); // 5
+ this.table.setColumnTail();
+ this.oktavia.addWord("Oakland"); // 7
+ this.table.setColumnTail();
+ this.oktavia.addWord("510"); // 3
+ this.table.setColumnTail();
+ this.table.setRowTail();
+
+ this.oktavia.addWord("94401"); // 5
+ this.table.setColumnTail();
+ this.oktavia.addWord("San Mateo"); // 9
+ this.table.setColumnTail();
+ this.oktavia.addWord("650"); // 3
+ this.table.setColumnTail();
+ this.table.setRowTail();
+
+ this.oktavia.build();
+ }
+
+ function test_row_sizes () : void
+ {
+ this.expect(this.table.rowSize()).toBe(3);
+ }
+
+ function test_column_sizes () : void
+ {
+ this.expect(this.table.columnSize()).toBe(3);
+ }
+
+ function test_get_cell () : void
+ {
+ this.expect(this.table.getCell(0)[0]).toBe(0);
+ this.expect(this.table.getCell(0)[1]).toBe(0);
+ this.expect(this.table.getCell(22)[0]).toBe(0);
+ this.expect(this.table.getCell(22)[1]).toBe(2);
+ this.expect(this.table.getCell(24)[0]).toBe(1);
+ this.expect(this.table.getCell(24)[1]).toBe(0);
+ this.expect(this.table.getCell(40)[0]).toBe(1);
+ this.expect(this.table.getCell(40)[1]).toBe(2);
+ this.expect(this.table.getCell(42)[0]).toBe(2);
+ this.expect(this.table.getCell(42)[1]).toBe(0);
+ this.expect(this.table.getCell(60)[0]).toBe(2);
+ this.expect(this.table.getCell(60)[1]).toBe(2);
+ }
+
+ function test_get_table_index_boundary () : void
+ {
+ try
+ {
+ this.table.getCell(-1);
+ this.fail("fm.gettableIndex()");
+ }
+ catch (e : Error)
+ {
+ }
+ try
+ {
+ this.table.getCell(62);
+ this.fail("fm.gettableIndex()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+
+ function test_get_table_content () : void
+ {
+ var row = this.table.getRowContent(0);
+ this.expect(row['zip']).toBe('94101');
+ this.expect(row['city']).toBe('San Francisco');
+ this.expect(row['area code']).toBe('415');
+ }
+
+ function test_get_table_content_boundary () : void
+ {
+ try
+ {
+ this.table.getContent(3);
+ this.fail("fm.getContent()");
+ }
+ catch (e : Error)
+ {
+ }
+ try
+ {
+ this.table.getContent(-1);
+ this.fail("fm.getContent()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+
+ function test_load_dump_and_row_sizes () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.table = this.oktavia.getTable('address book');
+
+ this.expect(this.table.rowSize()).toBe(3);
+ }
+
+ function test_load_dump_and_column_sizes () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.table = this.oktavia.getTable('address book');
+
+ this.expect(this.table.columnSize()).toBe(3);
+ }
+
+ function test_load_dump_and_get_cell () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.table = this.oktavia.getTable('address book');
+
+ this.expect(this.table.getCell(0)[0]).toBe(0);
+ this.expect(this.table.getCell(0)[1]).toBe(0);
+ this.expect(this.table.getCell(22)[0]).toBe(0);
+ this.expect(this.table.getCell(22)[1]).toBe(2);
+ this.expect(this.table.getCell(24)[0]).toBe(1);
+ this.expect(this.table.getCell(24)[1]).toBe(0);
+ this.expect(this.table.getCell(40)[0]).toBe(1);
+ this.expect(this.table.getCell(40)[1]).toBe(2);
+ this.expect(this.table.getCell(42)[0]).toBe(2);
+ this.expect(this.table.getCell(42)[1]).toBe(0);
+ this.expect(this.table.getCell(60)[0]).toBe(2);
+ this.expect(this.table.getCell(60)[1]).toBe(2);
+ }
+
+ function test_load_dump_and_get_table_index_boundary () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.table = this.oktavia.getTable('address book');
+
+ try
+ {
+ this.table.getCell(-1);
+ this.fail("fm.gettableIndex()");
+ }
+ catch (e : Error)
+ {
+ }
+ try
+ {
+ this.table.getCell(62);
+ this.fail("fm.gettableIndex()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+
+ function test_load_dump_and_get_table_content () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.table = this.oktavia.getTable('address book');
+
+ var row = this.table.getRowContent(0);
+ this.expect(row['zip']).toBe('94101');
+ this.expect(row['city']).toBe('San Francisco');
+ this.expect(row['area code']).toBe('415');
+ }
+
+ function test_load_dump_and_get_table_content_boundary () : void
+ {
+ var dump = this.oktavia.dump();
+ this.oktavia.load(dump);
+ this.table = this.oktavia.getTable('address book');
+
+ try
+ {
+ this.table.getContent(3);
+ this.fail("fm.getContent()");
+ }
+ catch (e : Error)
+ {
+ }
+ try
+ {
+ this.table.getContent(-1);
+ this.fail("fm.getContent()");
+ }
+ catch (e : Error)
+ {
+ }
+ }
+}
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-query-parser.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-query-parser.jsx
new file mode 100644
index 000000000..c04ac46e4
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-query-parser.jsx
@@ -0,0 +1,92 @@
+import "test-case.jsx";
+import "query-parser.jsx";
+
+class _Test extends TestCase
+{
+ var parser : QueryParser;
+
+ override function setUp () : void
+ {
+ this.parser = new QueryParser();
+ }
+
+ function test_and () : void
+ {
+ this.parser.parse(['word1', 'word2']);
+ this.expect(this.parser.queries.length).toBe(2);
+
+ this.expect(this.parser.queries[0].word).toBe('word1');
+ this.expect(this.parser.queries[0].or).toBe(false);
+ this.expect(this.parser.queries[0].not).toBe(false);
+ this.expect(this.parser.queries[0].raw).toBe(false);
+
+ this.expect(this.parser.queries[1].word).toBe('word2');
+ this.expect(this.parser.queries[1].or).toBe(false);
+ this.expect(this.parser.queries[1].not).toBe(false);
+ this.expect(this.parser.queries[1].raw).toBe(false);
+ }
+
+ function test_or () : void
+ {
+ this.parser.parse(['word1', 'OR', 'word2']);
+ this.expect(this.parser.queries.length).toBe(2);
+
+ this.expect(this.parser.queries[0].word).toBe('word1');
+ this.expect(this.parser.queries[0].or).toBe(false);
+ this.expect(this.parser.queries[0].not).toBe(false);
+ this.expect(this.parser.queries[0].raw).toBe(false);
+
+ this.expect(this.parser.queries[1].word).toBe('word2');
+ this.expect(this.parser.queries[1].or).toBe(true);
+ this.expect(this.parser.queries[1].not).toBe(false);
+ this.expect(this.parser.queries[1].raw).toBe(false);
+ }
+
+ function test_not () : void
+ {
+ this.parser.parse(['word1', '-word2']);
+ this.expect(this.parser.queries.length).toBe(2);
+
+ this.expect(this.parser.queries[0].word).toBe('word1');
+ this.expect(this.parser.queries[0].or).toBe(false);
+ this.expect(this.parser.queries[0].not).toBe(false);
+ this.expect(this.parser.queries[0].raw).toBe(false);
+
+ this.expect(this.parser.queries[1].word).toBe('word2');
+ this.expect(this.parser.queries[1].or).toBe(false);
+ this.expect(this.parser.queries[1].not).toBe(true);
+ this.expect(this.parser.queries[1].raw).toBe(false);
+ }
+
+ function test_raw () : void
+ {
+ this.parser.parse(['word1', '"word2"']);
+ this.expect(this.parser.queries.length).toBe(2);
+
+ this.expect(this.parser.queries[0].word).toBe('word1');
+ this.expect(this.parser.queries[0].or).toBe(false);
+ this.expect(this.parser.queries[0].not).toBe(false);
+ this.expect(this.parser.queries[0].raw).toBe(false);
+
+ this.expect(this.parser.queries[1].word).toBe('word2');
+ this.expect(this.parser.queries[1].or).toBe(false);
+ this.expect(this.parser.queries[1].not).toBe(false);
+ this.expect(this.parser.queries[1].raw).toBe(true);
+ }
+
+ function test_raw_not () : void
+ {
+ this.parser.parse(['word1', '-"word2"']);
+ this.expect(this.parser.queries.length).toBe(2);
+
+ this.expect(this.parser.queries[0].word).toBe('word1');
+ this.expect(this.parser.queries[0].or).toBe(false);
+ this.expect(this.parser.queries[0].not).toBe(false);
+ this.expect(this.parser.queries[0].raw).toBe(false);
+
+ this.expect(this.parser.queries[1].word).toBe('word2');
+ this.expect(this.parser.queries[1].or).toBe(false);
+ this.expect(this.parser.queries[1].not).toBe(true);
+ this.expect(this.parser.queries[1].raw).toBe(true);
+ }
+}
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-query-string-parser.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-query-string-parser.jsx
new file mode 100644
index 000000000..94ec7c193
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-query-string-parser.jsx
@@ -0,0 +1,94 @@
+import "test-case.jsx";
+import "query-string-parser.jsx";
+
+class _Test extends TestCase
+{
+ var parser : QueryStringParser;
+
+ override function setUp () : void
+ {
+ this.parser = new QueryStringParser();
+ }
+
+ function test_single_string_and () : void
+ {
+ this.parser.parse('word1 word2');
+ this.expect(this.parser.queries.length).toBe(2);
+
+ this.expect(this.parser.queries[0].word).toBe('word1');
+ this.expect(this.parser.queries[0].or).toBe(false);
+ this.expect(this.parser.queries[0].not).toBe(false);
+ this.expect(this.parser.queries[0].raw).toBe(false);
+
+ this.expect(this.parser.queries[1].word).toBe('word2');
+ this.expect(this.parser.queries[1].or).toBe(false);
+ this.expect(this.parser.queries[1].not).toBe(false);
+ this.expect(this.parser.queries[1].raw).toBe(false);
+ }
+
+ function test_single_string_or () : void
+ {
+ this.parser.parse('word1 OR word2');
+ this.expect(this.parser.queries.length).toBe(2);
+
+ this.expect(this.parser.queries[0].word).toBe('word1');
+ this.expect(this.parser.queries[0].or).toBe(false);
+ this.expect(this.parser.queries[0].not).toBe(false);
+ this.expect(this.parser.queries[0].raw).toBe(false);
+
+ this.expect(this.parser.queries[1].word).toBe('word2');
+ this.expect(this.parser.queries[1].or).toBe(true);
+ this.expect(this.parser.queries[1].not).toBe(false);
+ this.expect(this.parser.queries[1].raw).toBe(false);
+ }
+
+ function test_single_string_not () : void
+ {
+ this.parser.parse('word1 -word2');
+ this.expect(this.parser.queries.length).toBe(2);
+
+ this.expect(this.parser.queries[0].word).toBe('word1');
+ this.expect(this.parser.queries[0].or).toBe(false);
+ this.expect(this.parser.queries[0].not).toBe(false);
+ this.expect(this.parser.queries[0].raw).toBe(false);
+
+ this.expect(this.parser.queries[1].word).toBe('word2');
+ this.expect(this.parser.queries[1].or).toBe(false);
+ this.expect(this.parser.queries[1].not).toBe(true);
+ this.expect(this.parser.queries[1].raw).toBe(false);
+ }
+
+ function test_single_string_raw () : void
+ {
+ this.parser.parse('word1 "word2"');
+ this.expect(this.parser.queries.length).toBe(2);
+
+ this.expect(this.parser.queries[0].word).toBe('word1');
+ this.expect(this.parser.queries[0].or).toBe(false);
+ this.expect(this.parser.queries[0].not).toBe(false);
+ this.expect(this.parser.queries[0].raw).toBe(false);
+
+ this.expect(this.parser.queries[1].word).toBe('word2');
+ this.expect(this.parser.queries[1].or).toBe(false);
+ this.expect(this.parser.queries[1].not).toBe(false);
+ this.expect(this.parser.queries[1].raw).toBe(true);
+ }
+
+ function test_single_string_raw_not () : void
+ {
+ this.parser.parse('word1 -"word2"');
+ this.expect(this.parser.queries.length).toBe(2);
+
+ this.expect(this.parser.queries[0].word).toBe('word1');
+ this.expect(this.parser.queries[0].or).toBe(false);
+ this.expect(this.parser.queries[0].not).toBe(false);
+ this.expect(this.parser.queries[0].raw).toBe(false);
+
+ this.expect(this.parser.queries[1].word).toBe('word2');
+ this.expect(this.parser.queries[1].or).toBe(false);
+ this.expect(this.parser.queries[1].not).toBe(true);
+ this.expect(this.parser.queries[1].raw).toBe(true);
+ }
+
+}
+
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-sax.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-sax.jsx
new file mode 100644
index 000000000..8310bf0a7
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-sax.jsx
@@ -0,0 +1,147 @@
+import "sax.jsx";
+import "test-case.jsx";
+
+
+class TestHandler extends SAXHandler
+{
+ var events : string[];
+ var param1 : string[];
+ var param2 : string[];
+
+ function constructor (events : string[], param1 : string[], param2 : string[])
+ {
+ this.events = events;
+ this.param1 = param1;
+ this.param2 = param2;
+ }
+ override function ontext (text : string) : void
+ {
+ this.events.push("ontext");
+ this.param1.push(text);
+ this.param2.push(null);
+ }
+ override function ondoctype (doctype : string) : void
+ {
+ this.events.push("ondoctype");
+ this.param1.push(doctype);
+ this.param2.push(null);
+ }
+ override function onopentag (tagname : string, attributes : Map.<string>) : void
+ {
+ this.events.push("onopentag");
+ this.param1.push(tagname);
+ this.param2.push(null);
+ }
+ override function onclosetag (tagname : string) : void
+ {
+ this.events.push("onclosetag");
+ this.param1.push(tagname);
+ this.param2.push(null);
+ }
+ override function onattribute (name : string, value : string) : void
+ {
+ this.events.push("onattribute");
+ this.param1.push(name);
+ this.param2.push(value);
+ }
+ override function oncomment (comment : string) : void
+ {
+ this.events.push("oncomment");
+ this.param1.push(comment);
+ this.param2.push(null);
+ }
+ override function onend () : void
+ {
+ this.events.push("onend");
+ this.param1.push(null);
+ this.param2.push(null);
+ }
+ override function onready () : void
+ {
+ this.events.push("onready");
+ this.param1.push(null);
+ this.param2.push(null);
+ }
+ override function onscript (script : string) : void
+ {
+ this.events.push("onscript");
+ this.param1.push(script);
+ this.param2.push(null);
+ }
+}
+
+class _Test extends TestCase
+{
+ var handler : TestHandler;
+ var parser : SAXParser;
+
+ var events : string[];
+ var param1 : string[];
+ var param2 : string[];
+
+ override function setUp () : void
+ {
+ this.events = [] : string[];
+ this.param1 = [] : string[];
+ this.param2 = [] : string[];
+ this.handler = new TestHandler(this.events, this.param1, this.param2);
+ this.parser = new SAXParser(this.handler);
+ }
+
+ function test_empty_input () : void
+ {
+ this.parser.parse('');
+ this.expect(this.events[0]).toBe('onready');
+ this.expect(this.events[1]).toBe('onend');
+ }
+
+ function test_doctype () : void
+ {
+ this.parser.parse('<!DOCTYPE html>');
+ this.expect(this.events[1]).toBe('ondoctype');
+ this.expect(this.param1[1]).toBe('html');
+ }
+
+ function test_tag1 () : void
+ {
+ this.parser.parse('<html></html>');
+ this.expect(this.events[1]).toBe('onopentag');
+ this.expect(this.param1[1]).toBe('html');
+ this.expect(this.events[2]).toBe('onclosetag');
+ this.expect(this.param1[2]).toBe('html');
+ }
+
+ function test_tag2 () : void
+ {
+ this.parser.parse('<html/>');
+ this.expect(this.events[1]).toBe('onopentag');
+ this.expect(this.param1[1]).toBe('html');
+ this.expect(this.events[2]).toBe('onclosetag');
+ this.expect(this.param1[2]).toBe('html');
+ }
+
+ function test_attribute () : void
+ {
+ this.parser.parse('<html lang="ja"></html>');
+ this.expect(this.events[1]).toBe('onattribute');
+ this.expect(this.param1[1]).toBe('lang');
+ this.expect(this.param2[1]).toBe('ja');
+ this.expect(this.events[2]).toBe('onopentag');
+ this.expect(this.param1[2]).toBe('html');
+ }
+
+ function test_text () : void
+ {
+ this.parser.parse('<html><body>hello world</body></html>');
+ this.expect(this.events[3]).toBe('ontext');
+ this.expect(this.param1[3]).toBe('hello world');
+ }
+
+ function test_comment () : void
+ {
+ this.parser.parse('<html><body><!-- comment --></body></html>');
+ this.expect(this.events[3]).toBe('oncomment');
+ this.expect(this.param1[3]).toBe('comment');
+ }
+}
+
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-search-result.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-search-result.jsx
new file mode 100644
index 000000000..81bcc05d0
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-search-result.jsx
@@ -0,0 +1,159 @@
+import "test-case.jsx";
+import "search-result.jsx";
+
+
+class _Test extends TestCase
+{
+ function test_simple_registration () : void
+ {
+ var result = new SingleResult();
+ var section = result.getSearchUnit(0);
+ section.addPosition('hello', 0, false);
+ section.addPosition('world', 7, false);
+ this.expect(section.size()).toBe(2);
+ }
+
+ function test_duplicate_longer_word_is_kept () : void
+ {
+ var result = new SingleResult();
+ var section = result.getSearchUnit(0);
+ section.addPosition('hello', 0, false);
+ section.addPosition('hello world', 0, false);
+ var position = section.get(0);
+
+ this.expect(section.size()).toBe(1);
+ this.expect(position.word).toBe('hello world');
+ }
+
+ function test_duplicate_no_stemmed_word_is_kept () : void
+ {
+ var result = new SingleResult();
+ var section = result.getSearchUnit(0);
+ section.addPosition('hello', 0, true);
+ section.addPosition('hello', 0, false);
+ var position = section.get(0);
+
+ this.expect(section.size()).toBe(1);
+ this.expect(position.stemmed).toBe(false);
+ }
+
+ function test_and_merge () : void
+ {
+ var result1 = new SingleResult();
+ result1.getSearchUnit(0);
+ result1.getSearchUnit(1);
+
+ var result2 = new SingleResult();
+ result2.getSearchUnit(0);
+
+ var result3 = result1.merge(result2);
+
+ this.expect(result3.size()).toBe(1);
+ }
+
+ function test_and_merge_2 () : void
+ {
+ var result1 = new SingleResult();
+ result1.getSearchUnit(0);
+ result1.getSearchUnit(1);
+
+ var result2 = new SingleResult();
+ result2.getSearchUnit(2);
+
+ var result3 = result1.merge(result2);
+
+ this.expect(result3.size()).toBe(0);
+ }
+
+ function test_or_merge () : void
+ {
+ var result1 = new SingleResult();
+ result1.getSearchUnit(0);
+ result1.getSearchUnit(1);
+
+ var result2 = new SingleResult();
+ result2.getSearchUnit(0);
+ result2.getSearchUnit(2);
+ result2.or = true;
+
+ var result3 = result1.merge(result2);
+
+ this.expect(result3.size()).toBe(3);
+ }
+
+ function test_not_merge () : void
+ {
+ var result1 = new SingleResult();
+ result1.getSearchUnit(0);
+ result1.getSearchUnit(1);
+ result1.getSearchUnit(2);
+
+ var result2 = new SingleResult();
+ result2.getSearchUnit(0);
+ result2.getSearchUnit(2);
+ result2.not = true;
+
+ var result3 = result1.merge(result2);
+
+ this.expect(result3.size()).toBe(1);
+ }
+
+ function test_merge () : void
+ {
+ var summary = new SearchSummary();
+ var singleresult1 = new SingleResult();
+ singleresult1.getSearchUnit(0);
+ singleresult1.getSearchUnit(1);
+
+ var singleresult2 = new SingleResult();
+ singleresult2.getSearchUnit(1);
+
+ summary.add(singleresult1);
+ summary.add(singleresult2);
+ summary.mergeResult();
+
+ this.expect(summary.size()).toBe(1);
+ }
+
+ function test_proposal () : void
+ {
+ var summary = new SearchSummary();
+ var singleresult1 = new SingleResult();
+ singleresult1.getSearchUnit(0);
+ singleresult1.getSearchUnit(1);
+
+ var singleresult2 = new SingleResult();
+ singleresult2.getSearchUnit(2);
+
+ summary.add(singleresult1);
+ summary.add(singleresult2);
+
+ var proposal = summary.getProposal();
+
+ this.expect(proposal[0].omit).toBe(1);
+ this.expect(proposal[0].expect).toBe(2);
+ this.expect(proposal[1].omit).toBe(0);
+ this.expect(proposal[1].expect).toBe(1);
+ }
+
+ function test_sort () : void
+ {
+ var summary = new SearchSummary();
+ var singleresult = new SingleResult();
+ var section1 = singleresult.getSearchUnit(0);
+ var section2 = singleresult.getSearchUnit(1);
+ var section3 = singleresult.getSearchUnit(2);
+
+ summary.add(singleresult);
+ summary.mergeResult();
+ summary.result.getSearchUnit(0).score = 100;
+ summary.result.getSearchUnit(1).score = 300;
+ summary.result.getSearchUnit(2).score = 200;
+
+ var result = summary.getSortedResult();
+ this.expect(result.length).toBe(3);
+ this.expect(result[0].id).toBe(1);
+ this.expect(result[1].id).toBe(2);
+ this.expect(result[2].id).toBe(0);
+ }
+}
diff --git a/web/server/h2o/libh2o/misc/oktavia/test/test-wavelet-matrix.jsx b/web/server/h2o/libh2o/misc/oktavia/test/test-wavelet-matrix.jsx
new file mode 100644
index 000000000..049d18d89
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/test/test-wavelet-matrix.jsx
@@ -0,0 +1,143 @@
+/**
+ * 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 "wavelet-matrix.jsx";
+
+class _Test extends TestCase
+{
+ var test_src : string;
+ var wm : WaveletMatrix;
+ var rd : int[][];
+ var sd : int[][];
+ var td : int[][];
+
+ override function setUp () : void
+ {
+ this.test_src = "abracadabra mississippi";
+ this.wm = new WaveletMatrix();
+ this.wm.build(this.test_src);
+ this.rd = [] : int[][];
+ this.sd = [] : int[][];
+ this.td = [] : int[][];
+
+ for (var i = 0; i < 256; i++)
+ {
+ this.rd.push([0] : int[]);
+ this.td.push([0] : int[]);
+ this.sd.push([] : int[]);
+ }
+
+ for (var i = 0; i < this.test_src.length; i++)
+ {
+ for (var c = 0; c < 256; c++)
+ {
+ this.rd[c].push(this.rd[c][i]);
+ this.td[c].push(this.td[c][i]);
+ if (this.test_src.charCodeAt(i) == c)
+ {
+ this.rd[c][i + 1]++;
+ this.sd[c].push(i);
+ }
+ if (this.test_src.charCodeAt(i) < c)
+ {
+ this.td[c][i + 1]++;
+ }
+ }
+ }
+ }
+
+ function test_size () : void
+ {
+ this.expect(this.wm.size()).toBe(this.test_src.length);
+ for (var c = 0; c < 256; c++)
+ {
+ this.expect(this.wm.size(c)).toBe(this.rd[c][this.wm.size()]);
+ }
+ }
+
+ function test_get() : void
+ {
+ for (var i = 0; i < this.wm.size(); i++)
+ {
+ this.expect(this.wm.get(i)).toBe(this.test_src.charCodeAt((i)));
+ }
+ }
+
+ function test_rank() : void
+ {
+ for (var c = 0; c < 256; c++)
+ {
+ for (var i = 0; i <= this.wm.size(); i++)
+ {
+ this.expect(this.wm.rank(i, c)).toBe(this.rd[c][i]);
+ }
+ }
+ }
+
+ function test_rank_less_than() : void
+ {
+ for (var c = 0; c < 256; c++)
+ {
+ for (var i = 0; i <= this.wm.size(); i++)
+ {
+ this.expect(this.wm.rank_less_than(i, c)).toBe(this.td[c][i]);
+ }
+ }
+ }
+
+ function test_load_dump_and_size () : void
+ {
+ var dump = this.wm.dump();
+ this.wm.load(dump);
+
+ this.expect(this.wm.size()).toBe(this.test_src.length);
+ for (var c = 0; c < 256; c++)
+ {
+ this.expect(this.wm.size(c)).toBe(this.rd[c][this.wm.size()]);
+ }
+ }
+
+ function test_load_dump_and_get() : void
+ {
+ var dump = this.wm.dump();
+ this.wm.load(dump);
+
+ for (var i = 0; i < this.wm.size(); i++)
+ {
+ this.expect(this.wm.get(i)).toBe(this.test_src.charCodeAt((i)));
+ }
+ }
+
+ function test_load_dump_and_rank() : void
+ {
+ var dump = this.wm.dump();
+ this.wm.load(dump);
+
+ for (var c = 0; c < 256; c++)
+ {
+ for (var i = 0; i <= this.wm.size(); i++)
+ {
+ this.expect(this.wm.rank(i, c)).toBe(this.rd[c][i]);
+ }
+ }
+ }
+
+ function test_load_dump_and_rank_less_than() : void
+ {
+ var dump = this.wm.dump();
+ this.wm.load(dump);
+
+ for (var c = 0; c < 256; c++)
+ {
+ for (var i = 0; i <= this.wm.size(); i++)
+ {
+ this.expect(this.wm.rank_less_than(i, c)).toBe(this.td[c][i]);
+ }
+ }
+ }
+}