/// <summary>
        /// Side effect: state is managed in the _counters dictionary.
        /// </summary>
        /// <returns></returns>
        private String GetNextCycleText(String groupName, CycleTag cycleTag)
        {
            int currentIndex;
            // Create a like dictionary key entry to keep track of this declaration.  THis takes the variable
            // names (not the eval-ed variables) or literals and concatenates them together.
            var key = "cycle_" + groupName + "_" + String.Join("|", cycleTag.CycleList.Select(x => x.Data.Expression.ToString()));


            while (true)
            {
                currentIndex = _counters.GetOrAdd(key, 0);
                var newindex = (currentIndex + 1) % cycleTag.Length;

                // fails if updated concurrently by someone else.
                if (_counters.TryUpdate(key, newindex, currentIndex))
                {
                    break;
                }
            }

            String result         = "";
            var    currentElement = cycleTag.ElementAt(currentIndex);

            LiquidExpressionEvaluator.Eval(currentElement, _templateContext)
            .WhenSuccess(x => result = ValueCaster.RenderAsString(LiquidExpressionEvaluator.Eval(currentElement, _templateContext).SuccessResult.Value))
            .WhenError(err => result = FormatErrors(new List <LiquidError> {
                err
            }));

            return(result);
        }
        public void It_Should_Find_Elements_In_Its_Array()
        {
            // Arrange
            var cycleTag = new CycleTag();

            cycleTag.CycleList.Add(new TreeNode <LiquidExpression>(new LiquidExpression {
                Expression = LiquidString.Create("A")
            }));
            cycleTag.CycleList.Add(new TreeNode <LiquidExpression>(new LiquidExpression {
                Expression = LiquidString.Create("B")
            }));
            cycleTag.CycleList.Add(new TreeNode <LiquidExpression>(new LiquidExpression {
                Expression = LiquidString.Create("C")
            }));

            // Assert
            Assert.Equal("A", ((LiquidString)cycleTag.ElementAt(0).Data.Expression).StringVal);
            Assert.Equal("B", ((LiquidString)cycleTag.ElementAt(1).Data.Expression).StringVal);
        }