Exemplo n.º 1
0
        public void AddArrayValue(bool value)
        {
            JsonBool jsonBool = new JsonBool(value);
            var      array    = actualObject.Arrays.ToArray();

            array[array.Length - 1].Values.Add(jsonBool);
        }
Exemplo n.º 2
0
        public static void JsonBoolMethodsTest()
        {
            JsonBool boolA = new JsonBool(false), boolB = false, boolC = true;
            object   objTrue = true, objFalse = false;

            Assert.True(boolA == boolB);
            Assert.False(boolA == boolC);
            Assert.False(boolA != boolB);
            Assert.True(boolA != boolC);
            Assert.True((JsonBool)null == null);

            Assert.True(boolA.Equals((object)boolA));
            Assert.True(boolA.Equals((object)boolB));
            Assert.False(boolC.Equals((object)boolA));
            Assert.True(boolA.Equals(boolA));
            Assert.True(boolA.Equals(boolB));
            Assert.False(boolC.Equals(boolA));
            Assert.True(boolC.Equals(objTrue));
            Assert.False(boolC.Equals(objFalse));
            Assert.False(boolC.Equals((object)null));
            Assert.False(boolC.Equals((JsonBool)null));

            Assert.True(boolC);
            Assert.False(boolB);

            Assert.Equal(true.GetHashCode(), boolC.GetHashCode());
            Assert.Equal(false.GetHashCode(), boolA.GetHashCode());
        }
Exemplo n.º 3
0
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        internal virtual JsonElement CreateJsonElement()
        {
            JsonElement target = new JsonBool {
                Value = true
            };

            return(target);
        }
Exemplo n.º 4
0
        private void assertBoolParseFail(string json)
        {
            Assert.Throws <JsonParseException>(() => JsonBool.Parse(json));
            JsonBool val;

            Assert.IsFalse(JsonBool.TryParse(json, out val));
            Assert.IsNull(val);
        }
        public JsonData SaveToJson()
        {
            JsonObject obj = new JsonObject();

            obj["Pulse"]       = new JsonInteger(Pulse);
            obj["Enable"]      = new JsonBool(Enable);
            obj["Pulse Range"] = PulseRange.SaveToJson();
            return(obj);
        }
Exemplo n.º 6
0
        private void assertBoolParseSucc(string json, bool val)
        {
            JsonBool t = null;

            Assert.DoesNotThrow(() => { t = JsonBool.Parse(json); });
            Assert.AreEqual(val, (bool)t);
            Assert.IsTrue(JsonBool.TryParse(json, out t));
            Assert.AreEqual(val, (bool)t);
        }
Exemplo n.º 7
0
        public void ValueTest()
        {
            var target = new JsonBool {
                Value = false
            };
            bool actual = target.Value;

            Assert.AreEqual(false, actual);
            target.Value = true;
            actual       = target.Value;
            Assert.AreEqual(true, actual);
        }
Exemplo n.º 8
0
        public void ToStringTest()
        {
            var    target   = new JsonBool();
            string expected = "false";
            string actual   = target.ToString();

            Assert.AreEqual(expected, actual);
            target.Value = true;
            expected     = "true";
            actual       = target.ToString();
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 9
0
        public void ParseLiteral()
        {
            Assert.IsFalse(JsonBool.Parse("false").Value);
            Assert.IsTrue(JsonBool.Parse("true").Value);
            Assert.AreEqual("false", new JsonBool(false).ToString());
            Assert.AreEqual("true", new JsonBool(true).ToString());
            Assert.AreEqual("id", JsonText.Parse("\"id\"").Value);
            Assert.AreEqual(89, JsonNumber.Parse("89").Byte);
            Assert.AreEqual("\"{<guid>}\"", JsonText.Parse("\"\\\"{<guid>}\\\"\"").Value);
            Assert.AreEqual(-0.5m, JsonNumber.Parse("-0.5").Decimal);
            Assert.AreEqual(500d, JsonNumber.Parse("+0.5E3").Double);
            Assert.AreEqual(0.0005d, JsonNumber.Parse("0.5E-3").Double);
            JsonObject   o    = new JsonObject(("name", new JsonText("Lars \"kodekarl\" Hammer")));
            const string json = "{\"name\":\"Lars \\\"kodekarl\\\" Hammer\"}";

            Assert.AreEqual(json, o.ToString());
            Assert.AreEqual(json, JsonValue.Parse(json).ToString());
            Assert.AreEqual(json, JsonValue.Parse(o.Format()).ToString());
        }
Exemplo n.º 10
0
        private JsonElement ParseKeyword()
        {
            JsonElement element;
            string      test;

            switch (_source.Current)
            {
            case 't':
                test    = "true";
                element = new JsonBool {
                    Value = true
                };
                break;

            case 'f':
                test    = "false";
                element = new JsonBool {
                    Value = false
                };
                break;

            case 'n':
                test    = "null";
                element = new JsonNull();
                break;

            default:
                throw new Exception("Unknown keyword in JSON.");
            }

            // Compares the subsequent values from _source against the matching
            // character of the test string.
            if (test.Any(t => _source.Next() != t))
            {
                throw new Exception("Unknown keyword in JSON.");
            }

            return(element);
        }
Exemplo n.º 11
0
        public void JsonBoolConstructorTest()
        {
            var target = new JsonBool();

            Assert.IsFalse(target.Value);
        }
Exemplo n.º 12
0
        public void EqualsObject_SameInstance_True()
        {
            JsonBool obj = true;

            EqualityTester.AssertEquals <JsonBool>(obj, obj);
        }
Exemplo n.º 13
0
        public void EqualsJsonBool_SameInstance_True()
        {
            JsonBool obj = true;

            EqualityTester.AssertEquals(obj, obj);
        }
Exemplo n.º 14
0
 static void AssertInequalityFalse(JsonBool lhs, JsonBool rhs)
 => Assert.IsFalse(lhs != rhs);
Exemplo n.º 15
0
 static void AssertInequalityTrue(JsonBool lhs, JsonBool rhs)
 => Assert.IsTrue(lhs != rhs);
Exemplo n.º 16
0
 static void AssertEqualityTrue(JsonBool lhs, JsonBool rhs)
 => Assert.IsTrue(lhs == rhs);