public void TestXString()
 {
     VerifyZinc(new HaystackXString("hello", "Type"), "Type(\"hello\")");
     VerifyZinc(new HaystackXString("\u0abc", "Type"), "Type(\"\u0abc\")");
     Assert.IsTrue(ZincReader.ReadValue <HaystackXString>("Type(\"[\\u004e \\u0041]\")").Equals(new HaystackXString("[\u004e \u0041]", "Type")));
     Assert.IsTrue(ZincReader.ReadValue <HaystackXString>("Type(\"[\\u004E \\u0041]\")").Equals(new HaystackXString("[\u004E \u0041]", "Type")));
 }
        void VerifyGrid(string str, HaystackDictionary meta, object[] cols, HaystackValue[][] rows)
        {
            // normalize nulls
            if (meta == null)
            {
                meta = new HaystackDictionary();
            }
            for (int i = 0; i < cols.Length; ++i)
            {
                if (cols[i] == null)
                {
                    cols[i] = new HaystackDictionary();
                }
            }

            // read from zinc
            var grid = new ZincReader(str).ReadValue <HaystackGrid>();

            VerifyGridEquals(grid, meta, cols, rows);

            // write grid and verify we can parse that too
            string writeStr  = ZincWriter.ToZinc(grid);
            var    writeGrid = new ZincReader(writeStr).ReadValue <HaystackGrid>();

            VerifyGridEquals(writeGrid, meta, cols, rows);
        }
        public void TestDateTime()
        {
            TimeZoneInfo tziNewYork;

            try
            {
                tziNewYork = TimeZoneConverter.TZConvert.GetTimeZoneInfo("Eastern Standard Time");
            }
            catch
            {
                // Ignore issues with locally installed timezones.
                return;
            }
            var tz = new HaystackTimeZone("New_York");
            HaystackDateTime ts;

            ts = new HaystackDateTime(new DateTime(634429600180690000L), tz);
            VerifyZinc(ts, "2011-06-06T12:26:58.069-05:00 New_York");
            Assert.AreEqual(ts.TimeZone.Name, "New_York");
            Assert.AreEqual(ts.TimeZone.TimeZoneInfo, tziNewYork);

            // convert back to millis
            ts = ZincReader.ReadValue <HaystackDateTime>("2011-06-06T12:26:58.069-04:00 New_York");
            Assert.AreEqual(ts.Value.Ticks, 634429600180690000L);

            // different timezones
            ts = new HaystackDateTime(new DateTime(630850574400000000L), new HaystackTimeZone("New_York"));
            VerifyZinc(ts, "2000-02-02T03:04:00-05:00 New_York");
            ts = new HaystackDateTime(new DateTime(630850754400000000L), new HaystackTimeZone("UTC"));
            VerifyZinc(ts, "2000-02-02T08:04:00Z UTC");
            ts = new HaystackDateTime(new DateTime(630851042400000000L), new HaystackTimeZone("Taipei"));
            VerifyZinc(ts, "2000-02-02T16:04:00+08:00 Taipei");
        }
        public HttpClientMockBuilder WithReadAsync(string expectedFilter, HaystackGrid response)
        {
            _requestHandlers.Add(async request =>
            {
                var relativeUri = _baseUri.MakeRelativeUri(request.RequestUri);
                if (relativeUri.OriginalString != "read")
                {
                    return(null);
                }
                var reader = new ZincReader(await request.Content.ReadAsStringAsync());
                var grid   = reader.ReadValue <HaystackGrid>();
                var filter = grid.Rows.First().Get <HaystackString>("filter").Value;
                if (filter != expectedFilter)
                {
                    return(null);
                }
                using (var stream = new MemoryStream())
                    using (var streamWriter = new StreamWriter(stream))
                    {
                        var writer = new ZincWriter(streamWriter);
                        writer.WriteValue(response);
                        streamWriter.Flush();
                        stream.Position = 0;
                        return(new HttpResponseMessage
                        {
                            Content = new StringContent(await new StreamReader(stream).ReadToEndAsync()),
                        });
                    }
            });

            return(this);
        }
 public void TestString()
 {
     VerifyZinc(new HaystackString("hello"), "\"hello\"");
     VerifyZinc(new HaystackString("_ \\ \" \n \r \t \u0011 _"), "\"_ \\\\ \\\" \\n \\r \\t \\u0011 _\"");
     VerifyZinc(new HaystackString("\u0abc"), "\"\u0abc\"");
     Assert.IsTrue(ZincReader.ReadValue("\"[\\u004e \\u0041]\"").Equals(new HaystackString("[\u004e \u0041]")));
     Assert.IsTrue(ZincReader.ReadValue("\"[\\u004E \\u0041]\"").Equals(new HaystackString("[\u004E \u0041]")));
 }
        public void readGrid_withTagDef()
        {
            var reader = new ZincReader(
                @"ver:""3.0""
id,def,doc,mod
@p:struktonLibrary:r:25b81501-75003ad2 ""struktonActivePointOnly"",^struktonActivePointOnly,""Import only active points"",2020-01-20T07:36:33.162Z");
            var grid = reader.ReadValue <HaystackGrid>();

            Assert.IsTrue(grid.Row(0).Get("def") is HaystackDefinition);
        }
 public void TestBadUri()
 {
     string[] badZincs = new string[]
     {
         "`no end",
         "`new\nline`"
     };
     foreach (string zinc in badZincs)
     {
         ZincReader.ReadValue(zinc);
     }
 }
 public void TestBadDate()
 {
     string[] badDateZinc =
     {
         "2003-xx-02",
         "2003-02",
         "2003-02-xx"
     };
     foreach (string strCurZinc in badDateZinc)
     {
         ZincReader.ReadValue(strCurZinc);
     }
 }
 public void TestBadDateTime()
 {
     string[] badzincdt = new string[] {
         "2000-02-02T03:04:00-0x:00 New_York",
         "2000-02-02T03:04:00-05 New_York",
         "2000-02-02T03:04:00-05:!0 New_York",
         "2000-02-02T03:04:00-05:00",
         "2000-02-02T03:04:00-05:00 @"
     };
     foreach (string zinc in badzincdt)
     {
         ZincReader.ReadValue(zinc);
     }
 }
 public void TestBadTime()
 {
     string[] badZincs = new string[]
     {
         "13:xx:00",
         "13:45:0x",
         "13:45:00.",
         "13:45:00.x"
     };
     foreach (string zinc in badZincs)
     {
         ZincReader.ReadValue(zinc);
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Use vendor specific logic using the "eval" call.
        /// </summary>
        /// <param name="req">Grid with expressions in the "expr" field.</param>
        /// <returns>Grid of results per expression.</returns>
        public async Task <HaystackGrid[]> EvalAllAsync(HaystackGrid req)
        {
            var requestZinc = ZincWriter.ToZinc(req);
            var resultZinc  = await PostStringAsync("evalAll", requestZinc, "text/zinc");

            var result = new ZincReader(resultZinc).ReadGrids().ToArray();

            for (int i = 0; i < result.Length; ++i)
            {
                if (result[i].IsError())
                {
                    throw new HaystackException(result[i]);
                }
            }
            return(result);
        }
        public void TestNumber()
        {
            VerifyZinc(new HaystackNumber(123), "123");
            VerifyZinc(new HaystackNumber(123.4, "m/s"), "123.4m/s");
            VerifyZinc(new HaystackNumber(9.6, "m/s"), "9.6m/s");
            VerifyZinc(new HaystackNumber(-5.2, "\u00b0F"), "-5.2\u00b0F");
            VerifyZinc(new HaystackNumber(23, "%"), "23%");
            VerifyZinc(new HaystackNumber(2.4e-3, "fl_oz"), "0.0024fl_oz");
            VerifyZinc(new HaystackNumber(2.4e5, "$"), "240000$");
            Assert.IsTrue(ZincReader.ReadValue("1234.56fl_oz").Equals(new HaystackNumber(1234.56, "fl_oz")));
            Assert.IsTrue(ZincReader.ReadValue("0.000028fl_oz").Equals(new HaystackNumber(0.000028, "fl_oz")));

            // specials
            VerifyZinc(new HaystackNumber(double.NegativeInfinity), "-INF");
            VerifyZinc(new HaystackNumber(double.PositiveInfinity), "INF");
            VerifyZinc(new HaystackNumber(double.NaN), "NaN");

            // verify units never serialized for special values
            Assert.AreEqual(ZincWriter.ToZinc(new HaystackNumber(double.NaN, "ignore")), "NaN");
            Assert.AreEqual(ZincWriter.ToZinc(new HaystackNumber(double.PositiveInfinity, "%")), "INF");
            Assert.AreEqual(ZincWriter.ToZinc(new HaystackNumber(double.NegativeInfinity, "%")), "-INF");
        }
Exemplo n.º 13
0
 public static HTime make(string s) => M.Map(ZincReader.ReadValue <HaystackTime>(s));
 protected void VerifyZinc(HaystackValue val, string s)
 {
     Assert.AreEqual(s, ZincWriter.ToZinc(val));
     Assert.IsTrue(ZincReader.ReadValue(s).Equals(val));
 }
Exemplo n.º 15
0
 protected HVal read(string s)
 {
     return(M.Map(ZincReader.ReadValue(s)));
 }
 public void TestBadStringUnicodeEsc()
 {
     ZincReader.ReadValue("\"\\u1x34\"");
 }
Exemplo n.º 17
0
 public static HDef make(string val) => M.Map(ZincReader.ReadValue <HaystackDefinition>(val));
 public static HDateTime make(string s, bool bException)
 => M.Checked(() => M.Map(ZincReader.ReadValue <HaystackDateTime>(s)), bException);
Exemplo n.º 19
0
 public static HCoord make(string s) => M.Map(ZincReader.ReadValue <HaystackCoordinate>(s));
 public void TestStringNoEndQuote()
 {
     ZincReader.ReadValue("\"end...");
 }