-
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
35 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,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!"); | ||
}); | ||
}); |