File tree 2 files changed +32
-1
lines changed
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ export class TokenizedStringFragments {
87
87
}
88
88
89
89
public concat ( other : TokenizedStringFragments ) : void {
90
- this . fragments . concat ( other . fragments ) ;
90
+ this . fragments . push ( ... other . fragments ) ;
91
91
}
92
92
93
93
/**
Original file line number Diff line number Diff line change
1
+ // Copyright (c) HashiCorp, Inc
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ import { TokenizedStringFragments } from "../../lib/tokens/string-fragments" ;
4
+ import { IFragmentConcatenator } from "../../lib/tokens/resolvable" ;
5
+
6
+ describe ( "TokenizedStringFragments" , ( ) => {
7
+ test ( "concat method should merge fragments correctly" , ( ) => {
8
+ // Arrange: Create two instances with literals
9
+ const fragments1 = new TokenizedStringFragments ( ) ;
10
+ fragments1 . addLiteral ( "Hello" ) ;
11
+ fragments1 . addLiteral ( ", " ) ;
12
+
13
+ const fragments2 = new TokenizedStringFragments ( ) ;
14
+ fragments2 . addLiteral ( "World" ) ;
15
+ fragments2 . addLiteral ( "!" ) ;
16
+
17
+ // Act: Concatenate fragments2 into fragments1
18
+ fragments1 . concat ( fragments2 ) ;
19
+
20
+ // Assert: Check the length and combined result
21
+ expect ( fragments1 . length ) . toBe ( 4 ) ; // Verify total number of fragments
22
+
23
+ const result = fragments1 . join ( {
24
+ join ( left : any , right : any ) : string {
25
+ return `${ left } ${ right } ` ;
26
+ } ,
27
+ } as IFragmentConcatenator ) ;
28
+
29
+ expect ( result ) . toBe ( "Hello, World!" ) ; // Verify merged content
30
+ } ) ;
31
+ } ) ;
You can’t perform that action at this time.
0 commit comments