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); } }
public void testEmpty() { // Instance Empty HDict tags = new HDictBuilder().toDict(); Assert.AreEqual(tags, HDict.Empty); // size Assert.AreEqual(tags.size(), 0); Assert.IsTrue(tags.isEmpty()); // missing tag Assert.IsFalse(tags.has("foo")); Assert.IsTrue(tags.missing("foo")); Assert.IsNull(tags.get("foo", false)); }
public void testCheckedExplicitMissing() { HDict tags = new HDictBuilder().toDict(); tags.get("foo", true); }