Adding test cases.
This commit is contained in:
parent
50d6e83eb0
commit
87999db659
|
@ -47,7 +47,10 @@ function testObject(object: any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function findOverlappingHelpers(context: object) {
|
function findOverlappingHelpers(context?: object) {
|
||||||
|
if (!context) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
const contextKeys = Object.keys(context)
|
const contextKeys = Object.keys(context)
|
||||||
return contextKeys.filter(key => helperNames.includes(key))
|
return contextKeys.filter(key => helperNames.includes(key))
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,10 @@ export const PreprocessorNames = {
|
||||||
class Preprocessor {
|
class Preprocessor {
|
||||||
name: string
|
name: string
|
||||||
private fn: any
|
private fn: any
|
||||||
private helperNames: string[]
|
|
||||||
|
|
||||||
constructor(name: string, fn: any) {
|
constructor(name: string, fn: any) {
|
||||||
this.name = name
|
this.name = name
|
||||||
this.fn = fn
|
this.fn = fn
|
||||||
this.helperNames = HelperNames()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process(fullString: string, statement: string, opts: Object) {
|
process(fullString: string, statement: string, opts: Object) {
|
||||||
|
@ -81,7 +79,7 @@ export const processors = [
|
||||||
if (
|
if (
|
||||||
!noHelpers &&
|
!noHelpers &&
|
||||||
!opts.disabledHelpers?.includes(testHelper) &&
|
!opts.disabledHelpers?.includes(testHelper) &&
|
||||||
this.helperNames.some(option => testHelper === option.toLowerCase())
|
HelperNames().some(option => testHelper === option.toLowerCase())
|
||||||
) {
|
) {
|
||||||
insideStatement = `(${insideStatement})`
|
insideStatement = `(${insideStatement})`
|
||||||
}
|
}
|
||||||
|
|
|
@ -483,3 +483,26 @@ describe("uuid", () => {
|
||||||
expect(output).toMatch(UUID_REGEX)
|
expect(output).toMatch(UUID_REGEX)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("helper overlap", () => {
|
||||||
|
it("should use context over helpers (regex test helper)", async () => {
|
||||||
|
const output = await processString("{{ test }}", { test: "a" })
|
||||||
|
expect(output).toEqual("a")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should use helper if no sum in context, return the context value otherwise", async () => {
|
||||||
|
const hbs = "{{ sum 1 2 }}"
|
||||||
|
const output = await processString(hbs, {})
|
||||||
|
expect(output).toEqual("3")
|
||||||
|
const secondaryOutput = await processString(hbs, { sum: "a" })
|
||||||
|
expect(secondaryOutput).toEqual("a")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should handle multiple cases", async () => {
|
||||||
|
const output = await processString("{{ literal (split test sum) }}", {
|
||||||
|
test: "a-b",
|
||||||
|
sum: "-",
|
||||||
|
})
|
||||||
|
expect(output).toEqual(["a", "b"])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue