|
| 1 | +import assert from "node:assert" |
| 2 | +import renderIntrinsicFunction from "../renderIntrinsicFunction.js" |
| 3 | + |
| 4 | +describe("renderIntrinsicFunction", () => { |
| 5 | + it("should process Fn::Join correctly", () => { |
| 6 | + const input = { "Fn::Join": [":", ["a", "b", "c"]] } |
| 7 | + const result = renderIntrinsicFunction(input) |
| 8 | + assert.strictEqual(result, "a:b:c") |
| 9 | + }) |
| 10 | + |
| 11 | + it("should process !Join correctly", () => { |
| 12 | + const input = { "!Join": [":", ["a", "b", "c"]] } |
| 13 | + const result = renderIntrinsicFunction(input) |
| 14 | + assert.strictEqual(result, "a:b:c") |
| 15 | + }) |
| 16 | + |
| 17 | + it("should process Fn::Sub correctly", () => { |
| 18 | + const input = { |
| 19 | + "Fn::Sub": ["The name is ${name}", { name: "CloudFormation" }], // eslint-disable-line no-template-curly-in-string |
| 20 | + } |
| 21 | + const result = renderIntrinsicFunction(input) |
| 22 | + assert.strictEqual(result, "The name is CloudFormation") |
| 23 | + }) |
| 24 | + |
| 25 | + it("should process !Sub correctly", () => { |
| 26 | + const input = { "!Sub": ["Hello ${name}", { name: "World" }] } // eslint-disable-line no-template-curly-in-string |
| 27 | + const result = renderIntrinsicFunction(input) |
| 28 | + assert.strictEqual(result, "Hello World") |
| 29 | + }) |
| 30 | + |
| 31 | + it("should process nested Join correctly", () => { |
| 32 | + const input = { |
| 33 | + "Fn::Join": ["-", [{ "!Join": [":", ["a", "b", "c"]] }, "d"]], |
| 34 | + } |
| 35 | + const result = renderIntrinsicFunction(input) |
| 36 | + assert.strictEqual(result, "a:b:c-d") |
| 37 | + }) |
| 38 | + |
| 39 | + it("should process plain strings without modification", () => { |
| 40 | + const input = "This is a plain string" |
| 41 | + const result = renderIntrinsicFunction(input) |
| 42 | + assert.strictEqual(result, "This is a plain string") |
| 43 | + }) |
| 44 | + |
| 45 | + it("should process numbers without modification", () => { |
| 46 | + const input = 42 |
| 47 | + const result = renderIntrinsicFunction(input) |
| 48 | + assert.strictEqual(result, 42) |
| 49 | + }) |
| 50 | + |
| 51 | + it("should process arrays without intrinsic functions", () => { |
| 52 | + const input = ["a", "b", "c"] |
| 53 | + const result = renderIntrinsicFunction(input) |
| 54 | + assert.deepStrictEqual(result, ["a", "b", "c"]) |
| 55 | + }) |
| 56 | + |
| 57 | + it("should process nested intrinsic functions in arrays", () => { |
| 58 | + const input = ["a", { "Fn::Join": [":", ["b", "c"]] }, "d"] |
| 59 | + const result = renderIntrinsicFunction(input) |
| 60 | + assert.deepStrictEqual(result, ["a", "b:c", "d"]) |
| 61 | + }) |
| 62 | + |
| 63 | + it("should throw an error for unsupported intrinsic functions", () => { |
| 64 | + const input = { "Fn::UnsupportedFunction": "Value" } |
| 65 | + const result = renderIntrinsicFunction(input) |
| 66 | + assert.deepStrictEqual(result, { "Fn::UnsupportedFunction": "Value" }) |
| 67 | + }) |
| 68 | + |
| 69 | + it("should throw an error for unsupported shorthand intrinsic functions", () => { |
| 70 | + const input = { "!UnsupportedFunction": "Value" } |
| 71 | + const result = renderIntrinsicFunction(input) |
| 72 | + assert.deepStrictEqual(result, { "!UnsupportedFunction": "Value" }) |
| 73 | + }) |
| 74 | + |
| 75 | + it("should process nested arrays with intrinsic functions", () => { |
| 76 | + const input = ["a", ["b", { "!Join": [":", ["c", "d"]] }]] |
| 77 | + const result = renderIntrinsicFunction(input) |
| 78 | + assert.deepStrictEqual(result, ["a", ["b", "c:d"]]) |
| 79 | + }) |
| 80 | +}) |
0 commit comments