summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/misc/oktavia/test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 02:57:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 02:57:58 +0000
commitbe1c7e50e1e8809ea56f2c9d472eccd8ffd73a97 (patch)
tree9754ff1ca740f6346cf8483ec915d4054bc5da2d /web/server/h2o/libh2o/misc/oktavia/test
parentInitial commit. (diff)
downloadnetdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.tar.xz
netdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.zip
Adding upstream version 1.44.3.upstream/1.44.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-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
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/testdata/jsx_literal.txt65
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/testdata/jsx_operator.txt68
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/testdata/jsx_primitive_type.txt68
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/testdata/jsx_tutorial.txt213
-rw-r--r--web/server/h2o/libh2o/misc/oktavia/testdata/jsx_typeconversion.txt40
20 files changed, 2670 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 00000000..25882e34
--- /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 00000000..18f80b64
--- /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 00000000..6a033e58
--- /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 00000000..80035a61
--- /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 00000000..63731b92
--- /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 00000000..f5f562c7
--- /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 00000000..0c37afea
--- /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 00000000..859eb911
--- /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 00000000..d8d1d74e
--- /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 00000000..ee2aa097
--- /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 00000000..c04ac46e
--- /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 00000000..94ec7c19
--- /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 00000000..8310bf0a
--- /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 00000000..81bcc05d
--- /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 00000000..049d18d8
--- /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]);
+ }
+ }
+ }
+}
diff --git a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_literal.txt b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_literal.txt
new file mode 100644
index 00000000..7415d746
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_literal.txt
@@ -0,0 +1,65 @@
+Literals
+
+Keywords
+
+The table lists the keyword literals of JSX. In contrary to JavaScript, there is no distinction between undefined and null.
+
+Table 1. List of Keyword Literals
+Keyword Description
+null [: type] declares null, may have the type annotated. The type is deducted (if possible) if the type annotation does not exist.
+false a boolean constant
+true a boolean constant
+Number Literal
+
+Identical to JavaScript.
+
+String Literal
+
+Identical to JavaScript.
+
+RegExp Literal
+
+Identical to JavaScript.
+
+Function Literal
+
+Type annotations against arguments and return types are required for function declaration, unless the type can be deducted by the surrounding expression.
+
+// a function that takes no arguments, and returns void
+function () : void {}
+
+// a function that takes one argument (of number),
+// and returns a number that in incremented by one
+function (n : number) : number {
+ return n + 1;
+}
+
+// the argument types and return types may be omitted
+// (if it is deductable from the outer expression)
+var sum = 0;
+[ 1, 2, 3 ].forEach(function (e) {
+ sum += e;
+});
+log sum; // 6
+
+// short-handed
+var sum = 0;
+[ 1, 2, 3 ].forEach((e) -> { sum += e; });
+log sum; // 6
+
+// short-handed, single-statement function expression
+var s = "a0b1c".replace(/[a-z]/g, (ch) -> ch.toUpperCase());
+log s; // A0B1C
+A statement starting with function is parsed as inner function declaration, as is by JavaScript. Surround the function declaration with () if your intention is to create an anonymous function and call it immediately.
+
+// inner function declaration (when used within a function declaration)
+function innerFunc() : void {
+ ...;
+}
+
+// create an anonymous function and execute immediately
+(function () : void {
+ ...;
+})();
+See also: Member Function in Class, Interface, and Mixin.
+
diff --git a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_operator.txt b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_operator.txt
new file mode 100644
index 00000000..7b79f932
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_operator.txt
@@ -0,0 +1,68 @@
+Operators
+
+The operators of JSX are the same to those in JavaScript (ECMA-262 3rd edition) except for the following changes.
+
+types of the operands accepted by the operators are more restrictive
+logical operators (&& ||) return boolean
+binary ?: operator has been introduced (to cover the use of || in JavaScript to return non-boolean values)
+introduction of the as operator
+delete is a statement instead of an operator
+The table below lists the operators supported by JSX.
+
+Table 1. List of Operators by Precedence
+Operator Returned Type Operand Type(s)
+(x)[1] typeof x
+func(...) return type of the function
+obj.prop typeof obj.prop obj: any object type
+array[index] Nullable.<T> array: Array.<T>
+index: number
+map[key] Nullable.<T> map: Map.<T>
+key: string
+x++
+x-- typeof x number or int
+obj instanceof type boolean obj: any object type
+type: a Class, Interface, or Mixin
+x as type[2]
+x as __noconvert__ type[3] type
+++x
+--x typeof x number or int
++x
+-x typeof x number or int
+~x int number or int
+! x boolean any
+typeof x string variant
+x * y
+x % y number or int[4] number or int
+x / y number number or int
+x + y
+x - y number or int[4] number or int
+x + y string string
+x << y
+x >> y
+x >>> y int number or int
+x < y
+x<= y
+x > y
+x >= y boolean number, int, string[5]
+x in y boolean x: string
+y: Map.<T>
+x == y
+x != y boolean any except variant[5]
+x & y int number or int
+x ^ y int number or int
+x | y int number or int
+x && y boolean any
+x || y boolean any
+x ? y : z typeof y any[6]
+x ?: y typeof x any[5]
+x = y typeof x any[7]
+x op[8]= y typeof x same as op
+x, y typeof y any
+grouping operator
+cast operator
+cast operator (without run-time type check)
+int is returned if both operands are int
+types of x and y should be equal, or either should be convertible to the other
+types of y and z should be equal, or either should be convertible to the other
+type of y should be convertible to type of x
+any of: * / % + - << >> >>> & ^ |
diff --git a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_primitive_type.txt b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_primitive_type.txt
new file mode 100644
index 00000000..c55778dc
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_primitive_type.txt
@@ -0,0 +1,68 @@
+Primitive Types
+
+JSX provides the following four primitive types. Primitive types are non-nullable. Int exists as a type, but would be equal to or slower than using number in some cases (the definition of int is: an integral number between -231 to 231-1, or NaN, or +-Infinity).
+
+boolean
+number
+string
+(int)
+Nullable Primitive Types
+
+A nullable counterpart exists for each primitive type. Values of the types are returned by [] operators of Array.<primitive_type> and Map.<primitive_type>.
+
+Nullable.<boolean>
+Nullable.<number>
+Nullable.<string>
+(Nullable.<int>)
+Variant Type
+
+A variant can hold any type of data (including null). To use the data, explicit cast to other data types is necessary.
+
+Built-in Object Types
+
+Object
+
+Object class is the root class for all objects.
+
+Array.<T>
+
+The class represents an array, by providing the [] operator that takes a number as the argument, length property and other methods to manipulate the array. In contrast to JavaScript, the array is typed. An instance of Array.<T> class may only store elements of type T or null.
+
+The size of the array automatically grows. null is returned when an element out of the current boundary is requested.
+
+There are two ways to create an array object; one is to use the new opreator, the other is to use the array initialiser. The type of the array returned by an array initialiser is deducted from the type of the elements. Type information should be annotated in cases where such deduction is impossible (such as when initializing an empty array).
+
+new Array.<number>; // creates an empty array of numbers
+new Array.<number>(length); // creates an array of given length (elements are initialized to null)
+[] : Array.<number>; // creates an empty array of numbers
+[ 1, 2, 3 ]; // creates an array of numbers with three elements: 1, 2, 3
+Map.<T>
+
+The class represents an associative array (collection of key-values pairs), mapping strings to values of type T or null.
+
+Operator [] (that takes a string as the argument) is provided for registering / retreiving a keyed value. for..in statement can be used for iterating the keys. hasOwnProperty method is provided for checking whether or not a key-value pair of a particular name is registered. The delete statement can be used for unregistering a key-value pair.
+
+Map objects can be created in two ways; by using the new operator or by using the map initialiser.
+
+new Map.<number>; // creates an empty map of strings to numbers
+{} : Map.<number>; // same as above
+{ a: 1 }; // creates a map of strings to numbers that has one pair: ("a" => 1)
+Boolean, Number, String
+
+Internal types used for applying methods against primitives.
+
+These types of objects are instantiated when applying the dot operator against the primitives. For exmaple, the following code snippet applies the operator against string "abc", that returns a String object wrapping the primitive value. Then the charAt method of the object is called and "a" (of type string) is returned.
+
+"abc".charAt(0) // returns "a"
+Although being possible, it is discouraged to instantiate and store these values of the types (e.g. var s = new String("abc")). Use of the primitive types (or nullable primitive types) is preferable for performance and debugging reasons.
+
+Number and String classes also provide some useful class methods and constants, e.g. Number.parseInt(:string):number, String.encodeURIComponent(:string):string.
+
+JSX
+
+The class provides some methods for controlling the runtime environment.
+
+User-defined Types
+
+Users may define a new class by extending the Object class, or by declaring an interface or a mixin. See Class, Interface and Mixin.
+
diff --git a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_tutorial.txt b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_tutorial.txt
new file mode 100644
index 00000000..538238a3
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_tutorial.txt
@@ -0,0 +1,213 @@
+Background
+
+JSX is a statically-typed, object-oriented programming language compiling to standalone JavaScript. The reason why JSX was developed is our need for a more robust programming language than JavaScript. However, JSX is fairly close to JavaScript especially in its statements and expressions.
+
+Statically-typed programming language is robust because certain sorts of problems, for example typos in variable names or missing function definitions, are detected at compile-time. This is important especially in middle- to large-scale software development in which a number of engineers may be engaged.
+
+Therefore, JSX is designed as a statically-typed language. All the values and variables have a static type and you can only assign a correctly-typed value to a variable. In addition, all the functions including closures have types which are determined by the types of parameters and the return values, where you cannot call a function with incorrectly typed arguments.
+
+Also, another important reason why JSX was developed is to boost JavaScript performance. JavaScript itself is not so slow but large-scale development tends to have many abstraction layers, e.g. proxy classes and accessor methods, which often have negative impact on performance. JSX boosts performance by inline expansion: function bodies are expanded to where they are being called, if the functions being called could be determined at compile-time. This is the power of the statically-typed language in terms of performance.
+
+Run "Hello, World!"
+
+Let's start by running our first JSX program: hello.jsx. We use the jsx command, which is the JSX compiler in the JSX distribution, to compile JSX source code to JavaScript.
+
+Type as follows in the JSX distribution and/or repository, and then you will see it saying "Hello, world!".
+
+$ bin/jsx --run example/hello.jsx
+We will look into the hello.jsx source code in the next section.
+
+Program Structure
+
+Here is hello.jsx, the source code of the "Hello world!" example. You can see several features of JSX in this program, namely, static types and class structure within the source code.
+
+class _Main {
+ static function main(args : string[]) : void {
+ log "Hello, world!";
+ }
+}
+Class _Main has a static member function (a.k.a. a class method) named main, that takes an array of strings and returns nothing. _Main.main(:string[]):void is the entry point of JSX applications that is called when a user invokes an application from command line. JSX, like Java, does not allow top-level statements or functions.
+
+The log statement is mapped to console.log() in JavaScript, which displays the arguments to stdout with a newline.
+
+Next, we look into another typical library class, Point:
+
+class Point {
+ var x = 0;
+ var y = 0;
+
+ function constructor() {
+ }
+
+ function constructor(x : number, y : number) {
+ this.set(x, y);
+ }
+
+ function constructor(other : Point) {
+ this.set(other);
+ }
+
+ function set(x : number, y : number) : void {
+ this.x = x;
+ this.y = y;
+ }
+
+ function set(other : Point) : void {
+ this.x = other.x;
+ this.y = other.y;
+ }
+}
+As you can see, member variables of Point, var x and var y, are declared without types, but their types are deducted from their initial values to be number.
+
+You might be surprised at multiple definition of member functions: one takes no parameters and the others take parameters. They are overloaded by their types of parameters. When you construct the class with new Point(), the first constructor, which takes no parameters, is called. The second with two parameters will be called on new Point(2, 3) and the third with one parameter will be called as a copy constructor. Other forms of construction, e.g. new Point(42) or new Point("foo", "bar") will cause compilation errors of mismatching signatures. The Point#set() functions are also overloaded and the compiler know how to call the correct one.
+
+Static Types
+
+Basic type concept will be described in this section. Primitive types, object types, variant type, and Nullable types exist in JSX.
+
+Primitive types, e.g. string, boolean, or number are non-nullable, immutable types.
+
+var s : string = "hello";
+var n : number = 42;
+var b : boolean = true;
+Object types, e.g. string[] (array of string), functions or Date, are nullable, mutable types.
+
+var d : Date = new Date(); // Date
+var f : function():void = function() : void { log "Hi!"; };
+var a : string[] = ["foo"]; // the same as Array.<string>;
+Variant type, which means "no static type information," is used for interacting with existing JavaScript APIs. Some JavaScript libraries may return a variant value, which type cannot be determined at compile time. All you can do on variant values is to check equality of a variant value to another variant value. You have to cast it to another type before doing anything else on the value.
+
+Nullable type is a meta type which indicates a value may be null. For example, the return type of Array.<string>#shift() is Nullable.<string>. When you use a Nullable value, you have to make sure of the value is not null. Only primitive types can be marked Nullable. Object types and variants are nullable by default.
+
+function shiftOrReturnEmptyString(args : string[]) : string {
+ if (args.length > 0)
+ return args.shift();
+ else
+ return "";
+}
+When the source code is compiled in debug mode (which is the default), the compiler will insert run-time type-checking code. An exception will be raised (or the debugger will be activated) when misuse of a null value as actual value is detected. Run-time type checks can be omitted by compiling the source code with the --release option.
+Classes and Interfaces
+
+JSX is a class-based object-oriented language, and its class model is similar to Java.
+
+a class may extend another class (single inheritance)
+a class may implement multiple interfaces
+all classes share a single root class: the Object class
+interface Flyable {
+ abstract function fly() : void;
+}
+
+abstract class Animal {
+ function eat() : void {
+ log "An animal is eating!";
+ }
+}
+
+class Bat extends Animal implements Flyable {
+ override function fly() : void {
+ log "A bat is flying!";
+ }
+}
+
+abstract class Insect {
+}
+
+class Bee extends Insect implements Flyable {
+ override function fly() : void {
+ log "A bee is flying!";
+ }
+}
+
+class _Main {
+
+ static function main(args : string[]) : void {
+ // fo bar
+ var bat = new Bat();
+
+ var animal : Animal = bat; // OK. A bat is an animal.
+ animal.eat();
+
+ var flyable : Flyable = bat; // OK. A bat can fly
+ flyable.fly();
+
+ // for Bee
+ var bee = new Bee();
+
+ flyable = bee; // A bee is also flyable
+ flyable.fly();
+ }
+}
+In the example, the Bat class extends the Animal class, so it inherits the Animal#eat() member function, and it can be assigned to a variable typed to Animal. The class also implements the Flyable interface overriding the Flyable#fly() member function, so it can be assigned to a variable typed Flyable. There's also another flyable class, Bee. By using the Flyable interface, it is possible to deal with both classes as a flyable being, even if the organ of a bee is completely different from that of a bat.
+
+When overriding a member function, the use the override keyword is mandatory. Otherwise the compiler will report an error. In other words, you are saved from unexpected interface changes in the base classes which cause compilation errors in derived classes instead of undesirable runtime errors.
+Functions and Closures
+
+In JSX, functions are first-class objects and they have static types. You can declare a variable of a function type like var f : function(arg : number) : number, a function that takes a number as an argument and returns another number (or, just returns the same value as the argument; but it's not important here). The variable f can be called as f(42) from which you will get a number value.
+
+It is possible to define closures (or anonymous functions). They are typically used to implement event listeners, which are popular in GUI programming. Closures are similar to JavaScript except for what this points at: when a closure is defined within a member function, it refers to the receiver of the member function. See the following example.
+class _Main {
+ var foo = 42;
+
+ function constructor() {
+ var f = function() : void {
+ log this.foo;
+ };
+
+ f(); // says 42
+ }
+
+ static function main(args : string[]) : void {
+ var o = new _Main();
+ }
+}
+Modules
+
+JSX has a module system. You can reuse JSX class libraries by the import statement. For example, the following program uses timer.jsx module, which exports the Timer class.
+
+import "timer.jsx";
+
+class _Main {
+
+ static function main(args : string[]) : void {
+ Timer.setTimeout(function() : void {
+ log "Hello, world!";
+ }, 1000);
+ }
+
+}
+A module may export multiple classes, but you can specify what modules you import or name a namespace which the module is imported into.
+
+Interface to Web Browsers
+
+The js/web.jsx module provides the interface to web browser APIs, e.g. the window object and DOM APIs. The example below shows how to insert a text node into an HTML.
+
+// hello.jsx
+import "js/web.jsx";
+
+class _Main {
+
+ static function main(args : string[]) : void {
+ var document = dom.window.document;
+
+ var text = document.createTextNode("Hello, world!");
+ document.getElementById("hello").appendChild(text);
+ }
+
+}
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Hello, world!</title>
+ <script src="hello.jsx.js"></script>
+ </head>
+ <body>
+ <p id="hello"></p>
+ </body>
+</html>
+Once you compile hello.jsx by the following command, then you can access the HTML and you will see it saying "Hello, world!."
+
+$ bin/jsx --executable web --output hello.jsx.js hello.jsx
+Further Learning
+
+More documents can be found on the wiki.
+If you are looking for examples, please refer to the examples on this web site, the example directory of the distribution, or to the links on Resouces page of the wiki.
diff --git a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_typeconversion.txt b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_typeconversion.txt
new file mode 100644
index 00000000..ec138bb3
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_typeconversion.txt
@@ -0,0 +1,40 @@
+Documents > Type Conversion
+Type Conversion
+
+The as operator is used for: conversion between primitive types (including Nullable and variant), down-casting of object types.
+
+The conversion rules between primitive types are defined as follows. If the source type is a Nullable type and if the value is null, a run-time exception is raised under debug builds. The behavior is unspecified for release builds.
+
+The result of conversion from a variant type depends on the result of the typeof operator applied to the variant.
+
+Down-casting of an object type returns a reference to the casted object if successful, otherwise null.
+
+Table 1. Conversion between the Primitive Types using the As Operator
+Source Type Destination Type Result
+boolean number 0 if false, 1 if true
+boolean int same as above
+boolean string "false" if false, "true" if true
+number boolean false if 0 or NaN, otherwise true
+number int fractional part is removed, becomes 0 if NaN, may get rounded to between -231 and 231-1
+number string converted to string representation
+int boolean false if 0, otherwise true
+int number converted to number of same value
+int string converted to string representation
+string boolean false if the string is empty, otherwise true
+string number 0 if the string is empty, a number if the string can be parsed as a string, otherwise NaN
+string int equivalent to: as number as int
+Table 2. Conversion from Variant using the As Operator
+Result of typeof(variant) Destination Type Result
+"undefined" boolean false
+"undefined" number NaN
+"undefined" int 0
+"undefined" string "undefined"
+"null" boolean false
+"null" number 0
+"null" int 0
+"null" string "null"
+"boolean" any primitive type equivalent to the result of: boolean as type
+"number" any primitive type equivalent to the result of: number as type
+"string" any primitive type equivalent to the result of: string as type
+"object" any primitive type depends on the actual type of the value
+"object" any object type reference to the object if the value is an object of the specified type, otherwise null