Permalink
Browse files

Merge pull request #3 from ncolgan/add_bracket_support

Add support for square brackets and curly braces.
  • Loading branch information...
2 parents 3b3d30f + 7943a68 commit bbc3b60ab67580df672554cdb9b913821c1fb4d0 @georgebrock georgebrock committed Dec 14, 2012
Showing with 79 additions and 0 deletions.
  1. +14 −0 js/text_objects.js
  2. +65 −0 tests/acceptance/text_objects.js
View
@@ -60,6 +60,20 @@
textObjects['('] = textObjects['b'];
textObjects[')'] = textObjects['b'];
+ textObjects['['] = new Vimulator.TextObject({
+ name: "square brackets",
+ start: '[',
+ end: ']'
+ });
+ textObjects[']'] = textObjects['['];
+
+ textObjects['{'] = new Vimulator.TextObject({
+ name: "curly braces",
+ start: '{',
+ end: '}'
+ });
+ textObjects['}'] = textObjects['{'];
+
return {
'a': new C({
argument: "literal",
@@ -30,4 +30,69 @@ describe("Text objects", function () {
expect(currentText()).toBe("Some text, no brackets");
});
});
+
+ describe("curly braces", function () {
+ beforeEach(function () {
+ reset("Text {with curly braces} is great");
+ });
+
+ it("can specify text within braces", function () {
+ pressKeys("3wdi}");
+ expect(currentText()).toBe("Text {} is great");
+ });
+
+ it("matches when the cursor is on the opening brace", function () {
+ pressKeys("f{di{");
+ expect(currentText()).toBe("Text {} is great");
+ });
+
+ it("matches when the cursor is on the closing brace", function () {
+ pressKeys("f}di}");
+ expect(currentText()).toBe("Text {} is great");
+ });
+
+ it("can specify text including the braces", function () {
+ pressKeys("3wda}");
+ expect(currentText()).toBe("Text is great");
+ });
+
+ it("does nothing if there are no braces", function () {
+ reset("Some text, no braces");
+ pressKeys("da}");
+ expect(currentText()).toBe("Some text, no braces");
+ });
+ });
+
+ describe("square brackets", function () {
+ beforeEach(function () {
+ reset("Text [with a square bracket] is great");
+ });
+
+ it("can specify text within brackets", function () {
+ pressKeys("3wdi]");
+ expect(currentText()).toBe("Text [] is great");
+ });
+
+ it("matches when the cursor is on the opening bracket", function () {
+ pressKeys("f[di[");
+ expect(currentText()).toBe("Text [] is great");
+ });
+
+ it("matches when the cursor is on the closing bracket", function () {
+ pressKeys("f]di]");
+ expect(currentText()).toBe("Text [] is great");
+ });
+
+ it("can specify text including the brackets", function () {
+ pressKeys("3wda]");
+ expect(currentText()).toBe("Text is great");
+ });
+
+ it("does nothing if there are no brackets", function () {
+ reset("Some text, no brackets");
+ pressKeys("da]");
+ expect(currentText()).toBe("Some text, no brackets");
+ });
+ });
+
});

0 comments on commit bbc3b60

Please sign in to comment.