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

Decaf the tests (2nd attempt) #299

Merged
merged 6 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
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
150 changes: 67 additions & 83 deletions spec/body-parser-spec.coffee → spec/body-parser-spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
BodyParser = require '../lib/snippet-body-parser'
const BodyParser = require('../lib/snippet-body-parser');

describe "Snippet Body Parser", ->
it "breaks a snippet body into lines, with each line containing tab stops at the appropriate position", ->
bodyTree = BodyParser.parse """
the quick brown $1fox ${2:jumped ${3:over}
}the ${4:lazy} dog
"""
describe("Snippet Body Parser", () => {
it("breaks a snippet body into lines, with each line containing tab stops at the appropriate position", () => {
const bodyTree = BodyParser.parse(`\
the quick brown $1fox \${2:jumped \${3:over}
}the \${4:lazy} dog\
`
);

expect(bodyTree).toEqual [
expect(bodyTree).toEqual([
"the quick brown ",
{index: 1, content: []},
"fox ",
Expand All @@ -18,31 +19,27 @@ describe "Snippet Body Parser", ->
{index: 3, content: ["over"]},
"\n"
],
}
"the "
},
"the ",
{index: 4, content: ["lazy"]},
" dog"
]

it "removes interpolated variables in placeholder text (we don't currently support it)", ->
bodyTree = BodyParser.parse """
module ${1:ActiveRecord::${TM_FILENAME/(?:\\A|_)([A-Za-z0-9]+)(?:\\.rb)?/(?2::\\u$1)/g}}
"""
]);
});

expect(bodyTree).toEqual [
it("removes interpolated variables in placeholder text (we don't currently support it)", () => {
const bodyTree = BodyParser.parse("module ${1:ActiveRecord::${TM_FILENAME/(?:\\A|_)([A-Za-z0-9]+)(?:\\.rb)?/(?2::\\u$1)/g}}");
expect(bodyTree).toEqual([
"module ",
{
"index": 1,
"content": ["ActiveRecord::", ""]
}
]
]);
});

it "skips escaped tabstops", ->
bodyTree = BodyParser.parse """
snippet $1 escaped \\$2 \\\\$3
"""

expect(bodyTree).toEqual [
it("skips escaped tabstops", () => {
const bodyTree = BodyParser.parse("snippet $1 escaped \\$2 \\\\$3");
expect(bodyTree).toEqual([
"snippet ",
{
index: 1,
Expand All @@ -53,41 +50,36 @@ describe "Snippet Body Parser", ->
index: 3,
content: []
}
]

it "includes escaped right-braces", ->
bodyTree = BodyParser.parse """
snippet ${1:{\\}}
"""
]);
});

expect(bodyTree).toEqual [
it("includes escaped right-braces", () => {
const bodyTree = BodyParser.parse("snippet ${1:{\\}}");
expect(bodyTree).toEqual([
"snippet ",
{
index: 1,
content: ["{}"]
}
]
]);
});

it "parses a snippet with transformations", ->
bodyTree = BodyParser.parse """
<${1:p}>$0</${1/f/F/}>
"""
expect(bodyTree).toEqual [
it("parses a snippet with transformations", () => {
const bodyTree = BodyParser.parse("<${1:p}>$0</${1/f/F/}>");
expect(bodyTree).toEqual([
'<',
{index: 1, content: ['p']},
'>',
{index: 0, content: []},
'</',
{index: 1, content: [], substitution: {find: /f/g, replace: ['F']}},
'>'
]

it "parses a snippet with multiple tab stops with transformations", ->
bodyTree = BodyParser.parse """
${1:placeholder} ${1/(.)/\\u$1/} $1 ${2:ANOTHER} ${2/^(.*)$/\\L$1/} $2
"""
]);
});

expect(bodyTree).toEqual [
it("parses a snippet with multiple tab stops with transformations", () => {
const bodyTree = BodyParser.parse("${1:placeholder} ${1/(.)/\\u$1/} $1 ${2:ANOTHER} ${2/^(.*)$/\\L$1/} $2");
expect(bodyTree).toEqual([
{index: 1, content: ['placeholder']},
' ',
{
Expand Down Expand Up @@ -119,15 +111,13 @@ describe "Snippet Body Parser", ->
},
' ',
{index: 2, content: []},
]
]);
});


it "parses a snippet with transformations and mirrors", ->
bodyTree = BodyParser.parse """
${1:placeholder}\n${1/(.)/\\u$1/}\n$1
"""

expect(bodyTree).toEqual [
it("parses a snippet with transformations and mirrors", () => {
const bodyTree = BodyParser.parse("${1:placeholder}\n${1/(.)/\\u$1/}\n$1");
expect(bodyTree).toEqual([
{index: 1, content: ['placeholder']},
'\n',
{
Expand All @@ -143,14 +133,12 @@ describe "Snippet Body Parser", ->
},
'\n',
{index: 1, content: []}
]

it "parses a snippet with a format string and case-control flags", ->
bodyTree = BodyParser.parse """
<${1:p}>$0</${1/(.)(.*)/\\u$1$2/}>
"""
]);
});

expect(bodyTree).toEqual [
it("parses a snippet with a format string and case-control flags", () => {
const bodyTree = BodyParser.parse("<${1:p}>$0</${1/(.)(.*)/\\u$1$2/}>");
expect(bodyTree).toEqual([
'<',
{index: 1, content: ['p']},
'>',
Expand All @@ -169,16 +157,14 @@ describe "Snippet Body Parser", ->
}
},
'>'
]

it "parses a snippet with an escaped forward slash in a transform", ->
# Annoyingly, a forward slash needs to be double-backslashed just like the
# other escapes.
bodyTree = BodyParser.parse """
<${1:p}>$0</${1/(.)\\/(.*)/\\u$1$2/}>
"""

expect(bodyTree).toEqual [
]);
});

it("parses a snippet with an escaped forward slash in a transform", () => {
// Annoyingly, a forward slash needs to be double-backslashed just like the
// other escapes.
const bodyTree = BodyParser.parse("<${1:p}>$0</${1/(.)\\/(.*)/\\u$1$2/}>");
expect(bodyTree).toEqual([
'<',
{index: 1, content: ['p']},
'>',
Expand All @@ -197,14 +183,12 @@ describe "Snippet Body Parser", ->
}
},
'>'
]

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

expect(bodyTree).toEqual [
it("parses a snippet with a placeholder that mirrors another tab stop's content", () => {
const bodyTree = BodyParser.parse("$4console.${3:log}('${2:$1}', $1);$0");
expect(bodyTree).toEqual([
{index: 4, content: []},
'console.',
{index: 3, content: ['log']},
Expand All @@ -218,14 +202,12 @@ describe "Snippet Body Parser", ->
{index: 1, content: []},
');',
{index: 0, content: []}
]

it "parses a snippet with a placeholder that mixes text and tab stop references", ->
bodyTree = BodyParser.parse """
$4console.${3:log}('${2:uh $1}', $1);$0
"""
]);
});

expect(bodyTree).toEqual [
it("parses a snippet with a placeholder that mixes text and tab stop references", () => {
const bodyTree = BodyParser.parse("$4console.${3:log}('${2:uh $1}', $1);$0");
expect(bodyTree).toEqual([
{index: 4, content: []},
'console.',
{index: 3, content: ['log']},
Expand All @@ -240,4 +222,6 @@ describe "Snippet Body Parser", ->
{index: 1, content: []},
');',
{index: 0, content: []}
]
]);
});
});
Loading