Esempio n. 1
0
        public void Convert_AspxLineColumnPosition_Correct()
        {
            string          fileName   = Path.Combine(TestUtility.TestsDataPath, "TestAspxParser.aspx");
            string          text       = File.ReadAllText(fileName);
            var             aspxParser = new global::AspxParser.AspxParser(fileName, true);
            var             source     = new AspxSource(fileName, text);
            AspxParseResult result     = aspxParser.Parse(source);
            var             foundNode  = result.RootNode.Descendants <AspxNode.AspxExpressionTag>()
                                         .FirstOrDefault(node => node.Expression.Contains("Expression text"));

            var sourceCode = new CodeFile(source.Text);

            sourceCode.GetLineColumnFromLinear(foundNode.Location.Start, out int line, out int column);
            Assert.AreEqual(15, line);
            Assert.AreEqual(13, column);
            Assert.AreEqual(foundNode.Location.Start, sourceCode.GetLinearFromLineColumn(line, column));

            sourceCode.GetLineColumnFromLinear(foundNode.Location.End, out line, out column);
            Assert.AreEqual(15, line);
            Assert.AreEqual(30, column);
            Assert.AreEqual(foundNode.Location.End, sourceCode.GetLinearFromLineColumn(line, column));
        }
Esempio n. 2
0
        public void ConvertPosition_LineColumn_CorrectLinear()
        {
            string text = "row1\r\n" +
                          "row2\n" +
                          "row3\r" +
                          "row4";

            var sourceCodeFile = new CodeFile(text);
            int linearPos      = sourceCodeFile.GetLinearFromLineColumn(4, 4);

            Assert.AreEqual('4', text[linearPos]);

            sourceCodeFile.GetLineColumnFromLinear(linearPos, out int line, out int column);
            Assert.AreEqual(4, line);
            Assert.AreEqual(4, column);

            Assert.AreEqual(4, sourceCodeFile.GetLinesCount());
        }