Exemple #1
0
		public void DeleteToLineBoundary ()
		{
			var mode = new TestViEditMode () { Text =
@"   aaa bbb ccc ddd
   eee fff ggg hhh
   iii jjj kkk lll",
			};
			//move 3 words, delete to line end
			mode.Input ("wwwd$");
			Assert.AreEqual (
@"   aaa bbb 
   eee fff ggg hhh
   iii jjj kkk lll", mode.Text);
			//move down to 0 position, move 3 words, delete to home
			mode.Input ("j0wwwd^");
			Assert.AreEqual (
@"   aaa bbb
   ggg hhh
   iii jjj kkk lll", mode.Text);
			//move down to 0 position, move 3 words, delete to 0
			mode.Input ("j0wwwd0");
			Assert.AreEqual (
@"   aaa bbb
   ggg hhh
kkk lll", mode.Text);
		}
        public void LineMotion()
        {
            var mode = new TestViEditMode()
            {
                Text =
                    @"abc def
ghy jklmn op
qrstu
vwxyz",
            };

            mode.Caret.Offset = 0;
            Assert.AreEqual(0, mode.Line);
            mode.Input('j');
            Assert.AreEqual(1, mode.Line);
            mode.Input('k');
            Assert.AreEqual(0, mode.Line);
            mode.Input("jjjj");
            Assert.AreEqual(3, mode.Line);
            mode.Caret.Line   = 1;
            mode.Caret.Column = 11;
            mode.Input('j');
            Assert.AreEqual(4, mode.Col);
            mode.Input('k');
            Assert.AreEqual(11, mode.Col);
        }
Exemple #3
0
        public void YankInnerParen()
        {
            var mode = new TestViEditMode {
                Text = "if (foo(baz) == bar) "
            };

            RepeatChar('l', 3, mode);
            mode.Input("yi)");
            mode.Input("$p");              // HACK: I can't figure out how to test the register, so just paste at the end
            Assert.AreEqual("if (foo(baz) == bar) foo(baz) == bar", mode.Text);
        }
        public void LineDeletePaste()
        {
            var mode = new TestViEditMode()
            {
                Text =
                    @"   aaa aaa
   bbb bbb
   ccc ccc
   eee eee
   fff fff
   ggg ggg
   hhh hhh",
            };

            //move down, enter visual line mode, move down twice -> lines 2/3/4 selected -> delete
            mode.Input("jjVjjd");
            Assert.AreEqual(
                @"   aaa aaa
   bbb bbb
   ggg ggg
   hhh hhh", mode.Text);
            //enter visual line mode, move down once -> lines 1/2 selected -> delete
            mode.Input("Vkd");
            Assert.AreEqual(
                @"   aaa aaa
   hhh hhh", mode.Text);
            //paste last delete below current line (1)
            mode.Input("p");
            Assert.AreEqual(
                @"   aaa aaa
   hhh hhh
   bbb bbb
   ggg ggg", mode.Text);
            //paste last delete above current line (3)
            mode.Input("P");
            Assert.AreEqual(
                @"   aaa aaa
   hhh hhh
   bbb bbb
   bbb bbb
   ggg ggg
   ggg ggg", mode.Text);
            Assert.AreEqual(4, mode.Line);
            //movement to/across boundaries, check selection still okay by deleting lines 1/2/3
            mode.Input("kVlllllhhhhhhhhhhjjjhhhhhjjjjkkkkkkkkkkkkjd");
            Assert.AreEqual(
                @"   aaa aaa
   ggg ggg
   ggg ggg", mode.Text);
        }
Exemple #5
0
        public void ChangeInnerBrace_IsntConfusedByQuotes(char startBrace, char endBrace, char quote)
        {
            var text = string.Format("if {0}{2}{1}{2} == bar{1} ", startBrace, endBrace, quote);
            var mode = new TestViEditMode {
                Text = text
            };

            RepeatChar('l', 4, mode);

            // Validate that our setups work. Use a specific case (the rest proved correct via induction).
            if (startBrace == '(' && quote == '\'')
            {
                Assert.AreEqual("if (')' == bar) ", text,
                                "Validating that our test input because it's a bit too generic to be easy to read.");

                var plusMinusOneCharContext = "" + mode.GetChar(mode.Caret.Offset - 1) + mode.GetChar(mode.Caret.Offset)
                                              + mode.GetChar(mode.Caret.Offset + 1);
                Assert.AreEqual("(')", plusMinusOneCharContext, "The cursor is where we expect it to be.");

                Assert.NotNull(mode.Document.BracketMatcher);
                Assert.IsInstanceOf <DefaultBracketMatcher>(mode.Document.BracketMatcher);

                var matchingParen = mode.Document.GetMatchingBracketOffset(3);
                Assert.AreEqual(14, matchingParen, "Validate setup correctly enabled mode.Document functionality.");
            }

            mode.Input("ci" + endBrace);
            var expectedText = string.Format("if {0}{1} ", startBrace, endBrace, quote);

            Assert.AreEqual(expectedText, mode.Text);
        }
Exemple #6
0
		public void VisualMotion ()
		{
			var mode = new TestViEditMode () { Text =
@"    aaa bbb ccc ddd
   eee fff ggg hhh
   iii jjj kkk lll
   mmm nnn ooo ppp
   qqq rrr sss ttt",
			};
			//move 2 lines down, 2 words in, enter visual mode
			mode.Input ("jjwwv");
			mode.AssertSelection (3, 8, 3, 9);
			//2 letters to right
			mode.Input ("ll");
			mode.AssertSelection (3, 8, 3, 11);
			//4 letters to left
			mode.Input ("hhhh");
			mode.AssertSelection (3, 9, 3, 6);
			//1 line up
			mode.Input ("k");
			mode.AssertSelection (3, 9, 2, 6);
			//1 line up
			mode.Input ("k");
			mode.AssertSelection (3, 9, 1, 6);
			//5 letters to right
			mode.Input ("lllll");
			mode.AssertSelection (3, 9, 1, 11);
			//3 lines down
			mode.Input ("jjj");
			mode.AssertSelection (3, 8, 4, 12);
		}
Exemple #7
0
        static void RepeatChar(char c, int count, TestViEditMode mode)
        {
            string input = "";

            for (int i = 0; i < count; i++)
            {
                input += c;
            }
            mode.Input(input);
        }
Exemple #8
0
        public void ChangeOuterParen()
        {
            var mode = new TestViEditMode {
                Text = "((hello))"
            };

            RepeatChar('l', 3, mode);
            mode.Input("ca)");
            Assert.That(mode.Text, Is.EqualTo("()"));
        }
Exemple #9
0
        public void ChangeOuterQuote()
        {
            var mode = new TestViEditMode {
                Text = "'hello'"
            };

            RepeatChar('l', 3, mode);
            mode.Input("ca'");
            Assert.That(mode.Text, Is.Empty);
        }
Exemple #10
0
        public string ChangeInnerQuote(int col, char quote)
        {
            var mode = new TestViEditMode {
                Text = @"'hello' 'world\'s' 'worlder\\'s'".Replace('\'', quote)
            };

            RepeatChar('l', col, mode);
            mode.Input("ci" + quote);
            return(mode.Text);
        }
Exemple #11
0
        public void DeleteInnerParen()
        {
            var mode = new TestViEditMode {
                Text = "if (foo(baz) == bar) "
            };

            RepeatChar('l', 3, mode);
            mode.Input("di)");
            Assert.AreEqual("if () ", mode.Text);
        }
Exemple #12
0
        public void VisualInnerParen()
        {
            var mode = new TestViEditMode {
                Text = "if (foo(baz) == bar) "
            };

            RepeatChar('l', 3, mode);
            mode.Input("vi)");
            mode.AssertSelection(1, 5, 1, 20);
        }
Exemple #13
0
        public string ChangeInnerParen(int column)
        {
            var mode = new TestViEditMode {
                Text = "if (foo(baz) == bar) "
            };

            RepeatChar('l', column, mode);
            mode.Input("ci)");
            return(mode.Text);
        }
Exemple #14
0
        public string ChangeInnerWord(int column)
        {
            var mode = new TestViEditMode {
                Text = "if foo.bar[20]->baz_bay"
            };

            RepeatChar('l', column, mode);
            mode.Input("ciw");
            return(mode.Text);
        }
Exemple #15
0
        public void ChangeOuterParen_Multiline()
        {
            var mode = new TestViEditMode {
                Text = "((\n\thello\n))"
            };

            RepeatChar('j', 1, mode);
            RepeatChar('l', 4, mode);
            mode.Input("ca)");
            Assert.That(mode.Text, Is.EqualTo("()"));
        }
Exemple #16
0
		public void DeleteWord ()
		{
			var mode = new TestViEditMode () { Text =
@"abc def
ghy jklmn op
qrstu",
			};
			mode.Caret.Offset = 0;
			mode.Input ("jwlldw");
			Assert.AreEqual ("ghy jkop", mode.GetLine ());
		}
Exemple #17
0
		public void ChangeLine ()
		{
			var mode = new TestViEditMode () { Text =
@"   aaa aaa
   bbb bbb
   ccc ccc",
			};
			mode.Input ("jwllcceeee");
			Assert.AreEqual (
@"   aaa aaa
   eeee
   ccc ccc", mode.Text);
		}
Exemple #18
0
        public string ChangeInnerBrace(int row, int column)
        {
            var mode = new TestViEditMode {
                Text =
                    @"do { 
	foo
} forever;"
            };

            RepeatChar('j', row, mode);
            RepeatChar('l', column, mode);
            mode.Input("ci}");
            return(mode.Text);
        }
Exemple #19
0
		public void LineMotion ()
		{
			var mode = new TestViEditMode () { Text =
@"abc def
ghy jklmn op
qrstu
vwxyz",
			};
			mode.Caret.Offset = 0;
			Assert.AreEqual (1, mode.Line);
			mode.Input ('j');
			Assert.AreEqual (2, mode.Line);
			mode.Input ('k');
			Assert.AreEqual (1, mode.Line);
			mode.Input ("jjjj");
			Assert.AreEqual (4, mode.Line);
			mode.Caret.Line = 2;
			mode.Caret.Column = 12;
			mode.Input ('j');
			Assert.AreEqual (5, mode.Col);
			mode.Input ('k');
			Assert.AreEqual (12, mode.Col);
		}
Exemple #20
0
		public void DeleteLine ()
		{
			var mode = new TestViEditMode () { Text =
@"   aaa aaa
   bbb bbb
   ccc ccc",
			};
			mode.Input ("jwlldd");
			Assert.AreEqual (2, mode.Line);
			Assert.AreEqual (4, mode.Col);
			Assert.AreEqual (
@"   aaa aaa
   ccc ccc", mode.Text);
		}
Exemple #21
0
        public string ChangeInnerBrace_WithNestedMatchingBraces(int row, int column)
        {
            var mode = new TestViEditMode {
                Text =
                    @"{
	do
	{
		foo
	}
	do {
		bar
	}
}"
            };

            RepeatChar('j', row, mode);
            RepeatChar('l', column, mode);
            mode.Input("ci}");
            return(mode.Text);
        }
Exemple #22
0
		public void ColumnMotion ()
		{
			var mode = new TestViEditMode () { Text = "Test\nText" };
			Assert.AreEqual (1, mode.Col);
			mode.Input ('l');
			Assert.AreEqual (2, mode.Col);
			mode.Input ("ll");
			Assert.AreEqual (4, mode.Col);
			mode.Input ('l');
			Assert.AreEqual (4, mode.Col);
			mode.Input ("hh");
			Assert.AreEqual (2, mode.Col);
			mode.Input ('h');
			Assert.AreEqual (1, mode.Col);
			mode.Input ('h');
			Assert.AreEqual (1, mode.Col);
		}
Exemple #23
0
		public void ColumnMotion ()
		{
			var mode = new TestViEditMode () { Text = "Test\nText" };
			Assert.AreEqual (1, mode.Col);
			mode.Input ('l');
			Assert.AreEqual (2, mode.Col);
			mode.Input ("ll");
			Assert.AreEqual (4, mode.Col);
			mode.Input ('l');
			Assert.AreEqual (4, mode.Col);
			mode.Input ("hh");
			Assert.AreEqual (2, mode.Col);
			mode.Input ('h');
			Assert.AreEqual (1, mode.Col);
			mode.Input ('h');
			Assert.AreEqual (1, mode.Col);
		}
Exemple #24
0
		public void LineDeletePaste ()
		{
			var mode = new TestViEditMode () { Text =
@"   aaa aaa
   bbb bbb
   ccc ccc
   eee eee
   fff fff
   ggg ggg
   hhh hhh",
			};
			//move down, enter visual line mode, move down twice -> lines 2/3/4 selected -> delete
			mode.Input ("jjVjjd");
			Assert.AreEqual (
@"   aaa aaa
   bbb bbb
   ggg ggg
   hhh hhh", mode.Text);
			//enter visual line mode, move down once -> lines 1/2 selected -> delete
   			mode.Input ("Vkd");
			Assert.AreEqual (
@"   aaa aaa
   hhh hhh", mode.Text);
			//paste last delete below current line (1)
   			mode.Input ("p");
			Assert.AreEqual (
@"   aaa aaa
   hhh hhh
   bbb bbb
   ggg ggg", mode.Text);
			//paste last delete above current line (3)
   			mode.Input ("P");
			Assert.AreEqual (
@"   aaa aaa
   hhh hhh
   bbb bbb
   bbb bbb
   ggg ggg
   ggg ggg", mode.Text);
			Assert.AreEqual (5, mode.Line);
			//movement to/across boundaries, check selection still okay by deleting lines 1/2/3
			mode.Input ("kVlllllhhhhhhhhhhjjjhhhhhjjjjkkkkkkkkkkkkjd");
			Assert.AreEqual (
@"   aaa aaa
   ggg ggg
   ggg ggg", mode.Text);
		}
Exemple #25
0
		public void ChangeInnerBrace_IsntConfusedByQuotes (char startBrace, char endBrace, char quote)
		{
			var text = string.Format ("if {0}{2}{1}{2} == bar{1} ", startBrace, endBrace, quote);
			var mode = new TestViEditMode { Text = text };
			RepeatChar ('l', 4, mode);

			// Validate that our setups work. Use a specific case (the rest proved correct via induction).
			if (startBrace == '(' && quote == '\'') {
				Assert.AreEqual ("if (')' == bar) ", text, 
				                 "Validating that our test input because it's a bit too generic to be easy to read.");

				var plusMinusOneCharContext = "" + mode.GetChar(mode.Caret.Offset-1) + mode.GetChar(mode.Caret.Offset) 
					+ mode.GetChar(mode.Caret.Offset+1);
				Assert.AreEqual ("(')", plusMinusOneCharContext, "The cursor is where we expect it to be.");

				Assert.NotNull(mode.Document.BracketMatcher);
				Assert.IsInstanceOf<DefaultBracketMatcher>(mode.Document.BracketMatcher);

				var matchingParen = mode.Document.GetMatchingBracketOffset (3);
				Assert.AreEqual (14, matchingParen, "Validate setup correctly enabled mode.Document functionality.");
			}

			mode.Input ("ci" + endBrace);
			var expectedText = string.Format ("if {0}{1} ", startBrace, endBrace, quote);
			Assert.AreEqual (expectedText, mode.Text);
		}
Exemple #26
0
		public void ChangeOuterParen_Multiline() 
		{
			var mode = new TestViEditMode { Text = "((\n\thello\n))" };
			RepeatChar('j', 1, mode);
			RepeatChar('l', 4, mode);
			mode.Input ("ca)");
			Assert.That (mode.Text, Is.EqualTo ("()"));
		}
Exemple #27
0
		static void RepeatChar(char c, int count, TestViEditMode mode) 
		{
			string input = "";
			for (int i = 0; i < count; i++)
				input += c;
			mode.Input(input);
		}
Exemple #28
0
		public void ChangeOuterQuote() 
		{
			var mode = new TestViEditMode { Text = "'hello'" };
			RepeatChar('l', 3, mode);
			mode.Input ("ca'");
			Assert.That (mode.Text, Is.Empty);
		}
Exemple #29
0
		public void ChangeOuterParen() 
		{
			var mode = new TestViEditMode { Text = "((hello))" };
			RepeatChar('l', 3, mode);
			mode.Input ("ca)");
			Assert.That (mode.Text, Is.EqualTo ("()"));
		}
Exemple #30
0
		public void YankInnerParen() 
		{
			var mode = new TestViEditMode { Text = "if (foo(baz) == bar) " };
			RepeatChar('l', 3, mode);
			mode.Input ("yi)");
			mode.Input ("$p"); // HACK: I can't figure out how to test the register, so just paste at the end
			Assert.AreEqual ("if (foo(baz) == bar) foo(baz) == bar", mode.Text);
		}
Exemple #31
0
		public string ChangeInnerQuote (int col, char quote)
		{
			var mode = new TestViEditMode { Text = @"'hello' 'world\'s' 'worlder\\'s'".Replace ('\'', quote) };
			RepeatChar('l', col, mode);
			mode.Input ("ci" + quote);
			return mode.Text;
		}
Exemple #32
0
		public string ChangeInnerWord(int column) 
		{
			var mode = new TestViEditMode { Text = "if foo.bar[20]->baz_bay" };
			RepeatChar('l', column, mode);
			mode.Input ("ciw");
			return mode.Text;
		}
Exemple #33
0
		public void DeleteInnerParen() 
		{
			var mode = new TestViEditMode { Text = "if (foo(baz) == bar) " };
			RepeatChar('l', 3, mode);
			mode.Input ("di)");
			Assert.AreEqual ("if () ", mode.Text);
		}
Exemple #34
0
		public void DeleteToLineBoundary ()
		{
			var mode = new TestViEditMode () { Text =
@"   aaa bbb ccc ddd
   eee fff ggg hhh
   iii jjj kkk lll",
			};
			//move 3 words, delete to line end
			mode.Input ("wwwd$");
			Assert.AreEqual (
@"   aaa bbb 
   eee fff ggg hhh
   iii jjj kkk lll", mode.Text);
			//move down to 0 position, move 3 words, delete to home
			mode.Input ("j0wwwd^");
			Assert.AreEqual (
@"   aaa bbb
   ggg hhh
   iii jjj kkk lll", mode.Text);
			//move down to 0 position, move 3 words, delete to 0
			mode.Input ("j0wwwd0");
			Assert.AreEqual (
@"   aaa bbb
   ggg hhh
kkk lll", mode.Text);
		}
Exemple #35
0
		public string ChangeInnerBrace_WithNestedMatchingBraces(int row, int column)
		{
			var mode = new TestViEditMode { Text = 
@"{
	do
	{
		foo
	}
	do {
		bar
	}
}" };
			RepeatChar('j', row, mode);
			RepeatChar('l', column, mode);
			mode.Input ("ci}");
			return mode.Text;
		}
Exemple #36
0
		public string ChangeInnerBrace (int row, int column)
		{
			var mode = new TestViEditMode { Text = 
@"do { 
	foo
} forever;" };
			RepeatChar ('j', row, mode);
			RepeatChar ('l', column, mode);
			mode.Input ("ci}");
			return mode.Text;
		}
Exemple #37
0
		public string ChangeInnerParen(int column) 
		{
			var mode = new TestViEditMode { Text = "if (foo(baz) == bar) " };
			RepeatChar('l', column, mode);
			mode.Input ("ci)");
			return mode.Text;
		}
Exemple #38
0
		public void ChangeLine ()
		{
			var mode = new TestViEditMode () { Text =
@"   aaa aaa
   bbb bbb
   ccc ccc",
			};
			mode.Input ("jwllcceeee");
			Assert.AreEqual (
@"   aaa aaa
   eeee
   ccc ccc", mode.Text);
		}
Exemple #39
0
		public void VisualMotion ()
		{
			var mode = new TestViEditMode () { Text =
@"    aaa bbb ccc ddd
   eee fff ggg hhh
   iii jjj kkk lll
   mmm nnn ooo ppp
   qqq rrr sss ttt",
			};
			//move 2 lines down, 2 words in, enter visual mode
			mode.Input ("jjwwv");
			mode.AssertSelection (3, 8, 3, 9);
			//2 letters to right
			mode.Input ("ll");
			mode.AssertSelection (3, 8, 3, 11);
			//4 letters to left
			mode.Input ("hhhh");
			mode.AssertSelection (3, 9, 3, 6);
			//1 line up
			mode.Input ("k");
			mode.AssertSelection (3, 9, 2, 6);
			//1 line up
			mode.Input ("k");
			mode.AssertSelection (3, 9, 1, 6);
			//5 letters to right
			mode.Input ("lllll");
			mode.AssertSelection (3, 9, 1, 11);
			//3 lines down
			mode.Input ("jjj");
			mode.AssertSelection (3, 8, 4, 12);
		}
Exemple #40
0
		public void VisualInnerParen() 
		{
			var mode = new TestViEditMode { Text = "if (foo(baz) == bar) " };
			RepeatChar('l', 3, mode);
			mode.Input ("vi)");
			mode.AssertSelection (1, 5, 1, 20);
		}
Exemple #41
0
		public void DeleteWord ()
		{
			var mode = new TestViEditMode () { Text =
@"abc def
ghy jklmn op
qrstu",
			};
			mode.Caret.Offset = 0;
			mode.Input ("jwlldw");
			Assert.AreEqual ("ghy jkop", mode.GetLine ());
		}
Exemple #42
0
		public void DeleteLine ()
		{
			var mode = new TestViEditMode () { Text =
@"   aaa aaa
   bbb bbb
   ccc ccc",
			};
			mode.Input ("jwlldd");
			Assert.AreEqual (2, mode.Line);
			Assert.AreEqual (4, mode.Col);
			Assert.AreEqual (
@"   aaa aaa
   ccc ccc", mode.Text);
		}