@@ -127,6 +127,69 @@ describe("evaluate", () => {
127127 . toEqual ( Data . fromUint ( 42n % 0x1fn ) ) ;
128128 } ) ;
129129
130+ describe ( "evaluates concat expressions" , ( ) => {
131+ it ( "concatenates hex literals" , async ( ) => {
132+ const expression : Pointer . Expression = {
133+ $concat : [ "0x00" , "0x00" ]
134+ } ;
135+ expect ( await evaluate ( expression , options ) )
136+ . toEqual ( Data . fromHex ( "0x0000" ) ) ;
137+ } ) ;
138+
139+ it ( "concatenates multiple values preserving byte widths" , async ( ) => {
140+ const expression : Pointer . Expression = {
141+ $concat : [ "0xdead" , "0xbeef" ]
142+ } ;
143+ expect ( await evaluate ( expression , options ) )
144+ . toEqual ( Data . fromHex ( "0xdeadbeef" ) ) ;
145+ } ) ;
146+
147+ it ( "returns empty data for empty operand list" , async ( ) => {
148+ const expression : Pointer . Expression = {
149+ $concat : [ ]
150+ } ;
151+ expect ( await evaluate ( expression , options ) )
152+ . toEqual ( Data . zero ( ) ) ;
153+ } ) ;
154+
155+ it ( "preserves single operand unchanged" , async ( ) => {
156+ const expression : Pointer . Expression = {
157+ $concat : [ "0xabcdef" ]
158+ } ;
159+ expect ( await evaluate ( expression , options ) )
160+ . toEqual ( Data . fromHex ( "0xabcdef" ) ) ;
161+ } ) ;
162+
163+ it ( "concatenates variables" , async ( ) => {
164+ const expression : Pointer . Expression = {
165+ $concat : [ "foo" , "bar" ]
166+ } ;
167+ // foo = 0x2a (42), bar = 0x1f
168+ expect ( await evaluate ( expression , options ) )
169+ . toEqual ( Data . fromHex ( "0x2a1f" ) ) ;
170+ } ) ;
171+
172+ it ( "concatenates nested expressions" , async ( ) => {
173+ const expression : Pointer . Expression = {
174+ $concat : [
175+ { $sum : [ 1 , 2 ] } , // 3 = 0x03
176+ "0xff"
177+ ]
178+ } ;
179+ expect ( await evaluate ( expression , options ) )
180+ . toEqual ( Data . fromHex ( "0x03ff" ) ) ;
181+ } ) ;
182+
183+ it ( "preserves leading zeros in hex literals" , async ( ) => {
184+ const expression : Pointer . Expression = {
185+ $concat : [ "0x0001" , "0x0002" ]
186+ } ;
187+ const result = await evaluate ( expression , options ) ;
188+ expect ( result ) . toEqual ( Data . fromHex ( "0x00010002" ) ) ;
189+ expect ( result . length ) . toBe ( 4 ) ;
190+ } ) ;
191+ } ) ;
192+
130193 // skipped because test does not perform proper padding
131194 it . skip ( "evaluates keccak256 expressions" , async ( ) => {
132195 const expression : Pointer . Expression = {
0 commit comments