Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lib): correct the concat method in TokenizedStringFragments #3772

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cdktf/lib/tokens/string-fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class TokenizedStringFragments {
}

public concat(other: TokenizedStringFragments): void {
this.fragments.concat(other.fragments);
this.fragments.push(...other.fragments);
}

/**
Expand Down
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
});
});
Loading