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); }
/// <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(" ", "")); } }
/// <summary> /// Tests the enum property on the specified map /// </summary> /// <param name="parent"></param> /// <param name="key"></param> /// <param name="expectedFullValue"></param> public static void TestEnumProperty(MapValue parent, string key, string expectedFullValue) { // Test presense of property ValueNode valueNode; Assert.IsTrue(parent.TryGetValue(key, out valueNode)); Assert.IsNotNull(valueNode); // Test value of property TestEnumValue(valueNode, expectedFullValue); }
/// <summary> /// Tests the primitive property on the specified map /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parent"></param> /// <param name="key"></param> /// <param name="expectedValue"></param> public static void TestPrimitiveProperty <T>(MapValue parent, string key, T expectedValue) { // Test presense of property ValueNode valueNode; Assert.IsTrue(parent.TryGetValue(key, out valueNode)); Assert.IsNotNull(valueNode); // Test value of property TestPrimitiveValue(valueNode, expectedValue); }
/// <summary> /// Tests the primitive typed property on the specified map /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parent"></param> /// <param name="key"></param> /// <param name="value"></param> public static void TestPrimitiveTypedProperty <T>(MapValue parent, string key, string typeName, T value) { // Test presense of property ValueNode valueNode; Assert.IsTrue(parent.TryGetValue(key, out valueNode)); Assert.IsNotNull(valueNode); // Test value of property TestPrimitiveValue(valueNode, value); Assert.AreEqual(typeName, valueNode.TypeName); }
/// <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]); } }