@@ -42,6 +42,18 @@ struct TableRowsConstructionTests {
4242 #expect( table. rows [ 0 ] . values == [ " 1 " ] )
4343 #expect( table. rows [ 1 ] . values == [ " 2 " ] )
4444 }
45+
46+ @Test ( " Factory pads short rows and truncates long rows to columns.count " )
47+ func factoryNormalizesRowWidth( ) {
48+ let table = TableRows . from (
49+ queryRows: [ [ " a " ] , [ " b " , " c " , " extra " ] ] ,
50+ columns: [ " c1 " , " c2 " ] ,
51+ columnTypes: [ . text( rawType: nil ) , . text( rawType: nil ) ]
52+ )
53+ #expect( table. count == 2 )
54+ #expect( table. rows [ 0 ] . values == [ " a " , nil ] )
55+ #expect( table. rows [ 1 ] . values == [ " b " , " c " ] )
56+ }
4557}
4658
4759@Suite ( " TableRows - reads " )
@@ -137,7 +149,8 @@ struct TableRowsEditTests {
137149 let delta = table. editMany ( [
138150 ( row: 0 , column: 0 , value: " a " ) ,
139151 ( row: 0 , column: 1 , value: " y " ) ,
140- ( row: 99 , column: 0 , value: " ignored " )
152+ ( row: 99 , column: 0 , value: " ignored " ) ,
153+ ( row: 0 , column: 99 , value: " ignored " )
141154 ] )
142155 let expected : Set < CellPosition > = [ CellPosition ( row: 0 , column: 1 ) ]
143156 #expect( delta == . cellsChanged( expected) )
@@ -311,6 +324,22 @@ struct TableRowsReplaceTests {
311324 #expect( table. rows [ 0 ] . id == . existing( 0 ) )
312325 #expect( table. rows [ 0 ] . values == [ " x " ] )
313326 }
327+
328+ @Test ( " replace with non-zero offset assigns existing IDs starting from offset " )
329+ func replaceWithNonZeroOffsetAssignsExistingIDs( ) {
330+ var table = TableRows . from (
331+ queryRows: [ [ " a " ] ] ,
332+ columns: [ " c1 " ] ,
333+ columnTypes: [ . text( rawType: nil ) ]
334+ )
335+ let delta = table. replace ( rows: [ [ " x " ] , [ " y " ] ] , offset: 5 )
336+ #expect( delta == . fullReplace)
337+ #expect( table. count == 2 )
338+ #expect( table. rows [ 0 ] . id == . existing( 5 ) )
339+ #expect( table. rows [ 1 ] . id == . existing( 6 ) )
340+ #expect( table. rows [ 0 ] . values == [ " x " ] )
341+ #expect( table. rows [ 1 ] . values == [ " y " ] )
342+ }
314343}
315344
316345@Suite ( " TableRows - metadata " )
0 commit comments