public void testRef() { HaystackToken hrefVal = HaystackToken.refh; verifyToks("@125b780e-0684e169", new object[] { hrefVal, HRef.make("125b780e-0684e169") }); verifyToks("@demo:_:-.~", new object[] { hrefVal, HRef.make("demo:_:-.~") }); }
public void testBasics() { HRow row = BuildRows( new[] { "id", "site", "geoAddr", "area", "date", "null" }, new HVal[] { HRef.make("aaaa-bbbb"), HMarker.VAL, HStr.make("Richmond, Va"), HNum.make(1200, "ft"), HDate.make(2000, 12, 3), null }) .First(); // size Assert.AreEqual(row.size(), 6); Assert.IsFalse(row.isEmpty()); // configured tags Assert.IsTrue(row.get("id").hequals(HRef.make("aaaa-bbbb"))); Assert.IsTrue(row.get("site").hequals(HMarker.VAL)); Assert.IsTrue(row.get("geoAddr").hequals(HStr.make("Richmond, Va"))); Assert.IsTrue(row.get("area").hequals(HNum.make(1200, "ft"))); Assert.IsTrue(row.get("date").hequals(HDate.make(2000, 12, 3))); Assert.AreEqual(row.get("null", false), null); try { row.get("null"); Assert.Fail(); } catch (HaystackUnknownNameException) { Assert.IsTrue(true); } // missing tag Assert.IsFalse(row.has("foo")); Assert.IsTrue(row.missing("foo")); Assert.IsNull(row.get("foo", false)); try { row.get("foo"); Assert.Fail(); } catch (HaystackUnknownNameException) { Assert.IsTrue(true); } try { row.get("foo", true); Assert.Fail(); } catch (HaystackUnknownNameException) { Assert.IsTrue(true); } }
public void testInclude() { HDict a = new HDictBuilder() .add("dis", "a") .add("num", 100) .add("foo", 99) .add("date", HDate.make(2011, 10, 5)) .toDict(); HDict b = new HDictBuilder() .add("dis", "b") .add("num", 200) .add("foo", 88) .add("date", HDate.make(2011, 10, 20)) .add("bar") .add("ref", HRef.make("a")) .toDict(); HDict c = new HDictBuilder() .add("dis", "c") .add("num", 300) .add("ref", HRef.make("b")) .add("bar") .toDict(); Dictionary <string, HDict> db = new Dictionary <string, HDict>(); db.Add("a", a); db.Add("b", b); db.Add("c", c); verifyInclude(db, "dis", "a,b,c"); verifyInclude(db, "dis == \"b\"", "b"); verifyInclude(db, "dis != \"b\"", "a,c"); verifyInclude(db, "dis <= \"b\"", "a,b"); verifyInclude(db, "dis > \"b\"", "c"); verifyInclude(db, "num < 200", "a"); verifyInclude(db, "num <= 200", "a,b"); verifyInclude(db, "num > 200", "c"); verifyInclude(db, "num >= 200", "b,c"); verifyInclude(db, "date", "a,b"); verifyInclude(db, "date == 2011-10-20", "b"); verifyInclude(db, "date < 2011-10-10", "a"); verifyInclude(db, "foo", "a,b"); verifyInclude(db, "not foo", "c"); verifyInclude(db, "foo == 88", "b"); verifyInclude(db, "foo != 88", "a"); verifyInclude(db, "foo == \"x\"", ""); verifyInclude(db, "ref", "b,c"); verifyInclude(db, "ref->dis", "b,c"); verifyInclude(db, "ref->dis == \"a\"", "b"); verifyInclude(db, "ref->bar", "c"); verifyInclude(db, "not ref->bar", "a,b"); verifyInclude(db, "foo and bar", "b"); verifyInclude(db, "foo or bar", "a,b,c"); verifyInclude(db, "(foo and bar) or num==300", "b,c"); verifyInclude(db, "foo and bar and num==300", ""); }
public void testSimple() { HGridBuilder b = new HGridBuilder(); b.addCol("id"); b.addCol("dis"); b.addCol("area"); b.addRow(new HVal[] { HRef.make("a"), HStr.make("Alpha"), HNum.make(1200) }); b.addRow(new HVal[] { HRef.make("b"), null, HNum.make(1400) }); // meta HGrid g = b.toGrid(); Assert.AreEqual(g.meta.size(), 0); // cols //HCol c; Assert.AreEqual(g.numCols, 3); verifyCol(g, 0, "id"); verifyCol(g, 1, "dis"); verifyCol(g, 2, "area"); // rows Assert.AreEqual(g.numRows, 2); Assert.IsFalse(g.isEmpty()); HRow r; r = g.row(0); Assert.IsTrue(r.get("id").hequals(HRef.make("a"))); Assert.IsTrue(r.get("dis").hequals(HStr.make("Alpha"))); Assert.IsTrue(r.get("area").hequals(HNum.make(1200))); r = g.row(1); Assert.IsTrue(r.get("id").hequals(HRef.make("b"))); Assert.IsNull(r.get("dis", false)); Assert.IsTrue(r.get("area").hequals(HNum.make(1400))); try { r.get("dis"); Assert.Fail(); } catch (UnknownNameException) { Assert.IsTrue(true); } Assert.IsNull(r.get("fooBar", false)); try { r.get("fooBar"); Assert.Fail(); } catch (UnknownNameException) { Assert.IsTrue(true); } // HRow no-nulls HRow it = g.row(0); Assert.IsFalse(it.Size > 3); verifyRowIterator(it, 0, "id", HRef.make("a")); verifyRowIterator(it, 1, "dis", HStr.make("Alpha")); verifyRowIterator(it, 2, "area", HNum.make(1200)); // HRow with nulls it = g.row(1); Assert.IsFalse(it.Size > 3); verifyRowIterator(it, 0, "id", HRef.make("b")); verifyRowIterator(it, 2, "area", HNum.make(1400)); // iterating verifyGridIterator(g); }
private HVal parseLiteral() { object val = m_curVal; if (m_tokCur == HaystackToken.refh && m_tokPeek == HaystackToken.str) { val = HRef.make(((HRef)val).val, ((HStr)m_peekVal).Value); consume(HaystackToken.refh); } consume(); return((HVal)val); }
public void testBadRefConstruction() { string[] badRefs = new string[] { "@a", "a b", "a\n", "@" }; foreach (string strID in badRefs) { HRef.make(strID); } }
public void testBasics() { HRef hrefTest = HRef.make("a"); HStr str = HStr.make("string"); List <HVal> items = new List <HVal>(); items.Add(hrefTest); items.Add(str); HList list = HList.make(items); Assert.AreEqual(list.size(), 2); Assert.AreEqual(list.get(0), hrefTest); Assert.AreEqual(list.get(1), str); }
public void testJson() { // Arrange. HRef hrefTest = HRef.make("a"); HStr str = HStr.make("string"); List <HVal> items = new List <HVal>(); items.Add(hrefTest); items.Add(str); HList list = HList.make(items); // Act. var json = list.toJson(); // Assert. Assert.AreEqual("[{\"_kind\":\"ref\",\"val\":\"a\",\"dis\":null},\"string\"]", json); }
public void testWriter() { HGridBuilder gb = new HGridBuilder(); gb.addCol("a"); gb.addCol("b"); gb.addRow(new HVal[] { HNA.VAL, HBool.TRUE }); // Original Unit test had null - this is not valid gb.addRow(new HVal[] { HMarker.VAL, HNA.VAL }); gb.addRow(new HVal[] { HRemove.VAL, HNA.VAL }); gb.addRow(new HVal[] { HStr.make("test"), HStr.make("with:colon") }); gb.addRow(new HVal[] { HNum.make(12), HNum.make(72.3, "\u00b0F") }); gb.addRow(new HVal[] { HNum.make(double.NegativeInfinity), HNum.make(Double.NaN) }); gb.addRow(new HVal[] { HDate.make(2015, 6, 9), HTime.make(1, 2, 3) }); var tz = HTimeZone.make("UTC", true); gb.addRow(new HVal[] { HDateTime.make(634429600180690000L, tz), HUri.make("foo.txt") }); gb.addRow(new HVal[] { HRef.make("abc"), HRef.make("abc", "A B C") }); gb.addRow(new HVal[] { HBin.make("text/plain"), HCoord.make(90, -123) }); HGrid grid = gb.toGrid(); string actual = HJsonWriter.gridToString(grid); // System.out.println(actual); string[] lines = actual.Split('\n'); Assert.AreEqual(lines[0], "{"); Assert.AreEqual(lines[1], "\"meta\": {\"ver\":\"2.0\"},"); Assert.AreEqual(lines[2], "\"cols\":["); Assert.AreEqual(lines[3], "{\"name\":\"a\"},"); Assert.AreEqual(lines[4], "{\"name\":\"b\"}"); Assert.AreEqual(lines[5], "],"); Assert.AreEqual(lines[6], "\"rows\":["); Assert.AreEqual(lines[7], "{\"a\":\"z:\", \"b\":true},"); Assert.AreEqual(lines[8], "{\"a\":\"m:\", \"b\":\"z:\"},"); Assert.AreEqual(lines[9], "{\"a\":\"x:\", \"b\":\"z:\"},"); Assert.AreEqual(lines[10], "{\"a\":\"test\", \"b\":\"s:with:colon\"},"); Assert.AreEqual(lines[11], "{\"a\":\"n:12\", \"b\":\"n:72.3 \u00b0F\"},"); Assert.AreEqual(lines[12], "{\"a\":\"n:-INF\", \"b\":\"n:NaN\"},"); Assert.AreEqual(lines[13], "{\"a\":\"d:2015-06-09\", \"b\":\"h:01:02:03\"},"); Assert.AreEqual(lines[14], "{\"a\":\"t:2011-06-06T12:26:58.069Z UTC\", \"b\":\"u:foo.txt\"},"); Assert.AreEqual(lines[15], "{\"a\":\"r:abc\", \"b\":\"r:abc A B C\"},"); Assert.AreEqual(lines[16], "{\"a\":\"b:text/plain\", \"b\":\"c:90.0,-123.0\"}"); Assert.AreEqual(lines[17], "]"); Assert.AreEqual(lines[18], "}"); }
public void testBasics() { HDict tags = new HDictBuilder() .add("id", HRef.make("aaaa-bbbb")) .add("site") .add("geoAddr", "Richmond, Va") .add("area", 1200, "ft") .add("date", HDate.make(2000, 12, 3)) .add("null", (HVal)null) .toDict(); // size Assert.AreEqual(tags.size(), 5); Assert.IsFalse(tags.isEmpty()); // configured tags Assert.IsTrue(tags.get("id").hequals(HRef.make("aaaa-bbbb"))); Assert.IsTrue(tags.get("site").hequals(HMarker.VAL)); Assert.IsTrue(tags.get("geoAddr").hequals(HStr.make("Richmond, Va"))); Assert.IsTrue(tags.get("area").hequals(HNum.make(1200, "ft"))); Assert.IsTrue(tags.get("date").hequals(HDate.make(2000, 12, 3))); Assert.AreEqual(tags.get("null", false), null); try { tags.get("null"); Assert.Fail(); } catch (HaystackUnknownNameException) { Assert.IsTrue(true); } // missing tag Assert.IsFalse(tags.has("foo")); Assert.IsTrue(tags.missing("foo")); Assert.IsNull(tags.get("foo", false)); try { tags.get("foo"); Assert.Fail(); } catch (HaystackUnknownNameException) { Assert.IsTrue(true); } try { tags.get("foo", true); Assert.Fail(); } catch (HaystackUnknownNameException) { Assert.IsTrue(true); } }
private HaystackToken refh() { if (m_cCur < 0) { err("Unexpected eof in refh"); } consume('@'); StringBuilder s = new StringBuilder(); while (true) { if (HRef.isIdChar(m_cCur)) { s.Append((char)m_cCur); consume(); } else { break; } } m_val = HRef.make(s.ToString(), null); return(HaystackToken.refh); }
public void testDis() { Assert.AreEqual(new HDictBuilder().add("id", HRef.make("a")).toDict().dis(), "a"); Assert.AreEqual(new HDictBuilder().add("id", HRef.make("a", "b")).toDict().dis(), "b"); Assert.AreEqual(new HDictBuilder().add("id", HRef.make("a")).add("dis", "d").toDict().dis(), "d"); }
public void testZinc() { verifyZinc(HRef.make("1234-5678.foo:bar"), "@1234-5678.foo:bar"); verifyZinc(HRef.make("1234-5678", "Foo Bar"), "@1234-5678 \"Foo Bar\""); verifyZinc(HRef.make("1234-5678", "Foo \"Bar\""), "@1234-5678 \"Foo \\\"Bar\\\"\""); }
public void testEquality() { Assert.IsTrue(HRef.make("foo").hequals(HRef.make("foo"))); Assert.IsTrue(HRef.make("foo").hequals(HRef.make("foo", "Foo"))); Assert.IsFalse(HRef.make("foo").hequals(HRef.make("Foo"))); }
public void testComplexString() { verifyToks( @"{ id: ""1234:ab"", date: 2019-01-01T12:13:14 UTC, num: 100ms, def: ^tagdef }", new object[] { HaystackToken.lbrace, null, HaystackToken.id, "id", HaystackToken.colon, null, HaystackToken.str, HRef.make("1234:ab"), HaystackToken.comma, null, HaystackToken.id, "date", HaystackToken.colon, null, HaystackToken.dateTime, HDateTime.make("2019-01-01T12:13:14 UTC", false), HaystackToken.comma, null, HaystackToken.id, "num", HaystackToken.colon, null, HaystackToken.num, HNum.make(100, "ms"), HaystackToken.comma, null, HaystackToken.id, "def", HaystackToken.colon, null, HaystackToken.id, "^tagdef", HaystackToken.rbrace, null, }); }
public void testRef() { verifyParse("author == @xyz", HFilter.eq("author", HRef.make("xyz"))); verifyParse("author==@xyz:foo.bar", HFilter.eq("author", HRef.make("xyz:foo.bar"))); }