@@ -61,6 +61,47 @@ describe("deltaMap", function(): ()
6161 c .write (ch , { a = 1 , b = 2 })
6262 expect (ch .cursor ):toBeLessThan (w1 )
6363 end )
64+ it ("numeric keys full round-trip" , function (): ()
65+ Baseline .setReadKey (false )
66+ local c = Lync .deltaMap (Lync .u16 , Lync .string )
67+ local r = roundTrip (c , { [1 ] = "one" , [2 ] = "two" , [300 ] = "three hundred" })
68+ expect (r [1 ]):toBe ("one" )
69+ expect (r [2 ]):toBe ("two" )
70+ expect (r [300 ]):toBe ("three hundred" )
71+ end )
72+ it ("numeric keys unchanged is smaller" , function (): ()
73+ Baseline .setReadKey (false )
74+ local c = Lync .deltaMap (Lync .u16 , Lync .string )
75+ local ch = Channel .create ()
76+ c .write (ch , { [1 ] = "one" , [2 ] = "two" })
77+ local fullSize = ch .cursor
78+ ch .cursor = 0
79+ c .write (ch , { [1 ] = "one" , [2 ] = "two" })
80+ expect (ch .cursor ):toBeLessThan (fullSize )
81+ end )
82+ it ("numeric keys upsert and remove" , function (): ()
83+ Baseline .setReadKey (false )
84+ local c = Lync .deltaMap (Lync .u16 , Lync .u8 )
85+ local ch = Channel .create ()
86+
87+ -- First write: full frame
88+ c .write (ch , { [10 ] = 100 , [20 ] = 200 })
89+ local buf1 = buffer.create (ch .cursor )
90+ buffer.copy (buf1 , 0 , ch .buff , 0 , ch .cursor )
91+ local r1 = c .read (buf1 , 0 , nil )
92+ expect (r1 [10 ]):toBe (100 )
93+ expect (r1 [20 ]):toBe (200 )
94+
95+ -- Second write: remove key 20, add key 30, change key 10
96+ ch .cursor = 0
97+ c .write (ch , { [10 ] = 50 , [30 ] = 150 })
98+ local buf2 = buffer.create (ch .cursor )
99+ buffer.copy (buf2 , 0 , ch .buff , 0 , ch .cursor )
100+ local r2 = c .read (buf2 , 0 , nil )
101+ expect (r2 [10 ]):toBe (50 )
102+ expect (r2 [30 ]):toBe (150 )
103+ expect (r2 [20 ]):toBe (nil )
104+ end )
64105end )
65106
66107return nil
0 commit comments