@@ -138,5 +138,62 @@ ASSUME(LET
138138 IN
139139 AssertEq ( SVGElemToString ( elem ) , "<text x='0' y='0'><<1, 2, 3>></text>" ) )
140140
141+ (* *****************************************************************************)
142+ (* Test SVGDoc operator *)
143+ (***************************************************************************** *)
144+
145+ \* Test SVGDoc with basic elements and viewBox
146+ ASSUME ( LET
147+ circle == Circle ( 50 , 50 , 20 , [ fill |-> "blue" ] )
148+ rect == Rect ( 10 , 10 , 30 , 40 , [ fill |-> "red" ] )
149+ doc == SVGDoc ( << circle , rect >> , 0 , 0 , 100 , 100 , [ width |-> "200" , height |-> "200" ] )
150+ expected == [ name |-> "svg" ,
151+ attrs |-> ( "xmlns:xlink" :> "http://www.w3.org/1999/xlink" @@
152+ "xmlns" :> "http://www.w3.org/2000/svg" @@
153+ "viewBox" :> "0 0 100 100" @@
154+ "width" :> "200" @@
155+ "height" :> "200" ) ,
156+ children |-> << << circle , rect >> >> ,
157+ innerText |-> "" ] IN
158+ AssertEq ( doc , expected ) )
159+
160+ \* Test SVGDoc with empty children and no additional attributes
161+ ASSUME ( LET
162+ doc == SVGDoc ( << >> , 10 , 20 , 800 , 600 , << >> )
163+ expected == [ name |-> "svg" ,
164+ attrs |-> ( "xmlns:xlink" :> "http://www.w3.org/1999/xlink" @@
165+ "xmlns" :> "http://www.w3.org/2000/svg" @@
166+ "viewBox" :> "10 20 800 600" ) ,
167+ children |-> << << >> >> ,
168+ innerText |-> "" ] IN
169+ AssertEq ( doc , expected ) )
170+
171+ \* Test SVGDoc string conversion
172+ ASSUME ( LET
173+ text == Text ( 25 , 25 , "Hello SVG" , [ fill |-> "green" ] )
174+ doc == SVGDoc ( text , 0 , 0 , 50 , 50 , [ id |-> "test-svg" ] )
175+ expectedString == "<svg id='test-svg' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 50 50'><text x='25' y='25' fill='green'>Hello SVG</text></svg>" IN
176+ AssertEq ( SVGElemToString ( doc ) , expectedString ) )
177+
178+ (* *****************************************************************************)
179+ (* Test SVGSerialize operator *)
180+ (***************************************************************************** *)
181+
182+ \* Test SVGSerialize creates a file (we can't directly test file creation in TLA+,
183+ \* but we can test that the operator doesn't crash and returns the expected result)
184+ ASSUME ( LET
185+ circle == Circle ( 25 , 25 , 15 , [ fill |-> "purple" ] )
186+ doc == SVGDoc ( circle , 0 , 0 , 50 , 50 , [ width |-> "100" , height |-> "100" ] )
187+ result == SVGSerialize ( doc , "test_frame_" , 1 ) IN
188+ \* SVGSerialize should return TRUE if successful (based on IOUtils pattern)
189+ result . exitValue = 0 )
190+
191+ \* Test SVGSerialize with different frame numbers
192+ ASSUME ( LET
193+ line == Line ( 0 , 0 , 50 , 50 , "stroke" :> "black" @@ "stroke-width" :> "2" )
194+ doc == SVGDoc ( line , 0 , 0 , 50 , 50 , << >> )
195+ result == SVGSerialize ( doc , "animation_" , 42 ) IN
196+ result . exitValue = 0 )
197+
141198
142199=============================================================================
0 commit comments