コード例 #1
0
        public void TSLintLogReader_ReadLog_WhenInputIsNull_ThrowsArgumentNullException()
        {
            TSLintLogReader logReader = new TSLintLogReader();

            Action action = () => logReader.ReadLog(default(Stream));

            action.ShouldThrow <ArgumentNullException>();
        }
コード例 #2
0
        public void TSLintLogReader_NormalizeLog_WrapsSingleFixInArray()
        {
            const string Input = @"
            [
                {
                    ""endPosition"":
                        {
                            ""character"":1,
                            ""line"":113,
                            ""position"":4429
                        },
                    ""failure"":""file should end with a newline"",
                    ""fix"":
                    {
                        ""innerStart"":4429,
                        ""innerLength"":0,
                        ""innerText"":""\r\n""
                    },
                    ""name"":""SecureApp/js/index.d.ts"",
                    ""ruleName"":""eofline"",
                    ""ruleSeverity"":""ERROR"",
                    ""startPosition"":
                    {
                        ""character"":1,
                        ""line"":113,
                        ""position"":4429
                    }
                }
            ]";

            const string ExpectedOutput = @"
            [
                {
                    ""endPosition"":
                        {
                            ""character"":1,
                            ""line"":113,
                            ""position"":4429
                        },
                    ""failure"":""file should end with a newline"",
                    ""fix"":
                    [{
                        ""innerStart"":4429,
                        ""innerLength"":0,
                        ""innerText"":""\r\n""
                    }],
                    ""name"":""SecureApp/js/index.d.ts"",
                    ""ruleName"":""eofline"",
                    ""ruleSeverity"":""ERROR"",
                    ""startPosition"":
                    {
                        ""character"":1,
                        ""line"":113,
                        ""position"":4429
                    }
                }
            ]";

            JToken expectedToken = JToken.Parse(ExpectedOutput);

            JToken          inputToken  = JToken.Parse(Input);
            TSLintLogReader logReader   = new TSLintLogReader();
            JToken          actualToken = logReader.NormalizeLog(inputToken);

            JToken.DeepEquals(expectedToken, actualToken).Should().BeTrue();
        }
コード例 #3
0
        public void TSLintLogReader_ReadLog_ProducesExpectedLog()
        {
            const string Input = @"
            [
                {
                    ""endPosition"":
                        {
                            ""character"":1,
                            ""line"":113,
                            ""position"":4429
                        },
                    ""failure"":""file should end with a newline"",
                    ""fix"":
                    {
                        ""innerStart"":4429,
                        ""innerLength"":0,
                        ""innerText"":""\r\n""
                    },
                    ""name"":""SecureApp/js/index.d.ts"",
                    ""ruleName"":""eofline"",
                    ""ruleSeverity"":""ERROR"",
                    ""startPosition"":
                    {
                        ""character"":1,
                        ""line"":113,
                        ""position"":4429
                    }
                }
            ]";

            TSLintLog expectedLog = new TSLintLog
            {
                new TSLintLogEntry
                {
                    EndPosition = new TSLintLogPosition
                    {
                        Character = 1,
                        Line      = 113,
                        Position  = 4429
                    },
                    Failure = "file should end with a newline",
                    Fixes   = new List <TSLintLogFix>
                    {
                        new TSLintLogFix
                        {
                            InnerStart  = 4429,
                            InnerLength = 0,
                            InnerText   = "\r\n"
                        }
                    },
                    Name          = "SecureApp/js/index.d.ts",
                    RuleName      = "eofline",
                    RuleSeverity  = "ERROR",
                    StartPosition = new TSLintLogPosition
                    {
                        Character = 1,
                        Line      = 113,
                        Position  = 4429
                    }
                }
            };

            TSLintLogReader logReader = new TSLintLogReader();

            TSLintLog actualLog = logReader.ReadLog(Input);

            CompareLogs(actualLog, expectedLog);
        }
コード例 #4
0
        public void TSLintLogReader_NormalizeLog_HandlesInnerReplacements()
        {
            const string Input = @"
            [
                {
                    ""endPosition"": {
                        ""character"": 4,
                        ""line"": 56,
                        ""position"": 1876
                    },
                    ""failure"": ""trailing whitespace"",
                    ""fix"": {
                        ""innerRuleName"": ""no-trailing-whitespace"",
                        ""innerReplacements"": [
                            {
                                ""innerStart"": 1872,
                                ""innerLength"": 4,
                                ""innerText"": """"
                            }
                        ]
                    },
                    ""name"": ""SecureApp/ts/index.d.ts"",
                    ""ruleName"": ""no-trailing-whitespace"",
                    ""startPosition"": {
                        ""character"": 0,
                        ""line"": 56,
                        ""position"": 1872
                    }
                },
            ]";

            const string ExpectedOutput = @"
            [
                {
                    ""endPosition"": {
                        ""character"": 4,
                        ""line"": 56,
                        ""position"": 1876
                    },
                    ""failure"": ""trailing whitespace"",
                    ""fix"": [
                        {
                            ""innerStart"": 1872,
                            ""innerLength"": 4,
                            ""innerText"": """"
                        }
                    ],
                    ""name"": ""SecureApp/ts/index.d.ts"",
                    ""ruleName"": ""no-trailing-whitespace"",
                    ""startPosition"": {
                        ""character"": 0,
                        ""line"": 56,
                        ""position"": 1872
                    }
                },
            ]";

            JToken expectedToken = JToken.Parse(ExpectedOutput);

            JToken          inputToken  = JToken.Parse(Input);
            TSLintLogReader logReader   = new TSLintLogReader();
            JToken          actualToken = logReader.NormalizeLog(inputToken);

            JToken.DeepEquals(expectedToken, actualToken).Should().BeTrue();
        }