Exemple #1
0
        public void Array_Empty()
        {
            // Parse
            Node node = TaronParser.Parse($"TestArray [ ]");

            // Test type and size
            Assert.IsInstanceOfType(node, typeof(MapValue));
            MapValue mapNode = node.As <MapValue>();

            Assert.IsNotNull(mapNode);
            Assert.AreEqual(1, mapNode.Count);

            // Retrieve the array
            ValueNode arrayValueNode;

            Assert.IsTrue(mapNode.TryGetValue("TestArray", out arrayValueNode));
            Assert.IsNotNull(arrayValueNode);
            Assert.IsInstanceOfType(arrayValueNode, typeof(ArrayValue));
            ArrayValue arrayValue = arrayValueNode.As <ArrayValue>();

            Assert.IsNotNull(arrayValue);

            // Test it's content
            Assert.AreEqual(0, arrayValue.Count);
        }
Exemple #2
0
        public void Basic_Enumerations()
        {
            // Iterate each test value
            string[] testValues = new string[] { "A.B", "Test.Thing", "   Whitespace  .   Yep " };
            foreach (string testValue in testValues)
            {
                // Parse
                Node node = TaronParser.Parse($"TestEnum = {testValue}");

                // Test type and size
                Assert.IsInstanceOfType(node, typeof(MapValue));
                MapValue mapNode = node.As <MapValue>();
                Assert.IsNotNull(mapNode);
                Assert.AreEqual(1, mapNode.Count);

                // Test property
                Assert.AreEqual("TestEnum", mapNode.Keys.First());
            }

            // Test error on invalid enums
            Exception ex = null;

            try
            {
                TaronParser.Parse("TestEnum = A");
            }
            catch (Exception theEx)
            {
                ex = theEx;
            }
            finally
            {
                Assert.IsNotNull(ex);
            }
        }
Exemple #3
0
        /// <summary>
        /// Tests the specified array of enums
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="testValues"></param>
        private void TestEnumArray(string[] testValues)
        {
            // Parse
            Node node = TaronParser.Parse($"TestArray [ {string.Join(", ", testValues)} ]");

            // Test type and size
            Assert.IsInstanceOfType(node, typeof(MapValue));
            MapValue mapNode = node.As <MapValue>();

            Assert.IsNotNull(mapNode);
            Assert.AreEqual(1, mapNode.Count);

            // Retrieve the array
            ValueNode arrayValueNode;

            Assert.IsTrue(mapNode.TryGetValue("TestArray", out arrayValueNode));
            Assert.IsNotNull(arrayValueNode);
            Assert.IsInstanceOfType(arrayValueNode, typeof(ArrayValue));
            ArrayValue arrayValue = arrayValueNode.As <ArrayValue>();

            Assert.IsNotNull(arrayValue);

            // Test it's content
            Assert.AreEqual(testValues.Length, arrayValue.Count);
            for (int i = 0; i < testValues.Length; i++)
            {
                TestUtils.TestEnumValue(arrayValue[i], testValues[i].Replace(" ", ""));
            }
        }
Exemple #4
0
        public void Basic_Group()
        {
            // Parse
            Node node = TaronParser.Parse(TestUtils.ReusableMapTest);

            // Test type and size
            Assert.IsInstanceOfType(node, typeof(MapValue));
            MapValue mapNode = node.As <MapValue>();

            Assert.IsNotNull(mapNode);

            // Test content
            TestUtils.TestReusableMap(mapNode);
        }
Exemple #5
0
        public void Translator_BasicMap_FromModel_ToStruct()
        {
            // Parse the basic map
            Node node = TaronParser.Parse(TestUtils.ReusableMapTest);

            Assert.IsNotNull(node);
            MapValue mapValue = node.As <MapValue>();

            Assert.IsNotNull(mapValue);

            // Translate to a strongly-typed struct
            var t     = new TaronTranslator(TaronTranslatorOptions.Default);
            var strct = (TestUtils.ReusableMapStruct)t.Deserialise(typeof(TestUtils.ReusableMapStruct), mapValue);

            strct.Test();
        }
Exemple #6
0
        public void Basic_Empty()
        {
            // Test empty string
            Assert.IsNull(TaronParser.Parse(""));

            // Test variations of whitespace
            Assert.IsNull(TaronParser.Parse("\t"));
            Assert.IsNull(TaronParser.Parse(" "));
            Assert.IsNull(TaronParser.Parse("\t "));
            Assert.IsNull(TaronParser.Parse(" \t"));
            Assert.IsNull(TaronParser.Parse("\t \n"));
            Assert.IsNull(TaronParser.Parse(" \t\n"));
            Assert.IsNull(TaronParser.Parse("\t \n\t"));
            Assert.IsNull(TaronParser.Parse("\t \n "));
            Assert.IsNull(TaronParser.Parse("\t \n\t "));
            Assert.IsNull(TaronParser.Parse(" \t\n \t"));
        }
Exemple #7
0
        /// <summary>
        /// Tests the specified array
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="testValues"></param>
        private void TestArray <T>(T[] testValues)
        {
            // Parse
            Node node;

            if (typeof(T) == typeof(string))
            {
                node = TaronParser.Parse($"TestArray [ {string.Join(", ", testValues.Select(s => $"\"{s}\"")) } ]");
            }
            else if (typeof(T) == typeof(bool))
            {
                node = TaronParser.Parse($"TestArray [ {string.Join(", ", testValues.Select(s => s.ToString().ToLowerInvariant())) } ]");
            }
            else
            {
                node = TaronParser.Parse($"TestArray [ {string.Join(", ", testValues)} ]");
            }

            // Test type and size
            Assert.IsInstanceOfType(node, typeof(MapValue));
            MapValue mapNode = node.As <MapValue>();

            Assert.IsNotNull(mapNode);
            Assert.AreEqual(1, mapNode.Count);

            // Retrieve the array
            ValueNode arrayValueNode;

            Assert.IsTrue(mapNode.TryGetValue("TestArray", out arrayValueNode));
            Assert.IsNotNull(arrayValueNode);
            Assert.IsInstanceOfType(arrayValueNode, typeof(ArrayValue));
            ArrayValue arrayValue = arrayValueNode.As <ArrayValue>();

            Assert.IsNotNull(arrayValue);

            // Test it's content
            Assert.AreEqual(testValues.Length, arrayValue.Count);
            for (int i = 0; i < testValues.Length; i++)
            {
                TestUtils.TestPrimitiveValue(arrayValue[i], testValues[i]);
            }
        }
Exemple #8
0
        public void Basic_Strings()
        {
            // Iterate each test value
            string[] testValues = new string[] { "", "test", " ", "TestString", "\\\"" };
            foreach (string testValue in testValues)
            {
                // Parse
                Node node = TaronParser.Parse($"TestString = \"{testValue}\"");

                // Test type and size
                Assert.IsInstanceOfType(node, typeof(MapValue));
                MapValue mapNode = node.As <MapValue>();
                Assert.IsNotNull(mapNode);
                Assert.AreEqual(1, mapNode.Count);

                // Test property
                Assert.AreEqual("TestString", mapNode.Keys.First());
                TestUtils.TestPrimitiveProperty(mapNode, "TestString", testValue);
            }
        }
Exemple #9
0
        public void Basic_Integers()
        {
            // Iterate each test value
            string[] testValues = new string[] { "0", "10", "5", "3456", "-7", "-0", "-01234", "024" };
            foreach (string testValue in testValues)
            {
                // Parse
                Node node = TaronParser.Parse($"TestNumber = {testValue}");

                // Test type and size
                Assert.IsInstanceOfType(node, typeof(MapValue));
                MapValue mapNode = node.As <MapValue>();
                Assert.IsNotNull(mapNode);
                Assert.AreEqual(1, mapNode.Count);

                // Test property
                Assert.AreEqual("TestNumber", mapNode.Keys.First());
                TestUtils.TestPrimitiveProperty(mapNode, "TestNumber", int.Parse(testValue));
            }
        }
Exemple #10
0
        public void Translator_BasicMap_FromModel_ToDict()
        {
            // Parse the basic map
            Node node = TaronParser.Parse(TestUtils.ReusableMapTest);

            Assert.IsNotNull(node);
            MapValue mapValue = node.As <MapValue>();

            Assert.IsNotNull(mapValue);

            // Translate to weakly-typed dict
            var t    = new TaronTranslator(TaronTranslatorOptions.Default);
            var dict = t.Deserialise(typeof(Dictionary <string, object>), mapValue) as Dictionary <string, object>;

            Assert.IsNotNull(dict);
            Assert.AreEqual(5, dict.Count);
            Assert.AreEqual(10.0, dict["DecimalVal"]);
            Assert.AreEqual(5, dict["IntegerVal"]);
            Assert.AreEqual("thingy", dict["StringVal"]);
            Assert.AreEqual(true, dict["BooleanVal"]);
        }
Exemple #11
0
        public void Basic_Booleans()
        {
            // Iterate each test value
            string[] testValues = new string[] { "true", "false" };
            foreach (string testValue in testValues)
            {
                // Parse
                Node node = TaronParser.Parse($"TestBoolean = {testValue}");

                // Test type and size
                Assert.IsInstanceOfType(node, typeof(MapValue));
                MapValue mapNode = node.As <MapValue>();
                Assert.IsNotNull(mapNode);
                Assert.AreEqual(1, mapNode.Count);

                // Test property
                Assert.AreEqual("TestBoolean", mapNode.Keys.First());
                TestUtils.TestPrimitiveProperty(mapNode, "TestBoolean", bool.Parse(testValue));
            }

            // Test error on invalid booleans
            Exception ex = null;

            try
            {
                TaronParser.Parse("TestBoolean = True");
                TaronParser.Parse("TestBoolean = False");
            }
            catch (Exception theEx)
            {
                ex = theEx;
            }
            finally
            {
                Assert.IsNotNull(ex);
            }
        }
Exemple #12
0
        public void Basic_Decimals()
        {
            // Iterate each test value
            string[] testValues = new string[] { "0.1", "10.2", "5.43", "-400.3", "-0.5", "-0.0" };
            foreach (string testValue in testValues)
            {
                // Parse
                Node node = TaronParser.Parse($"TestNumber = {testValue}");

                // Test type and size
                Assert.IsInstanceOfType(node, typeof(MapValue));
                MapValue mapNode = node.As <MapValue>();
                Assert.IsNotNull(mapNode);
                Assert.AreEqual(1, mapNode.Count);

                // Test property
                Assert.AreEqual("TestNumber", mapNode.Keys.First());
                TestUtils.TestPrimitiveProperty(mapNode, "TestNumber", double.Parse(testValue));
            }

            // Test error on invalid numbers
            Exception ex = null;

            try
            {
                TaronParser.Parse("TestNumber = .2");
            }
            catch (Exception theEx)
            {
                ex = theEx;
            }
            finally
            {
                Assert.IsNotNull(ex);
            }
        }