public void DealsOkWithLongStrings()
 {
     ApprovalTest.Verify(
         annotator.AnnotatedToCode(
             () => string.Join("##", Enumerable.Range(0, 100)) + "suffix"
             ));
 }
 public void DealsOkWithLongEnumerables()
 {
     ApprovalTest.Verify(
         annotator.AnnotatedToCode(
             () => Enumerable.Range(0, 1000).ToDictionary(i => "n" + i)["n3"].ToString(CultureInfo.InvariantCulture) == 3.5.ToString(CultureInfo.InvariantCulture)
             ));
 }
        public void AplusBapproved()
        {
            var a = 2;
            var b = 5;

            ApprovalTest.Verify(annotator.AnnotatedToCode(() => a + b));
        }
        public void MethodCallsAndArrayLiterals()
        {
            var a = 2;
            var b = 5;

            ApprovalTest.Verify(annotator.AnnotatedToCode(() => Math.Max(a, b) > new[] { 3, 8, 13, 4 }.Average()));
        }
Exemple #5
0
        public void DealsOkWithObjectsContainingLongMultilineStrings()
        {
            var wallOfText =
                string.Join(
                    "",
                    Enumerable.Range(0, 100)
                    .Select(
                        line =>
                        $"line {line}:".PadRight(10)
                        + string.Join(
                            "",
                            Enumerable.Range(2, 20).Select(n => $"{n * 10,9};")
                            ) + "\n"
                        )
                    );

            ApprovalTest.Verify(
                AnnotateAsAssertion(
                    () => new {
                A_wall_of_text    = wallOfText,
                A_short_string    = "short",
                A_long_enumerable = Enumerable.Range(0, 1000)
            }
                    ));
        }
        public void AnonymousObjectsInArrayExpression()
        {
            var arr    = new[] { new { Name = "hmm", Val = (object)3, }, new { Name = "foo", Val = (object)"test" } };
            var config = ExpressionToCodeConfiguration.DefaultCodeGenConfiguration.WithAnnotator(CodeAnnotators.ValuesOnStalksCodeAnnotator);

            ApprovalTest.Verify(config.AnnotatedToCode(() => arr.Any()));
        }
Exemple #7
0
        public void AplusBapproved()
        {
            var a = 2;
            var b = 5;

            ApprovalTest.Verify(AnnotateAsAssertion(() => a + b > 3));
        }
Exemple #8
0
        public void MethodCallsAndArrayLiterals()
        {
            var a = 2;
            var b = 5;

            ApprovalTest.Verify(AnnotateAsAssertion(() => Math.Max(a, b) > new[] { 3, 8, 13, 4 }.Average()));
        }
        public void NodesThatAreUndescribableAreNotDescribed()
        {
            var list = new List <int> {
                1, 2, 3, 3, 2, 1
            };

            ApprovalTest.Verify(annotator.AnnotatedToCode(() => list.Select(e => e + 1).Count() == 5));
        }
        public void NestedArrayAccessWithOuterAnd()
        {
            var a    = 2;
            var b    = 5;
            var nums = Enumerable.Range(10, 10).ToArray();

            ApprovalTest.Verify(annotator.AnnotatedToCode(() => a < b && nums[a + b] < 7 && b < 10));
        }
        public void NestedArrayAccess()
        {
            var a    = 2;
            var b    = 5;
            var nums = Enumerable.Range(10, 10).ToArray();

            ApprovalTest.Verify(annotator.AnnotatedToCode(() => nums[a + b] < 7));
        }
        public void Binary_expressions_with_nesting()
        {
            var a = 2;
            var b = 5;
            var c = 3.45;

            ApprovalTest.Verify(annotator.AnnotatedToCode(() => a < b && (c > -a || c > b) && b < 10));
        }
Exemple #13
0
        public void Binary_expressions_with_nesting()
        {
            var a = 2;
            var b = 5;
            var c = 3.45;

            ApprovalTest.Verify(AnnotateAsAssertion(() => a < b && (c > -a || c > b) && b < 10));
        }
Exemple #14
0
        public void NestedArrayAccess()
        {
            var a    = 2;
            var b    = 5;
            var nums = Enumerable.Range(10, 10).ToArray();

            ApprovalTest.Verify(AnnotateAsAssertion(() => nums[a + b] < 7));
        }
        public void MessyStructureElidesNeatly()
        {
            var hmm = "1234567890";

            ApprovalTest.Verify(
                annotator.AnnotatedToCode(
                    () => hmm[1] == hmm[2] || hmm[4] == hmm[int.Parse(hmm[8].ToString())] || false
                    ));
        }
Exemple #16
0
 public void DealsOkWithObjectsContainingLongStrings()
 => ApprovalTest.Verify(
     AnnotateAsAssertion(
         () => new {
     A_long_string     = string.Join("##", Enumerable.Range(0, 100)) + "suffix",
     A_short_string    = "short",
     A_long_enumerable = Enumerable.Range(0, 1000)
 }
         ));
Exemple #17
0
        public void MessyStructureElidesNeatly()
        {
            var hmm = "1234567890";

            ApprovalTest.Verify(
                AnnotateAsAssertion(
                    // ReSharper disable once RedundantLogicalConditionalExpressionOperand
                    () => hmm[1] == hmm[2] || hmm[4] == hmm[int.Parse(hmm[8].ToString())] || false
                    ));
        }
Exemple #18
0
        public void UnstableApi()
        {
            var unstableTypes = typeof(ExpressionToCode).GetTypeInfo().Assembly.GetTypes()
                                .Where(IsPublic)
                                .Where(type => type.Namespace !.Contains("Unstable"))
                                .OrderByDescending(type => type.GetTypeInfo().IsEnum)
                                .ThenByDescending(type => type.GetTypeInfo().IsInterface)
                                .ThenBy(type => type.FullName);

            ApprovalTest.Verify(PrettyPrintTypes(unstableTypes));
        }
Exemple #19
0
        public void NestedArraysUseProperConfig()
        {
            var config = ExpressionToCodeConfiguration.DefaultCodeGenConfiguration.WithPrintedListLengthLimit(3);

            ApprovalTest.Verify(config.ComplexObjectToPseudoCode(new[] {
                null,
                new {
                    A = 3,
                    B = new[] { 1, 2, 3, 4, 5 }
                }
            }));
        }
        public void MessyEnumerablesOfAnonymousObjects()
        {
            var foo = new
            {
                A_long_string     = string.Join("##", Enumerable.Range(0, 100)) + "suffix",
                A_short_string    = "short",
                A_long_enumerable = Enumerable.Range(0, 1000)
            };

            ApprovalTest.Verify(
                ExpressionToCodeConfiguration.DefaultAssertionConfiguration.ComplexObjectToPseudoCode(new[] {
                foo, foo,
            }));
        }
        public void DealsOkWithEnumerablesOfAnonymousObjects()
        {
            var foo = new
            {
                A_long_string     = string.Join("##", Enumerable.Range(0, 100)) + "suffix",
                A_short_string    = "short",
                A_long_enumerable = Enumerable.Range(0, 1000)
            };

            ApprovalTest.Verify(
                annotator.AnnotatedToCode(
                    () => new[] {
                foo, foo,
            }));
        }
Exemple #22
0
 public void DealsOkWithLongStrings()
 => ApprovalTest.Verify(
     AnnotateAsAssertion(
         () => string.Join("##", Enumerable.Range(0, 100)) + "suffix"
         ));