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

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

const fragments2 = new TokenizedStringFragments();
fragments2.addLiteral("World");
fragments2.addLiteral("!");

// 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 result = fragments1.join({
join(left: any, right: any): string {
return `${left}${right}`;
},
} as IFragmentConcatenator);

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

0 comments on commit f0c8272

Please sign in to comment.