Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Add regression tests for tab stops at ends of snippets #289

Merged
merged 3 commits into from
Apr 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions spec/snippets-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ describe "Snippets extension", ->
${2:placeholder ending second line}
"""

"tab stops at beginning and then end of snippet":
prefix: "t6b"
body: "$1expanded$0"

"tab stops at end and then beginning of snippet":
prefix: "t6c"
body: "$0expanded$1"

"contains empty lines":
prefix: "t7"
body: """
Expand Down Expand Up @@ -581,15 +589,40 @@ describe "Snippets extension", ->
expect(editor.getSelectedBufferRange()).toEqual [[0, 0], [0, 4]]

describe "when a previous snippet expansion has just been undone", ->
it "expands the snippet based on the current prefix rather than jumping to the old snippet's tab stop", ->
editor.insertText 't6\n'
editor.setCursorBufferPosition [0, 2]
simulateTabKeyEvent()
expect(editor.lineTextForBufferRow(0)).toBe "first line"
editor.undo()
expect(editor.lineTextForBufferRow(0)).toBe "t6"
simulateTabKeyEvent()
expect(editor.lineTextForBufferRow(0)).toBe "first line"
describe "when the tab stops appear in the middle of the snippet", ->
it "expands the snippet based on the current prefix rather than jumping to the old snippet's tab stop", ->
editor.insertText 't6\n'
editor.setCursorBufferPosition [0, 2]
simulateTabKeyEvent()
expect(editor.lineTextForBufferRow(0)).toBe "first line"
editor.undo()
expect(editor.lineTextForBufferRow(0)).toBe "t6"
simulateTabKeyEvent()
expect(editor.lineTextForBufferRow(0)).toBe "first line"

describe "when the tab stops appear at the beginning and then the end of snippet", ->
it "expands the snippet based on the current prefix rather than jumping to the old snippet's tab stop", ->
editor.insertText 't6b\n'
editor.setCursorBufferPosition [0, 3]
simulateTabKeyEvent()
expect(editor.lineTextForBufferRow(0)).toBe "expanded"
editor.undo()
expect(editor.lineTextForBufferRow(0)).toBe "t6b"
simulateTabKeyEvent()
expect(editor.lineTextForBufferRow(0)).toBe "expanded"
expect(editor.getCursorBufferPosition()).toEqual([0, 0])

describe "when the tab stops appear at the end and then the beginning of snippet", ->
it "expands the snippet based on the current prefix rather than jumping to the old snippet's tab stop", ->
editor.insertText 't6c\n'
editor.setCursorBufferPosition [0, 3]
simulateTabKeyEvent()
expect(editor.lineTextForBufferRow(0)).toBe "expanded"
editor.undo()
expect(editor.lineTextForBufferRow(0)).toBe "t6c"
simulateTabKeyEvent()
expect(editor.lineTextForBufferRow(0)).toBe "expanded"
expect(editor.getCursorBufferPosition()).toEqual([0, 8])

describe "when the prefix contains non-word characters", ->
it "selects the non-word characters as part of the prefix", ->
Expand Down