Ejemplo n.º 1
0
        public void TestExponentFail()
        {
            using (StringReader rdr = new StringReader("123E "))
                using (PushbackReader pbr = new PushbackReader(rdr, 1))
                {
                    try
                    {
                        JSONNumber number = new JSONNumber();
                        number.Read("$", pbr);

                        Assert.Fail("Exception expected");
                    }
                    catch (JSONException)
                    {
                    }
                }
            using (StringReader rdr = new StringReader("123E+ "))
                using (PushbackReader pbr = new PushbackReader(rdr, 1))
                {
                    try
                    {
                        JSONNumber number = new JSONNumber();
                        number.Read("$", pbr);

                        Assert.Fail("Exception expected");
                    }
                    catch (JSONException)
                    {
                    }
                }
        }
Ejemplo n.º 2
0
        public void TestDecimal()
        {
            using (StringReader rdr = new StringReader("-123.456 "))
                using (PushbackReader pbr = new PushbackReader(rdr, 1))
                {
                    JSONNumber number = new JSONNumber();
                    number.Read("$", pbr);

                    Assert.AreEqual("-123.456", number.Value.ToString());
                }
        }
Ejemplo n.º 3
0
        public void TestExponent()
        {
            using (StringReader rdr = new StringReader("123.456E+2 "))
                using (PushbackReader pbr = new PushbackReader(rdr, 1))
                {
                    JSONNumber number = new JSONNumber();
                    number.Read("$", pbr);

                    Assert.AreEqual("12345.6", number.Value.ToString());
                }

            using (StringReader rdr = new StringReader("123.456E-2 "))
                using (PushbackReader pbr = new PushbackReader(rdr, 1))
                {
                    JSONNumber number = new JSONNumber();
                    number.Read("$", pbr);

                    Assert.AreEqual("1.23456", number.Value.ToString());
                }

            using (StringReader rdr = new StringReader("123.456E2 "))
                using (PushbackReader pbr = new PushbackReader(rdr, 1))
                {
                    JSONNumber number = new JSONNumber();
                    number.Read("$", pbr);

                    Assert.AreEqual("12345.6", number.Value.ToString());
                }

            using (StringReader rdr = new StringReader("123e2 "))
                using (PushbackReader pbr = new PushbackReader(rdr, 1))
                {
                    JSONNumber number = new JSONNumber();
                    number.Read("$", pbr);

                    Assert.AreEqual("12300", number.Value.ToString());
                }
        }