-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(lib): add test for concat method in TokenizedStringFragments
Added a test case to verify that the `concat` method correctly merges fragments from another instance.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
}); |