Ejemplo n.º 1
0
        public static string ToEndings(this string text, EndingsStyle endingsStyle)
        {
            switch (endingsStyle)
            {
            case EndingsStyle.Linux:
                return(text.ToLinuxEndings());

            case EndingsStyle.Windows:
                return(text.ToWindowsEndings());

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 2
0
        public void SingleEmptyLine(EndingsStyle endingsStyle)
        {
            var text = "\n";

            text = text.ToEndings(endingsStyle);
            var doc = new TextDocument(text, TestCommon.UriMock);

            var eol = endingsStyle == EndingsStyle.Linux ? 1 : 2;

            Assert.AreEqual(0, doc.GetPosition(0, 1));
            Assert.AreEqual(0, doc.GetPosition(0, 5));
            Assert.AreEqual(eol, doc.GetPosition(1, 1));
            Assert.AreEqual(eol, doc.GetPosition(1, 5));
            Assert.AreEqual(eol, doc.GetPosition(2, 5));

            Assert.AreEqual(LineChr.Zero, doc.GetLineChr(0));
            Assert.AreEqual(LineChr.Zero, doc.GetLineChr(1));
            Assert.AreEqual(LineChr.Zero, doc.GetLineChr(2));
            Assert.AreEqual(LineChr.Zero, doc.GetLineChr(3));
        }
Ejemplo n.º 3
0
        public void ShowPositionOnLine(EndingsStyle endingsStyle)
        {
            var rawLine = "Line test ble\n";

            Console.WriteLine($"Script:\n{rawLine}");

            var line = rawLine.ToEndings(endingsStyle);
            Func <int, string> leadSpaces = spaces => "^".PadLeft(spaces + 1);

            string GetAndPrint(string lineStr, int chr)
            {
                var posOnLine = TextDocument.ShowPositionOnLine(lineStr, chr);

                Console.WriteLine(posOnLine);
                return(posOnLine);
            }

            Assert.AreEqual(rawLine + leadSpaces(0), GetAndPrint(line, 0));
            Assert.AreEqual(rawLine + leadSpaces(4), GetAndPrint(line, 4));
            Assert.AreEqual(rawLine + leadSpaces(13), GetAndPrint(line, 13));
            Assert.AreEqual(rawLine + leadSpaces(13), GetAndPrint(line, 14));
            Assert.AreEqual(rawLine + leadSpaces(13), GetAndPrint(line, 20));
        }