Exemplo n.º 1
0
 public void AssignEvaluation_IndexToInt_ErrorsForAnExpression()
 {
     //------------Setup for test--------------------------
     var arr = new JArray();
     //------------Execute Test---------------------------
     // ReSharper disable once AccessToStaticMemberViaDerivedType
     var res = AssignEvaluation.indexToInt(LanguageAST.Index.IndexExpression.NewIndexExpression(LanguageAST.LanguageExpression.NewWarewolfAtomExpression(DataStorage.WarewolfAtom.Nothing)), arr);
     //------------Assert Results-------------------------
 }
Exemplo n.º 2
0
        public void AssignEvaluation_IndexToInt_ErrorsForAnExpression()
        {
            //------------Setup for test--------------------------
            var arr = new JArray();
            //------------Execute Test---------------------------

            var res = AssignEvaluation.indexToInt(LanguageAST.Index.IndexExpression.NewIndexExpression(LanguageAST.LanguageExpression.NewWarewolfAtomExpression(DataStorage.WarewolfAtom.Nothing)), arr);
            //------------Assert Results-------------------------
        }
Exemplo n.º 3
0
        public void AssignEvaluation_IndexToInt_IntIndexReturnsInt()
        {
            //------------Setup for test--------------------------
            var arr = new JArray {
                new JValue("bob")
            };

            //------------Execute Test---------------------------
            var res = AssignEvaluation.indexToInt(LanguageAST.Index.NewIntIndex(1), arr);

            //------------Assert Results-------------------------
            Assert.AreEqual(res.Length, 1);
            Assert.AreEqual(1, res.Head);
        }
Exemplo n.º 4
0
        public void AssignEvaluation_IndexToInt_LastReturnsCountPlusOne()
        {
            //------------Setup for test--------------------------
            var arr = new JArray {
                new JValue("bob")
            };

            //------------Execute Test---------------------------
            var res = AssignEvaluation.indexToInt(LanguageAST.Index.Last, arr);

            //------------Assert Results-------------------------
            Assert.AreEqual(res.Length, 1);
            Assert.AreEqual(2, res.Head);
        }
Exemplo n.º 5
0
        private void BuildIndexMapHelper(string exp, List <string> indexMap, LanguageAST.JsonIdentifierExpression.IndexNestedNameExpression nameExpression, string objectName, JArray arr)
        {
            var indexToInt = AssignEvaluation.indexToInt(LanguageAST.Index.Star, arr).ToList();

            foreach (var i in indexToInt)
            {
                if (!string.IsNullOrEmpty(exp))
                {
                    var indexed    = objectName + @"(" + i + @")";
                    var updatedExp = exp.Replace(objectName + @"(*)", indexed);
                    indexMap.Add(updatedExp);
                    BuildIndexMap(nameExpression.Item.Next, updatedExp, indexMap, arr[i - 1] as JContainer);
                }
            }
        }
Exemplo n.º 6
0
        public void AssignEvaluation_IndexToInt_StarIndexReturnsAllIndexes()
        {
            //------------Setup for test--------------------------
            var arr = new JArray {
                new JValue("bob"), new JValue("bob")
            };

            //------------Execute Test---------------------------
            var res = AssignEvaluation.indexToInt(LanguageAST.Index.Star, arr);

            //------------Assert Results-------------------------
            Assert.AreEqual(res.Length, 2);
            Assert.AreEqual(1, res.Head);
            Assert.AreEqual(2, res[1]);
        }
        private void BuildIndexMap(LanguageAST.JsonIdentifierExpression var, string exp, List <string> indexMap, JContainer container)
        {
            var jsonIdentifierExpression = var;

            if (jsonIdentifierExpression != null)
            {
                var nameExpression = jsonIdentifierExpression as LanguageAST.JsonIdentifierExpression.IndexNestedNameExpression;
                if (nameExpression != null)
                {
                    var        objectName = nameExpression.Item.ObjectName;
                    JContainer obj;
                    JArray     arr = null;
                    if (container == null)
                    {
                        obj = _env.JsonObjects[objectName];
                        arr = obj as JArray;
                    }
                    else
                    {
                        var props = container.FirstOrDefault(token => token.Type == JTokenType.Property && ((JProperty)token).Name == objectName);
                        if (props != null)
                        {
                            obj = props.First as JContainer;
                            arr = obj as JArray;
                        }
                        else
                        {
                            obj = container;
                        }
                    }

                    if (arr != null)
                    {
                        var indexToInt = AssignEvaluation.indexToInt(LanguageAST.Index.Star, arr).ToList();
                        foreach (var i in indexToInt)
                        {
                            if (!string.IsNullOrEmpty(exp))
                            {
                                var indexed    = objectName + @"(" + i + @")";
                                var updatedExp = exp.Replace(objectName + @"(*)", indexed);
                                indexMap.Add(updatedExp);
                                BuildIndexMap(nameExpression.Item.Next, updatedExp, indexMap, arr[i - 1] as JContainer);
                            }
                        }
                    }
                    else
                    {
                        if (!nameExpression.Item.Next.IsTerminal)
                        {
                            BuildIndexMap(nameExpression.Item.Next, exp, indexMap, obj);
                        }
                    }
                }
                else
                {
                    var nestedNameExpression = jsonIdentifierExpression as LanguageAST.JsonIdentifierExpression.NestedNameExpression;
                    if (nestedNameExpression != null)
                    {
                        JContainer obj;
                        var        objectName = nestedNameExpression.Item.ObjectName;
                        if (container == null)
                        {
                            obj = _env.JsonObjects[objectName];
                        }
                        else
                        {
                            var props = container.FirstOrDefault(token => token.Type == JTokenType.Property && ((JProperty)token).Name == objectName);
                            if (props != null)
                            {
                                obj = props.First as JContainer;
                            }
                            else
                            {
                                obj = container;
                            }
                        }
                        BuildIndexMap(nestedNameExpression.Item.Next, exp, indexMap, obj);
                    }
                }
            }
        }