public void testZinc()
        {
            verifyZinc(
                HDict.Empty,
                "{}");
            verifyZinc(
                new HDictBuilder().add("foo_12").toDict(),
                "{foo_12}");
            verifyZinc(
                new HDictBuilder().add("fooBar", 123, "ft").toDict(),
                "{fooBar:123ft}");
            verifyZinc(
                new HDictBuilder().add("dis", "Bob").add("bday", HDate.make(1970, 6, 3)).add("marker").toDict(),
                "{dis:\"Bob\" bday:1970-06-03 marker}");

            // nested dict
            verifyZinc(
                new HDictBuilder().add("auth", HDict.Empty).toDict(),
                "{auth:{}}");
            verifyZinc(
                new HDictBuilder().add("auth",
                                       new HDictBuilder().add("alg", "scram").add("c", 10000).add("marker").toDict()
                                       ).toDict(),
                "{auth:{alg:\"scram\" c:10000 marker}}");

            // nested list
            verifyZinc(
                new HDictBuilder().add("arr", HList.make(new HVal[] { HNum.make(1.0), HNum.make(2), HNum.make(3) }))
                .add("x").toDict(),
                "{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
        }
Esempio n. 2
0
        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
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 public void testEmpty()
 {
     Assert.IsTrue(HList.EMPTY.hequals(HList.make(new List <HVal>())));
     Assert.IsTrue(HList.EMPTY.hequals(HList.make(new HVal[0])));
     Assert.AreEqual(HList.EMPTY.size(), 0);
     try
     {
         HList.EMPTY.get(0);
         Assert.Fail();
     }
     catch (Exception)
     {
         Assert.IsTrue(true);
     }
 }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        private HList parseList()
        {
            List <HVal> arr = new List <HVal>();

            consume(HaystackToken.lbracket);
            while (m_tokCur != HaystackToken.rbracket && m_tokCur != HaystackToken.eof)
            {
                HVal val = parseVal();
                arr.Add(val);
                if (m_tokCur != HaystackToken.comma)
                {
                    break;
                }
                consume(HaystackToken.comma);
            }
            consume(HaystackToken.rbracket);
            return(HList.make(arr));
        }