public void testZinc() { verifyZinc( HRow.Empty, "{}"); verifyZinc( BuildRows(new[] { "fooBar" }, new[] { HNum.make(123, "ft") }).First(), "{fooBar:123ft}"); verifyZinc( BuildRows(new[] { "dis", "bday", "marker" }, new HVal[] { HStr.make("Bob"), HDate.make(1970, 6, 3), HMarker.VAL }).First(), "{dis:\"Bob\" bday:1970-06-03 marker}"); // nested dict verifyZinc( BuildRows(new[] { "auth" }, new HVal[] { HDict.Empty }).First(), "{auth:{}}"); verifyZinc( BuildRows(new[] { "auth" }, BuildRows(new[] { "alg", "c", "marker" }, new HVal[] { HStr.make("scram"), HNum.make(10000), HMarker.VAL }).ToArray()).First(), "{auth:{alg:\"scram\" c:10000 marker}}"); // nested list verifyZinc( BuildRows(new[] { "arr", "x" }, new HVal[] { HList.make(new HVal[] { HNum.make(1.0), HNum.make(2), HNum.make(3) }), HMarker.VAL }).First(), "{arr:[1,2,3] x}"); // Was "{arr:[1.0,2,3] x}" - double in .NET will not recognise the difference between 1.0 and 1 }
private HaystackToken str() { consume('"'); StringBuilder s = new StringBuilder(); while (true) { if (m_cCur == m_iEOF) { err("Unexpected end of str"); } if ((char)m_cCur == '"') { consume('"'); break; } if ((char)m_cCur == '\\') { s.Append(escape()); continue; } s.Append((char)m_cCur); consume(); } m_val = HStr.make(s.ToString()); return(HaystackToken.str); }
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 testNoRows() { HGridBuilder b = new HGridBuilder(); b.Meta.add("dis", "Title"); b.addCol("a").add("dis", "Alpha"); b.addCol("b"); HGrid g = b.toGrid(); // meta Assert.AreEqual(g.meta.size(), 1); Assert.IsTrue(g.meta.get("dis").hequals(HStr.make("Title"))); // cols HCol c; Assert.AreEqual(g.numCols, 2); c = verifyCol(g, 0, "a"); Assert.AreEqual(c.dis(), "Alpha"); Assert.AreEqual(c.meta.size(), 1); Assert.IsTrue(c.meta.get("dis").hequals(HStr.make("Alpha"))); // rows Assert.AreEqual(g.numRows, 0); Assert.AreEqual(g.isEmpty(), true); // iterator verifyGridIterator(g); }
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); }
public void testStrings() { HaystackToken str = HaystackToken.str; verifyToks("\"\"", new object[] { str, HStr.make("") }); verifyToks("\"x y\"", new object[] { str, HStr.make("x y") }); verifyToks("\"x\\\"y\"", new object[] { str, HStr.make("x\"y") }); verifyToks("\"_\\u012f \\n \\t \\\\_\"", new object[] { str, HStr.make("_\u012f \n \t \\_") }); }
public void testToDict() { var row = BuildRows(new[] { "x", "y" }, new HVal[] { HMarker.VAL, HStr.make("y") }).First(); var dict = row.ToDict(); Assert.AreEqual(2, dict.Size); Assert.AreEqual(HMarker.VAL, dict["x"]); Assert.AreEqual(HStr.make("y"), dict["y"]); }
////////////////////////////////////////////////////////////////////////// // Evals ////////////////////////////////////////////////////////////////////////// /** * Call "eval" operation to evaluate a vendor specific * expression on the server: * - SkySpark: any Axon expression * * Raise CallErrException if the server raises an exception. */ public HGrid eval(string expr) { HGridBuilder b = new HGridBuilder(); b.addCol("expr"); b.addRow(new HVal[] { HStr.make(expr) }); HGrid req = b.toGrid(); return(call("eval", req)); }
public void testAdd() { HDict dict = new HDictBuilder().add("x").add("y").toDict(); dict.Add("z", HStr.make("z")); Assert.AreEqual(3, dict.Size); Assert.AreEqual(HMarker.VAL, dict["x"]); Assert.AreEqual(HMarker.VAL, dict["y"]); Assert.AreEqual(HStr.make("z"), dict["z"]); }
public void testToArray() { HDict a = new HDictBuilder().add("x").add("y", "str").toDict(); var array = a.ToArray(); Assert.AreEqual(2, array.Length); Assert.AreEqual("x", array[0].Key); Assert.AreEqual(HMarker.VAL, array[0].Value); Assert.AreEqual("y", array[1].Key); Assert.AreEqual(HStr.make("str"), array[1].Value); }
public void testToArray() { var row = BuildRows(new[] { "x", "y" }, new HVal[] { HMarker.VAL, HStr.make("str") }).First(); var array = row.ToArray(); Assert.AreEqual(2, array.Length); Assert.AreEqual("x", array[0].Key); Assert.AreEqual(HMarker.VAL, array[0].Value); Assert.AreEqual("y", array[1].Key); Assert.AreEqual(HStr.make("str"), array[1].Value); }
protected override HGrid onReadAll(String filter, int limit) { HGridBuilder b = new HGridBuilder(); b.addCol("filter"); b.addCol("limit"); b.addRow(new HVal[] { HStr.make(filter), HNum.make(limit) }); HGrid req = b.toGrid(); return(call("read", req)); }
/** * Convenience for "evalAll(HGrid, checked)". */ public HGrid[] evalAll(string[] exprs, bool bChecked) { HGridBuilder b = new HGridBuilder(); b.addCol("expr"); for (int i = 0; i < exprs.Length; ++i) { b.addRow(new HVal[] { HStr.make(exprs[i]) }); } return(evalAll(b.toGrid(), bChecked)); }
////////////////////////////////////////////////////////////////////////// // History ////////////////////////////////////////////////////////////////////////// /** * Read history time-series data for given record and time range. The * items returned are exclusive of start time and inclusive of end time. * Raise exception if id does not map to a record with the required tags * "his" or "tz". The range may be either a String or a HDateTimeRange. * If HTimeDateRange is passed then must match the timezone configured on * the history record. Otherwise if a String is passed, it is resolved * relative to the history record's timezone. */ public override HGrid hisRead(HRef id, object range) { HGridBuilder b = new HGridBuilder(); b.addCol("id"); b.addCol("range"); b.addRow(new HVal[] { id, HStr.make(range.ToString()) }); HGrid req = b.toGrid(); HGrid res = call("hisRead", req); return(res); }
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 Task <HGrid> readAllAsync(string filter, int limit) { HGridBuilder b = new HGridBuilder(); b.addCol("filter"); if (limit > 0) { b.addCol("limit"); b.addRow(new HVal[] { HStr.make(filter), HNum.make(limit) }); } else { b.addRow(new HVal[] { HStr.make(filter) }); } HGrid req = b.toGrid(); return(CallAsync("read", req, "text/zinc")); }
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); } }
////////////////////////////////////////////////////////////////////////// // PointWrite ////////////////////////////////////////////////////////////////////////// /** * Write to a given level of a writable point, and return the current status * of a writable point's priority array (see pointWriteArray()). * * @param id Ref identifier of writable point * @param level Number from 1-17 for level to write * @param val value to write or null to auto the level * @param who optional username performing the write, otherwise user dis is used * @param dur Number with duration unit if setting level 8 */ public HGrid pointWrite(HRef id, int level, string who, HVal val, HNum dur) { HGridBuilder b = new HGridBuilder(); b.addCol("id"); b.addCol("level"); b.addCol("who"); b.addCol("val"); b.addCol("duration"); b.addRow(new HVal[] { id, HNum.make(level), HStr.make(who), val, dur }); HGrid req = b.toGrid(); HGrid res = call("pointWrite", req); return(res); }
public void testRemove() { var row = BuildRows(new[] { "x", "y" }, new HVal[] { HMarker.VAL, HStr.make("y") }).First(); Assert.ThrowsException <InvalidOperationException>(() => row.Remove("y")); }
public void testCompare() { Assert.IsTrue(HStr.make("abc").CompareTo(HStr.make("z")) < 0); Assert.AreEqual(HStr.make("Foo").CompareTo(HStr.make("Foo")), 0); }
public void testZinc() { verifyZinc(HStr.make("hello"), "\"hello\""); verifyZinc(HStr.make("_ \\ \" \n \r \t \u0011 _"), "\"_ \\\\ \\\" \\n \\r \\t \\u0011 _\""); verifyZinc(HStr.make("\u0abc"), "\"\u0abc\""); }
public void testHex() { // Changed test - unicode code must be valid not random like original test. - this is "NA" Assert.IsTrue(read("\"[\\u004e \\u0041]\"").hequals(HStr.make("[\u004e \u0041]"))); Assert.IsTrue(read("\"[\\u004E \\u0041]\"").hequals(HStr.make("[\u004E \u0041]"))); }
public void testEquality() { Assert.IsTrue(HStr.make("a").hequals(HStr.make("a"))); Assert.IsFalse(HStr.make("a").hequals(HStr.make("b"))); Assert.IsTrue(HStr.make("").hequals(HStr.make(""))); }
public void testStr() { verifyParse("x==\"hi\"", HFilter.eq("x", HStr.make("hi"))); verifyParse("x!=\"\\\"hi\\\"\"", HFilter.ne("x", HStr.make("\"hi\""))); verifyParse("x==\"_\\u00a3_\\n_\"", HFilter.eq("x", HStr.make("_\u00a3_\n_"))); // Was abcd but changed to valid unicode pound }