Ejemplo n.º 1
0
        public void TestConditionParserInvalidConditions()
        {
            var conditionTests = new string[]
            {
                "$123",                     // Property names cannot start with a number
                "$_123",                    // Property names cannot start with an underscore
                "$1.23",                    // Property names cannot contain special characters
                "horizontal||$Prop[gt]1000",// OR is '|', not '||'
                "$Prop==1||$Prop==2"        // OR is '|', not '||'
            };

            var parseContext = new ParseContext();
            ConditionParser parser = new ConditionParser(new ConditionFormat() { StatesUnderscored = false });
            foreach (var test in conditionTests)
            {
                try
                {
                    parser.Parse(test, parseContext);
                    Assert.Fail("Parsing {0} succeeded", test);
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 2
0
        public void TestConditionParserValidConditions()
        {
            var horizontal = new ConditionTreeLeaf(ConditionType.State, "horizontal", ConditionComparison.Equal, new PropertyUnion(true));
            var propertyEq1 = new ConditionTreeLeaf(ConditionType.Property, "Property", ConditionComparison.Equal, new PropertyUnion(1));

            var conditionTests = new Dictionary<string, IConditionTreeItem>()
            {
                { "horizontal", horizontal},
                { "$Property==1", propertyEq1},
                { "horizontal|$Property==1", new ConditionTree(ConditionTree.ConditionOperator.OR, horizontal, propertyEq1)},
                { "horizontal,$Property==1", new ConditionTree(ConditionTree.ConditionOperator.AND, horizontal, propertyEq1)}
            };

            var parseContext = new ParseContext();
            parseContext.PropertyTypes.Add(new KeyValuePair<string,PropertyUnionType>("Property", PropertyUnionType.Double));

            ConditionParser parser = new ConditionParser(new ConditionFormat() { StatesUnderscored = false });
            foreach(var test in conditionTests)
            {
                var parsed = parser.Parse(test.Key, parseContext);
                Assert.AreEqual(test.Value, parsed);
            }
        }