Skip to content

Commit

Permalink
test(lib): add test for concat method in TokenizedStringFragments
Browse files Browse the repository at this point in the history
Added a test case to verify that the `concat` method correctly merges fragments from another instance.
  • Loading branch information
suojae committed Nov 25, 2024
1 parent b1365fc commit 453cb0c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/cdktf/test/tokens/string-fragments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// string-fragments.test.ts
// SPDX-License-Identifier: MPL-2.0
import { TokenizedStringFragments } from "../../lib/tokens/string-fragments";
import { IFragmentConcatenator } from "../../lib/tokens/resolvable";

// Helper function to create fragments with literals
function createFragments(...literals: string[]): TokenizedStringFragments {
const fragments = new TokenizedStringFragments();
literals.forEach((literal) => fragments.addLiteral(literal));
return fragments;
}

describe("TokenizedStringFragments", () => {
test("concat method should merge fragments correctly", () => {
// Arrange: Create two instances with literals
const fragments1 = createFragments("Hello", ", ");
const fragments2 = createFragments("World", "!");

// Act: Concatenate fragments2 into fragments1
fragments1.concat(fragments2);

// Assert: Check the length and combined result
expect(fragments1.length).toBe(4); // Verify total number of fragments
const concatenatedResult = fragments1.join({
join(left: any, right: any): string {
return `${left}${right}`;
},
} as IFragmentConcatenator);

expect(concatenatedResult).toBe("Hello, World!"); // Verify merged content
});
});

0 comments on commit 453cb0c

Please sign in to comment.