예제 #1
0
        public void StringValueWithValueOfScopeWithStringOnly_BuildString_StringBuildCorrectly()
        {
            // prepare
            var scope_prototype = new ScopePrototype
            {
                Variables = new HashSet <string> {
                    "model "
                },
            };
            var scope = new Scope(scope_prototype)
            {
                VariableValues = new Dictionary <string, AssignedValue> {
                    { "model", new AssignedValue(JToken.Parse("\"black\"")) }
                }
            };

            var stringValue = new StringValue
            {
                StringComponents = new List <IStringComponent> {
                    new ValueOf {
                        VariableName = "model"
                    },
                }
            };

            // act
            var result = StringValueBuilder.Build(stringValue, scope);

            // validate
            Assert.Equal("black", result);
        }
예제 #2
0
        public void StringValueWithValueOfAndStringsAlternating_BuildString_StringBuildCorrectly()
        {
            // prepare
            var scope_prototype = new ScopePrototype
            {
                Variables = new HashSet <string> {
                    "model "
                },
            };
            var scope = new Scope(scope_prototype)
            {
                VariableValues = new Dictionary <string, AssignedValue> {
                    { "model", new AssignedValue(JToken.Parse("{'val1': 'aaa', 'val2': 'bbb'}")) }
                }
            };

            var stringValue = new StringValue
            {
                StringComponents = new List <IStringComponent> {
                    new Literal {
                        Content = "literal_"
                    },
                    new ValueOf {
                        VariableName = "model",
                        NestedValue  = new ValueOf {
                            VariableName = "val1"
                        }
                    },
                    new ValueOf {
                        VariableName = "model",
                        NestedValue  = new ValueOf {
                            VariableName = "val2"
                        }
                    },
                    new Literal {
                        Content = "_end"
                    }
                }
            };

            // act
            var result = StringValueBuilder.Build(stringValue, scope);

            // validate
            Assert.Equal("literal_aaabbb_end", result);
        }
예제 #3
0
        public override bool PerformComparisonOnRhs(JToken lhsToken, ConditionType conditionType, Scope scope)
        {
            string lhsLiteral;

            try
            {
                lhsLiteral = lhsToken.ToObject <string>();
            }
            catch (Exception e)
            {
                throw new RuntimeException($"Error occured when parsing object to string in condition: {e.Message}");
            }
            if (conditionType == ConditionType.Equal)
            {
                return(lhsLiteral == StringValueBuilder.Build(this, scope));
            }
            else if (conditionType == ConditionType.NotEqual)
            {
                return(lhsLiteral != StringValueBuilder.Build(this, scope));
            }
            throw new RuntimeException($"Cannot make comparison of type {conditionType.ToString()} when comparing with a literal.");
        }
예제 #4
0
 public override AssignedValue GetIRValue(Scope scope)
 {
     return(new AssignedValue(StringValueBuilder.Build(this, scope)));
 }