public void TestIgnoreLinesMatching()
        {
            var nl = System.Environment.NewLine;

            var testCases = new List <(string, string[], ulong[], string)>
            {
                ("AA!?", new[] { "AA" }, new ulong[] {},
                 "line ignored"),

                ($"AA--{nl}#@!?", new[] { "AA" }, new ulong[] { 2 },
                 "one line ignored, other hits"),

                ($"AA!?{nl}BB!?{nl}#@!?", new[] { "AA", "BB" }, new ulong[] { 3 },
                 "ignored lines should match at least one pattern, one line still hits")
            };

            foreach (var(text, patterns, expectedLineTooLongs, caseName) in
                     testCases)
            {
                using var reader = new StringReader(text);
                uint maxLineLength = 3;

                var ignoreLinesMatching =
                    patterns
                    .Select(p => new Regex(p))
                    .ToList();

                Inspection.Record record = Inspection.InspectLines(reader, maxLineLength, ignoreLinesMatching);

                Assert.That(
                    record.LinesTooLong.Select(l => l.LineNumber).ToList(),
                    Is.EquivalentTo(expectedLineTooLongs),
                    caseName);
            }
        }
        public void TestSingleLineWithoutTrailingNewlineOK()
        {
            using var reader = new StringReader("some content");
            uint maxLineLength       = 120;
            var  ignoreLinesMatching = new List <Regex>();

            Inspection.Record record = Inspection.InspectLines(reader, maxLineLength, ignoreLinesMatching);

            Assert.AreEqual(0, record.LinesTooLong.Count);
            Assert.AreEqual(1, record.LineCount);
        }
        public void TestLinuxLineCount()
        {
            using var reader = new StringReader("123\n123\n");
            uint maxLineLength       = 3;
            var  ignoreLinesMatching = new List <Regex>();

            Inspection.Record record = Inspection.InspectLines(reader, maxLineLength, ignoreLinesMatching);

            Assert.AreEqual(0, record.LinesTooLong.Count);
            Assert.AreEqual(2, record.LineCount);
        }
示例#4
0
        public void TestOKWithoutVerbose()
        {
            using var writer = new StringWriter();

            var record = new Inspection.Record(
                new List <Inspection.LineTooLong>(),
                10);

            Output.Report("Program.cs", record, 13, 1984, false, writer);

            var nl = Environment.NewLine;

            Assert.AreEqual("", writer.ToString());
        }
        public void TestSingleLineTooLong()
        {
            using var reader = new StringReader("1234567");
            uint maxLineLength       = 3;
            var  ignoreLinesMatching = new List <Regex>();

            Inspection.Record record = Inspection.InspectLines(reader, maxLineLength, ignoreLinesMatching);

            var expected = new List <Inspection.LineTooLong>
            {
                new Inspection.LineTooLong(1, 7)
            };

            Assert.That(record.LinesTooLong, Is.EquivalentTo(expected));
            Assert.AreEqual(1, record.LineCount);
        }
示例#6
0
        public void TestFileTooLong()
        {
            using var writer = new StringWriter();

            var record = new Inspection.Record(
                new List <Inspection.LineTooLong>(),
                5000);

            Output.Report("Program.cs", record, 13, 1984, false, writer);

            var    nl       = Environment.NewLine;
            string expected = $"FAIL Program.cs{nl}" +
                              $"  * The file is too long. It contains 5000 line(s), " +
                              $"but only 1984 line(s) are allowed.{nl}";

            Assert.AreEqual(expected, writer.ToString());
        }
        public void TestMultipleTrespassingLines()
        {
            var nl = System.Environment.NewLine;

            using var reader = new StringReader($"123{nl}1234{nl}12345{nl}123");
            uint maxLineLength       = 3;
            var  ignoreLinesMatching = new List <Regex>();

            Inspection.Record record = Inspection.InspectLines(reader, maxLineLength, ignoreLinesMatching);

            var expected = new List <Inspection.LineTooLong>
            {
                new Inspection.LineTooLong(2, 4),
                new Inspection.LineTooLong(3, 5)
            };

            Assert.That(record.LinesTooLong, Is.EquivalentTo(expected));
            Assert.AreEqual(4, record.LineCount);
        }
示例#8
0
        public void TestSingleLineTooLong()
        {
            using var writer = new StringWriter();

            var record = new Inspection.Record(
                new List <Inspection.LineTooLong>
            {
                new Inspection.LineTooLong(3, 123)
            },
                10);

            Output.Report("Program.cs", record, 13, 1984, false, writer);

            var    nl       = Environment.NewLine;
            string expected = $"FAIL Program.cs{nl}" +
                              $"  * The following line(s) have more than allowed 13 characters:{nl}" +
                              $"    * Line 3: 123 characters{nl}";


            Assert.AreEqual(expected, writer.ToString());
        }
示例#9
0
        public void TestLinesAndFileTooLong()
        {
            using var writer = new StringWriter();

            var record = new Inspection.Record(
                new List <Inspection.LineTooLong>
            {
                new Inspection.LineTooLong(3, 123),
                new Inspection.LineTooLong(4, 124)
            },
                5000);

            Output.Report("Program.cs", record, 13, 1984, false, writer);

            var    nl       = Environment.NewLine;
            string expected = $"FAIL Program.cs{nl}" +
                              $"  * The following line(s) have more than allowed 13 characters:{nl}" +
                              $"    * Line 3: 123 characters{nl}" +
                              $"    * Line 4: 124 characters{nl}" +
                              $"  * The file is too long. It contains 5000 line(s), " +
                              $"but only 1984 line(s) are allowed.{nl}";

            Assert.AreEqual(expected, writer.ToString());
        }