Skip to content

Commit

Permalink
test(template): add test-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
vvagaytsev committed Jun 25, 2024
1 parent d854bdf commit 57a97a1
Showing 1 changed file with 65 additions and 13 deletions.
78 changes: 65 additions & 13 deletions core/test/unit/src/template-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,22 +386,74 @@ describe("resolveTemplateString", () => {
})

context("partial resolution", () => {
it("a missing reference as the first clause returns the original template", () => {
const res = resolveTemplateString({
string: "${var.foo && 'a'}",
context: new TestContext({ var: {} }),
contextOpts: { allowPartial: true },
context("boolean operators", () => {
it("a missing reference as the first clause returns the original template", () => {
const res = resolveTemplateString({
string: "${var.foo && 'a'}",
context: new TestContext({ var: {} }),
contextOpts: { allowPartial: true },
})
expect(res).to.equal("${var.foo && 'a'}")
})
expect(res).to.equal("${var.foo && 'a'}")
})

it("a missing reference as the second clause returns the original template", () => {
const res = resolveTemplateString({
string: "${'a' && var.foo}",
context: new TestContext({ var: {} }),
contextOpts: { allowPartial: true },
it("a missing reference as the second clause returns the original template", () => {
const res = resolveTemplateString({
string: "${'a' && var.foo}",
context: new TestContext({ var: {} }),
contextOpts: { allowPartial: true },
})
expect(res).to.equal("${'a' && var.foo}")
})
expect(res).to.equal("${'a' && var.foo}")
})

context("arithmetic operators", () => {
const arithmeticOperators = ["-", "*", "/", "%", ">", ">=", "<", "<="]
for (const operator of arithmeticOperators) {
describe(`with ${operator} operator`, () => {
it("a missing reference as the first clause returns the original template", () => {
const res = resolveTemplateString({
string: `$\{var.foo ${operator} 2}`,
context: new TestContext({ var: {} }),
contextOpts: { allowPartial: true },
})
expect(res).to.equal(`$\{var.foo ${operator} 2}`)
})

it("a missing reference as the second clause returns the original template", () => {
const res = resolveTemplateString({
string: `$\{2 ${operator} var.foo}`,
context: new TestContext({ var: {} }),
contextOpts: { allowPartial: true },
})
expect(res).to.equal(`$\{2 ${operator} var.foo}`)
})
})
}
})

context("overloaded operators", () => {
const overLoadedOperators = ["+"]
for (const operator of overLoadedOperators) {
describe(`with ${operator} operator`, () => {
it(`a missing reference as the first clause returns the original template`, () => {
const res = resolveTemplateString({
string: `$\{var.foo ${operator} '2'}`,
context: new TestContext({ var: {} }),
contextOpts: { allowPartial: true },
})
expect(res).to.equal(`$\{var.foo ${operator} '2'}`)
})

it("a missing reference as the second clause returns the original template", () => {
const res = resolveTemplateString({
string: `$\{2 ${operator} var.foo}`,
context: new TestContext({ var: {} }),
contextOpts: { allowPartial: true },
})
expect(res).to.equal(`$\{2 ${operator} var.foo}`)
})
})
}
})
})
})
Expand Down

0 comments on commit 57a97a1

Please sign in to comment.