public void testUri() { HaystackToken uri = HaystackToken.uri; verifyToks("`http://foo/`", new object[] { uri, HUri.make("http://foo/") }); verifyToks("`_ \\n \\\\ \\`_`", new object[] { uri, HUri.make("_ \n \\\\ `_") }); }
private HaystackToken uri() { if (m_cCur < 0) { err("Unexpected end of uri"); } consume('`'); StringBuilder s = new StringBuilder(); while (true) { if ((m_cCur < (int)char.MinValue) || (m_cCur > (int)char.MaxValue)) { err("Unexpected character in uri at a value of " + m_cCur.ToString()); } if ((char)m_cCur == '`') { consume('`'); break; } if (m_cCur == m_iEOF || (char)m_cCur == '\n') { err("Unexpected end of uri"); } if ((char)m_cCur == '\\') { switch ((char)m_cPeek) { case ':': case '/': case '?': case '#': case '[': case ']': case '@': case '\\': case '&': case '=': case ';': s.Append((char)m_cCur); s.Append((char)m_cPeek); consume(); consume(); break; default: s.Append(escape()); break; } } else { s.Append((char)(m_cCur)); consume(); } } m_val = HUri.make(s.ToString()); return(HaystackToken.uri); }
public void testZinc() { verifyZinc(HUri.make("http://foo.com/f?q"), "`http://foo.com/f?q`"); verifyZinc(HUri.make("a$b"), "`a$b`"); verifyZinc(HUri.make("a`b"), "`a\\`b`"); verifyZinc(HUri.make("http\\:a\\?b"), "`http\\:a\\?b`"); verifyZinc(HUri.make("\u01ab.txt"), "`\u01ab.txt`"); }
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 testCompare() { Assert.IsTrue(HUri.make("abc").CompareTo(HUri.make("z")) < 0); Assert.AreEqual(HUri.make("Foo").CompareTo(HUri.make("Foo")), 0); }
public void testEquality() { Assert.IsTrue(HUri.make("a").hequals(HUri.make("a"))); Assert.IsFalse(HUri.make("a").hequals(HUri.make("b"))); Assert.IsTrue(HUri.make("") == HUri.make("")); }
public void testUri() { verifyParse("ref==`http://foo/?bar`", HFilter.eq("ref", HUri.make("http://foo/?bar"))); verifyParse("ref->x==`file name`", HFilter.eq("ref->x", HUri.make("file name"))); verifyParse("ref == `foo bar`", HFilter.eq("ref", HUri.make("foo bar"))); }