Exemple #1
0
 static string OutermostValue(ExpressionToCodeConfiguration config, StringifiedExpression node)
 {
     if (node.OptionalValue != null)
     {
         return(ObjectToCodeImpl.ExpressionValueAsCode(config, node.OptionalValue, 10));
     }
     foreach (var kid in node.Children)
     {
         if (!kid.IsConceptualChild)
         {
             var value = OutermostValue(config, kid);
             if (value != null)
             {
                 return(value);
             }
         }
     }
     foreach (var kid in node.Children)
     {
         if (kid.IsConceptualChild)
         {
             var value = OutermostValue(config, kid);
             if (value != null)
             {
                 return(value);
             }
         }
     }
     return(null);
 }
Exemple #2
0
        static void AppendTo(
            ExpressionToCodeConfiguration config,
            StringBuilder sb,
            List <SubExpressionInfo> nodeInfos,
            StringifiedExpression node,
            ref bool ignoreInitialSpace,
            bool showTopExpressionValue)
        {
            if (node.Text != null)
            {
                var trimmedText = ignoreInitialSpace ? node.Text.TrimStart() : node.Text;
                var pos0        = sb.Length;
                sb.Append(trimmedText);
                ignoreInitialSpace = node.Text.Any() && ExpressionToCode.ShouldIgnoreSpaceAfter(node.Text[node.Text.Length - 1]);
                if (showTopExpressionValue)
                {
                    var valueString = node.OptionalValue == null ? null : ObjectToCodeImpl.ExpressionValueAsCode(config, node.OptionalValue, 0);
                    if (valueString != null)
                    {
                        nodeInfos.Add(new SubExpressionInfo {
                            Location = pos0 + trimmedText.Length / 2, Value = valueString
                        });
                    }
                }
            }

            foreach (var kid in node.Children)
            {
                AppendTo(config, sb, nodeInfos, kid, ref ignoreInitialSpace, showTopExpressionValue || kid.IsConceptualChild);
            }
        }
Exemple #3
0
            static void FindSubExpressionValues(
                ExpressionToCodeConfiguration config,
                StringifiedExpression node,
                StringifiedExpression subExprNode,
                List <SubExpressionValue> subExpressionValues,
                bool outerValueIsAssertionFailure)
            {
                if (!outerValueIsAssertionFailure && node.OptionalValue != null)
                {
                    var sb = new StringBuilder();
                    var ignoreInitialSpace = true;
                    var valueString        = ObjectToCodeImpl.ExpressionValueAsCode(config, node.OptionalValue, 10);
                    AppendNodeToStringBuilder(sb, subExprNode, ref ignoreInitialSpace);
                    var maxSize       = Math.Max(40, config.Value.MaximumValueLength ?? 200);
                    var subExprString = sb.Length <= maxSize
                        ? sb.ToString()
                        : sb.ToString(0, maxSize / 2 - 1) + "  …  " + sb.ToString(sb.Length - (maxSize / 2 - 1), maxSize / 2 - 1);

                    // ReSharper disable once ReplaceWithStringIsNullOrEmpty - for nullability analysis
                    if (valueString != null && valueString != "")
                    {
                        subExpressionValues.Add(new SubExpressionValue {
                            SubExpression = subExprString, ValueAsString = valueString
                        });
                    }
                }

                foreach (var kid in node.Children)
                {
                    if (!kid.IsConceptualChild)
                    {
                        FindSubExpressionValues(config, kid, subExprNode, subExpressionValues, outerValueIsAssertionFailure);
                    }
                }

                foreach (var kid in node.Children)
                {
                    if (kid.IsConceptualChild)
                    {
                        FindSubExpressionValues(config, kid, kid, subExpressionValues, false);
                    }
                }
            }
Exemple #4
0
            static void FindSubExpressionValues(
                ExpressionToCodeConfiguration config,
                StringifiedExpression node,
                StringifiedExpression subExprNode,
                List <SubExpressionValue> subExpressionValues,
                bool hideOutermostValue)
            {
                if (!hideOutermostValue && node.OptionalValue != null)
                {
                    var sb = new StringBuilder();
                    var ignoreInitialSpace = true;
                    var valueString        = ObjectToCodeImpl.ExpressionValueAsCode(config, node.OptionalValue, 10);
                    AppendNodeToStringBuilder(sb, subExprNode, ref ignoreInitialSpace);
                    var maxSize       = 80;
                    var subExprString = sb.Length <= maxSize
                        ? sb.ToString()
                        : sb.ToString(0, maxSize / 2 - 1) + "  …  " + sb.ToString(sb.Length - (maxSize / 2 - 1), maxSize / 2 - 1);

                    if (!string.IsNullOrEmpty(valueString))
                    {
                        subExpressionValues.Add(new SubExpressionValue {
                            SubExpression = subExprString, ValueAsString = valueString
                        });
                    }
                }
                foreach (var kid in node.Children)
                {
                    if (kid.IsConceptualChild)
                    {
                        FindSubExpressionValues(config, kid, kid, subExpressionValues, false);
                    }
                }
                foreach (var kid in node.Children)
                {
                    if (!kid.IsConceptualChild)
                    {
                        FindSubExpressionValues(config, kid, subExprNode, subExpressionValues, hideOutermostValue);
                    }
                }
            }