Skip to content
Browse files

Add support for square brackets and curly braces.

  • Loading branch information...
1 parent 3b3d30f commit 7943a6848a9a5a2e93a0aa6bd7826873dadbc0f0 @ncolgan ncolgan committed Dec 13, 2012
Showing with 79 additions and 0 deletions.
  1. +14 −0 js/text_objects.js
  2. +65 −0 tests/acceptance/text_objects.js
View
14 js/text_objects.js
@@ -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",
View
65 tests/acceptance/text_objects.js
@@ -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 7943a68

Please sign in to comment.
Something went wrong with that request. Please try again.