Пример #1
0
        private void AssertExpression(string expression, object expectedReturnValue)
        {
            var    accessor            = new PropertyAccessor(_project, _project.RootTargetCallStack);
            string value               = accessor.ExpandProperties("${" + expression + "}", Location.UnknownLocation);
            string expectedStringValue = Convert.ToString(expectedReturnValue, CultureInfo.InvariantCulture);

            (_project as ITargetLogger).Log(Level.Debug, "expression: " + expression);
            (_project as ITargetLogger).Log(Level.Debug, "value: " + value + ", expected: " + expectedStringValue);
            Assert.AreEqual(expectedStringValue, value, expression);
        }
Пример #2
0
        /// <summary>
        /// Refills the buffer, running our input through
        /// <see cref="M:PropertyDictionary.ExpandProperties(string, Location)" />.)
        /// </summary>
        private void ReplenishBuffer()
        {
            // Fill buffer from input.
            bool isMoreInput = true;
            int  curCharInt;

            while ((_buffer.Length < BUFFER_LENGTH) && isMoreInput)
            {
                curCharInt = base.Read();
                if (curCharInt != -1)
                {
                    _buffer.Append((char)curCharInt);
                }
                else
                {
                    isMoreInput = false;
                }
            }

            string bufferBeforeExpand = _buffer.ToString();
            int    lastExprStartIndex = bufferBeforeExpand.LastIndexOf("${");
            int    lastExprEndIndex   = bufferBeforeExpand.LastIndexOf('}');
            string bufferAfterExpand;

            var propertyAccessor = new PropertyAccessor(this.Project, this.CallStack);

            // Expand properties from input into buffer for output.
            if (lastExprEndIndex < lastExprStartIndex)
            {
                // There's an unfinished expression - don't attempt to expand it yet. Perhaps it will all fit in the buffer next time around.
                bufferAfterExpand  = propertyAccessor.ExpandProperties(bufferBeforeExpand.Substring(0, lastExprStartIndex), Location);
                bufferBeforeExpand = bufferBeforeExpand.Substring(lastExprStartIndex);
                _buffer            = new StringBuilder(bufferAfterExpand, Math.Max(BUFFER_LENGTH, bufferAfterExpand.Length + bufferBeforeExpand.Length));
                _buffer.Append(bufferBeforeExpand);
            }
            else
            {
                // No partial expressions - keep it simple.
                bufferAfterExpand = propertyAccessor.ExpandProperties(bufferBeforeExpand, Location);
                _buffer           = new StringBuilder(bufferAfterExpand, Math.Max(BUFFER_LENGTH, bufferAfterExpand.Length));
            }
        }