Skip to content

Commit

Permalink
fix(config): whitespace was incorrrectly stripped around format strings
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Jul 24, 2019
1 parent 91047e5 commit ee32557
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions garden-service/src/template-string-parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ InvalidFormatString
}

FormatStart
= ws "${" ws
= "${" ws

FormatEnd
= ws "}" ws
= ws "}"

Identifier
= [a-zA-Z][a-zA-Z0-9_\-]* { return text() }
Expand Down
15 changes: 15 additions & 0 deletions garden-service/test/unit/src/template-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ describe("resolveTemplateString", async () => {
expect(res).to.equal("value-suffix")
})

it("should interpolate a format string with a prefix with whitespace", async () => {
const res = await resolveTemplateString("prefix ${some}", new TestContext({ some: "value" }))
expect(res).to.equal("prefix value")
})

it("should interpolate a format string with a suffix with whitespace", async () => {
const res = await resolveTemplateString("${some} suffix", new TestContext({ some: "value" }))
expect(res).to.equal("value suffix")
})

it("should correctly interpolate a format string with surrounding whitespace", async () => {
const res = await resolveTemplateString("prefix ${some} suffix", new TestContext({ some: "value" }))
expect(res).to.equal("prefix value suffix")
})

it("should handle a nested key", async () => {
const res = await resolveTemplateString("${some.nested}", new TestContext({ some: { nested: "value" } }))
expect(res).to.equal("value")
Expand Down

0 comments on commit ee32557

Please sign in to comment.