Ejemplo n.º 1
0
        public void TestInsertText01()
        {
            textCore.SetCursorPosition(0, 0);
            //Cursor Position should be 0,0

            textCore.InsertText("this is now the first line\n");
            Assert.AreEqual(textCore.GetLine(0), "this is now the first line\n");
        }
Ejemplo n.º 2
0
 public void TestCopyPaste01()
 {
     textCore.SetCursorPosition(0, 0);
     textCore.SetOverrideModifierFlag(TextEditorCommand.Modifier.Shift);
     textCore.DoNavigation(Key.Right);
     textCore.SetOverrideModifierFlag(TextEditorCommand.Modifier.Shift);
     textCore.DoNavigation(Key.Right);
     textCore.SetOverrideModifierFlag(TextEditorCommand.Modifier.Shift);
     textCore.DoNavigation(Key.Right);
     Assert.AreEqual(textCore.GetSelectionText(), "hel");
     textCore.DoCopyText(false);
     Assert.AreEqual(textCore.GetLine(0), "hello\n");
     textCore.SetCursorPosition(0, 3);
     textCore.DoPasteText();
     Assert.AreEqual(textCore.GetLine(3), "hel\tworld");
 }
 public void TestUndoEditing()
 {
     textCore.SetCursorPosition(3, 0);
     textCore.InsertText("testest");
     Assert.AreEqual(textCore.GetLine(0), "heltestestlo\n");
     textCore.UndoEditing();
     Assert.AreEqual(textCore.GetLine(0), "hello\n");
     textCore.UndoEditing();
     Assert.AreEqual(textCore.GetLine(0), "hello\n");
     Assert.AreEqual(textCore.LineCount, 4);
 }
 public void DoControlBackspaceTest01()
 {
     textCore.SetCursorPosition(0, 2);
     textCore.DoControlCharacter(Key.Back);
     Assert.AreEqual(textCore.GetLine(1), "\t\tcruel\n");
     Assert.AreEqual(textCore.LineCount, 3);
 }
        public void TestCommentedLines()
        {
            string fileContent =
                "// This case tests the ability to format embedded comments\n" +
                "// properly. These include both multi-line and single-line\n" +
                "// comments syntax.                                       \n" +
                "                                                          \n" +
                "// This line by itself should not be modified.            \n" +
                "                                                          \n" +
                "a=2;// This line should be formatted (not indented).      \n" +
                "                                                          \n" +
                "/* This is the beginning of a multi-line comment block    \n" +
                "                                                          \n" +
                "    This is a line within a multi-line comment block.     \n" +
                "    It is indented now but should not be indented further.\n" +
                "                                                          \n" +
                "This marks the end of a multi-line comment block */       \n" +
                "                                                          \n" +
                "    [Imperative] // This should be un-indented.           \n" +
                "{                                                         \n" +
                "    /*  This  is another multi-line                       \n" +
                "        comment block, only that it                       \n" +
                "        is  indented  for the scope */                    \n" +
                "                                                          \n" +
                "                   //   This should be indented.          \n" +
                "                                                          \n" +
                "b=3;// Formatting should resume on this line.             \n" +
                "         c     =    4    ; // And this line, too.         \n" +
                "}                                                         \n" +
                "                                                          \n" +
                "   //   Spaces in comments  shouldn't   be  normalized!   \n";

            Solution testSolution = Solution.CreateTemporary();

            testSolution.AddNewScript(fileContent);
            testSolution.ActivateScript(0);

            TextEditorCore textCore = TextEditorCore.Instance;

            textCore.ChangeScript(0);
            textCore.ParseScriptImmediate();

            SmartFormatter.Instance.AlternateEditorCore = textCore;
            bool formatted = textCore.FormatDocument();

            Assert.AreEqual(true, formatted);
            SmartFormatter.Instance.AlternateEditorCore = null;

            Assert.AreEqual("// This case tests the ability to format embedded comments\n", textCore.GetLine(0));
            Assert.AreEqual("// properly. These include both multi-line and single-line\n", textCore.GetLine(1));
            Assert.AreEqual("// comments syntax.                                       \n", textCore.GetLine(2));
            Assert.AreEqual("\n", textCore.GetLine(3));
            Assert.AreEqual("// This line by itself should not be modified.            \n", textCore.GetLine(4));
            Assert.AreEqual("\n", textCore.GetLine(5));
            Assert.AreEqual("a = 2; // This line should be formatted (not indented).      \n", textCore.GetLine(6));
            Assert.AreEqual("\n", textCore.GetLine(7));
            Assert.AreEqual("/* This is the beginning of a multi-line comment block    \n", textCore.GetLine(8));
            Assert.AreEqual("\n", textCore.GetLine(9));
            Assert.AreEqual("    This is a line within a multi-line comment block.     \n", textCore.GetLine(10));
            Assert.AreEqual("    It is indented now but should not be indented further.\n", textCore.GetLine(11));
            Assert.AreEqual("\n", textCore.GetLine(12));
            Assert.AreEqual("This marks the end of a multi-line comment block */       \n", textCore.GetLine(13));
            Assert.AreEqual("\n", textCore.GetLine(14));
            Assert.AreEqual("[Imperative] // This should be un-indented.           \n", textCore.GetLine(15));
            Assert.AreEqual("{\n", textCore.GetLine(16));
            Assert.AreEqual("    /*  This  is another multi-line                       \n", textCore.GetLine(17));
            Assert.AreEqual("        comment block, only that it                       \n", textCore.GetLine(18));
            Assert.AreEqual("        is  indented  for the scope */                    \n", textCore.GetLine(19));
            Assert.AreEqual("    \n", textCore.GetLine(20));
            Assert.AreEqual("    //   This should be indented.          \n", textCore.GetLine(21));
            Assert.AreEqual("    \n", textCore.GetLine(22));
            Assert.AreEqual("    b = 3; // Formatting should resume on this line.             \n", textCore.GetLine(23));
            Assert.AreEqual("    c = 4; // And this line, too.         \n", textCore.GetLine(24));
            Assert.AreEqual("}\n", textCore.GetLine(25));
            Assert.AreEqual("\n", textCore.GetLine(26));
            Assert.AreEqual("//   Spaces in comments  shouldn't   be  normalized!   \n", textCore.GetLine(27));
        }
 public void TestDeleteCurrentLine01()
 {
     textCore.SetCursorPosition(2, 2);
     textCore.DeleteCurrentLine();
     Assert.AreEqual(textCore.GetLine(2), "\tworld".ToCharArray());
 }
 public void TestMoveSelectedText01()
 {
     //hruel\n
     //\twello\n
     //\n
     //\t\tcorld
     textCore.SetCursorPosition(1, 0);
     textCore.SetOverrideModifierFlag(TextEditorCommand.Modifier.Shift);
     textCore.SetCursorPosition(3, 2);
     textCore.MoveSelectedText(2, 3, false);
     Assert.AreEqual(textCore.GetLine(3), "\t\tcorld");
     Assert.AreEqual(textCore.GetLine(2), "\n");
     Assert.AreEqual(textCore.GetLine(1), "\twello\n");
     Assert.AreEqual(textCore.GetLine(0), "hruel\n");
     Assert.AreEqual(textCore.LineCount, 4);
     textCore.UndoEditing();
     Assert.AreEqual(textCore.GetLine(3), "\tworld");
     Assert.AreEqual(textCore.GetLine(2), "\t\tcruel\n");
     Assert.AreEqual(textCore.GetLine(1), "\n");
     Assert.AreEqual(textCore.GetLine(0), "hello\n");
     Assert.AreEqual(textCore.LineCount, 4);
 }