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 7cdf1be
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/cdktf/test/tokens/string-fragments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// string-fragments.test.ts
// SPDX-License-Identifier: MPL-2.0
import { TokenizedStringFragments } from "../../lib/tokens/string-fragments";
import { IFragmentConcatenator } from "../../lib/tokens/resolvable";

describe("TokenizedStringFragments", () => {
test("concat method correctly merges fragments from another instance", () => {
// Create two TokenizedStringFragments instances
const fragments1 = new TokenizedStringFragments();
const fragments2 = new TokenizedStringFragments();

// Add fragments to the first instance
fragments1.addLiteral("Hello");
fragments1.addLiteral(", ");

// Add fragments to the second instance
fragments2.addLiteral("World");
fragments2.addLiteral("!");

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

// The total number of fragments should now be 4
expect(fragments1.length).toBe(4);

// Verify that the fragments are correctly merged by joining them
const result = fragments1.join({
join(left: any, right: any): any {
return `${left}${right}`;
},
} as IFragmentConcatenator);

expect(result).toBe("Hello, World!");
});
});

0 comments on commit 7cdf1be

Please sign in to comment.