Skip to content

Commit

Permalink
test(template): add more test cases suggested in CR
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Beyer <[email protected]>
  • Loading branch information
vvagaytsev and TimBeyer committed Aug 22, 2024
1 parent da09afa commit 51d2c1b
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions core/test/unit/src/template-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,69 @@ describe("resolveTemplateString", () => {
expect(res).to.equal("${bar}")
})

it("should allow nesting normal strings within escaped strings", () => {
const res = resolveTemplateString({
string: "$${var.${foo}}",
context: new TestContext({ foo: "yes" }),
contextOpts: { unescape: true },
})
expect(res).to.equal("${var.yes}")
})

it("should allow nesting escaped strings within normal strings", () => {
const res = resolveTemplateString({
string: "${foo == 'yes' ? '$${bar}' : 'fail' }",
context: new TestContext({ foo: "yes" }),
contextOpts: { unescape: true },
})
expect(res).to.equal("${bar}")
})

it("should escape things correctly", () => {
const res = resolveTemplateString({
string: "$${env.TEST_ENV}",
context: new TestContext({}),
contextOpts: { unescape: true },
})
expect(res).to.equal("${env.TEST_ENV}")
})

it("should escape things correctly", () => {
const res = resolveTemplateString({
string: "foo $${env.TEST_ENV} bar",
context: new TestContext({}),
contextOpts: { unescape: true },
})
expect(res).to.equal("foo ${env.TEST_ENV} bar")
})

it("should escape things correctly", () => {
const res = resolveTemplateString({
string: "$${env:TEST_ENV}",
context: new TestContext({}),
contextOpts: { unescape: true },
})
expect(res).to.equal("${env:TEST_ENV}")
})

it("should escape things correctly", () => {
const res = resolveTemplateString({
string: "foo $${env:TEST_ENV} bar",
context: new TestContext({}),
contextOpts: { unescape: true },
})
expect(res).to.equal("foo ${env:TEST_ENV} bar")
})

it("should escape things correctly", () => {
const res = resolveTemplateString({
string: "${foo}-$${env:TEST_ENV}",
context: new TestContext({ foo: "foo" }),
contextOpts: { unescape: true },
})
expect(res).to.equal("foo-${env:TEST_ENV}")
})

it("should allow mixing normal and escaped strings", () => {
const res = resolveTemplateString({
string: "${foo}-and-$${var.nope}",
Expand Down

0 comments on commit 51d2c1b

Please sign in to comment.