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

Commit

Permalink
parser specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerijo committed Jul 24, 2020
1 parent 9630b66 commit d1d4cfc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 195 deletions.
1 change: 1 addition & 0 deletions lib/snippet-expansion.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = class SnippetExpansion {
this.subscriptions = new CompositeDisposable
this.tabStopMarkers = []
this.selections = [this.cursor.selection]
this.markerLayer = this.editor.addMarkerLayer()

const startPosition = this.cursor.selection.getBufferRange().start
let {body, tabStopList} = this.snippet
Expand Down
195 changes: 0 additions & 195 deletions spec/body-parser-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,199 +438,4 @@ describe("Snippet Body Parser", () => {
]);
});
});

describe("examples", () => {
it("breaks a snippet body into lines, with each line containing tab stops at the appropriate position", () => {
expectMatch("the quick brown $1fox ${2:jumped ${3:over}\n}the ${4:lazy} dog", [
"the quick brown ",
{ index: 1 },
"fox ",
{
index: 2,
content: [
"jumped ",
{ index: 3, content: ["over"] },
"\n"
],
},
"the ",
{ index: 4, content: ["lazy"] },
" dog"
]);
});

it("supports interpolated variables in placeholder text", () => {
expectMatch("module ${1:ActiveRecord::${TM_FILENAME/(?:\\A|_)([A-Za-z0-9]+)(?:\\.rb)?/(?2::\\u$1)/g}}", [
"module ",
{
index: 1,
content: [
"ActiveRecord::",
{
variable: "TM_FILENAME",
transformation: {
find: /(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/g,
replace: [
"(?2::",
{
modifier: "u",
},
{
backreference: 1,
},
")",
]
}
}
],
}
]);
});

it("parses a snippet with transformations", () => {
expectMatch("<${1:p}>$0</${1/f/F/}>", [
'<',
{ index: 1, content: ['p'] },
'>',
{ index: 0 },
'</',
{ index: 1, transformation: { find: /f/, replace: ['F'] } },
'>',
]);
});

it("parses a snippet with multiple tab stops with transformations", () => {
expectMatch("${1:placeholder} ${1/(.)/\\u$1/} $1 ${2:ANOTHER} ${2/^(.*)$/\\L$1/} $2", [
{ index: 1, content: ['placeholder'] },
' ',
{
index: 1,
transformation: {
find: /(.)/,
replace: [
{ modifier: 'u' },
{ backreference: 1 },
],
},
},
' ',
{ index: 1 },
' ',
{ index: 2, content: ['ANOTHER'] },
' ',
{
index: 2,
transformation: {
find: /^(.*)$/,
replace: [
{ modifier: 'L' },
{ backreference: 1 },
],
},
},
' ',
{ index: 2 },
]);
});

it("parses a snippet with transformations and mirrors", () => {
expectMatch("${1:placeholder}\n${1/(.)/\\u$1/}\n$1", [
{ index: 1, content: ['placeholder'] },
'\n',
{
index: 1,
transformation: {
find: /(.)/,
replace: [
{ modifier: 'u' },
{ backreference: 1 },
],
},
},
'\n',
{ index: 1 },
]);
});

it("parses a snippet with a format string and case-control flags", () => {
expectMatch("<${1:p}>$0</${1/(.)(.*)/\\u$1$2/}>", [
'<',
{ index: 1, content: ['p'] },
'>',
{ index: 0 },
'</',
{
index: 1,
transformation: {
find: /(.)(.*)/,
replace: [
{ modifier: 'u' },
{ backreference: 1 },
{ backreference: 2 },
],
},
},
'>',
]);
});

it("parses a snippet with an escaped forward slash in a transform", () => {
expectMatch("<${1:p}>$0</${1/(.)\\/(.*)/\\u$1$2/}>", [
'<',
{ index: 1, content: ['p'] },
'>',
{ index: 0 },
'</',
{
index: 1,
transformation: {
find: /(.)\/(.*)/,
replace: [
{ modifier: 'u' },
{ backreference: 1 },
{ backreference: 2 },
],
},
},
'>',
]);
});

it("parses a snippet with a placeholder that mirrors another tab stop's content", () => {
expectMatch("$4console.${3:log}('${2:$1}', $1);$0", [
{ index: 4 },
'console.',
{ index: 3, content: ['log'] },
'(\'',
{
index: 2, content: [
{ index: 1 }
]
},
'\', ',
{ index: 1 },
');',
{ index: 0 }
]);
});

it("parses a snippet with a placeholder that mixes text and tab stop references", () => {
expectMatch("$4console.${3:log}('${2:uh $1}', $1);$0", [
{ index: 4 },
'console.',
{ index: 3, content: ['log'] },
'(\'',
{
index: 2, content: [
'uh ',
{ index: 1 }
]
},
'\', ',
{ index: 1 },
');',
{ index: 0 }
]);
});
});
});

0 comments on commit d1d4cfc

Please sign in to comment.