public void testEquality() { HBin bin1 = HBin.make("text/plain"); HBin bin2 = HBin.make("text/plain"); HBin bin3 = HBin.make("text/xml"); // Can't user AreEqual or AreNotEqual as these are objects and that is doing // a reference check not a logical value test because HBin does not implement // IComparable Interface - Haystack equals determines equality for this library purpose //e.g this will fail = Assert.AreEqual(HBin.make("text/plain"), HBin.make("text/plain")); Assert.IsTrue(bin1.hequals(bin2)); Assert.IsFalse(bin1.hequals(bin3)); }
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], "}"); }
private HBin parseBinObsolete() { StringBuilder s = new StringBuilder(); while (m_tokCur != HaystackToken.rparen && m_tokCur != HaystackToken.eof) { if (m_curVal == null) { s.Append(m_tokCur.Symbol); } else { s.Append(m_curVal); } consume(); } consume(HaystackToken.rparen); return(HBin.make(s.ToString())); }