@@ -37,6 +37,106 @@ const xmlText =
3737 ' </block>\n' +
3838 '</xml>' ;
3939
40+ const json = {
41+ 'blocks' : {
42+ 'languageVersion' : 0 ,
43+ 'blocks' : [
44+ {
45+ 'type' : 'procedures_defnoreturn' ,
46+ 'id' : '0!;|f{%4H@mgQ`SIEDKV' ,
47+ 'x' : 38 ,
48+ 'y' : 163 ,
49+ 'icons' : {
50+ 'comment' : {
51+ 'text' : 'Describe this function...' ,
52+ 'pinned' : false ,
53+ 'height' : 80 ,
54+ 'width' : 160 ,
55+ } ,
56+ } ,
57+ 'fields' : {
58+ 'NAME' : 'say hello' ,
59+ } ,
60+ 'inputs' : {
61+ 'STACK' : {
62+ 'block' : {
63+ 'type' : 'text_print' ,
64+ 'id' : 't^`WoL~R$t}rk]`JVFUP' ,
65+ 'inputs' : {
66+ 'TEXT' : {
67+ 'shadow' : {
68+ 'type' : 'text' ,
69+ 'id' : '_PxHV1tqEy60kP^].Qhh' ,
70+ 'fields' : {
71+ 'TEXT' : 'abc' ,
72+ } ,
73+ } ,
74+ 'block' : {
75+ 'type' : 'text_join' ,
76+ 'id' : 'K4.OZ9ql9j0f367238R@' ,
77+ 'extraState' : {
78+ 'itemCount' : 2 ,
79+ } ,
80+ 'inputs' : {
81+ 'ADD0' : {
82+ 'block' : {
83+ 'type' : 'text' ,
84+ 'id' : '5ElufS^j4;l:9N#|Yt$X' ,
85+ 'fields' : {
86+ 'TEXT' : 'The meaning of life is' ,
87+ } ,
88+ } ,
89+ } ,
90+ 'ADD1' : {
91+ 'block' : {
92+ 'type' : 'math_arithmetic' ,
93+ 'id' : ',QfcN`h]rQ86a]6J|di1' ,
94+ 'fields' : {
95+ 'OP' : 'MINUS' ,
96+ } ,
97+ 'inputs' : {
98+ 'A' : {
99+ 'shadow' : {
100+ 'type' : 'math_number' ,
101+ 'id' : 'ClcKUIPYleVQ_j7ZjK]^' ,
102+ 'fields' : {
103+ 'NUM' : 44 ,
104+ } ,
105+ } ,
106+ } ,
107+ 'B' : {
108+ 'shadow' : {
109+ 'type' : 'math_number' ,
110+ 'id' : 'F_cU|uaP7oB-k(j~@X?g' ,
111+ 'fields' : {
112+ 'NUM' : 2 ,
113+ } ,
114+ } ,
115+ } ,
116+ } ,
117+ } ,
118+ } ,
119+ } ,
120+ } ,
121+ } ,
122+ } ,
123+ } ,
124+ } ,
125+ } ,
126+ } ,
127+ {
128+ 'type' : 'procedures_callnoreturn' ,
129+ 'id' : 'Ad^$sruQ.`6zNmQ6jPit' ,
130+ 'x' : 38 ,
131+ 'y' : 113 ,
132+ 'extraState' : {
133+ 'name' : 'say hello' ,
134+ } ,
135+ } ,
136+ ] ,
137+ } ,
138+ } ;
139+
40140suite ( 'Test Node.js' , function ( ) {
41141 test ( 'Import XML' , function ( ) {
42142 const xml = Blockly . utils . xml . textToDom ( xmlText ) ;
@@ -69,4 +169,16 @@ suite('Test Node.js', function () {
69169 // Check output
70170 assert . equal ( "window.alert('Hello from Blockly!');" , code . trim ( ) , 'equal' ) ;
71171 } ) ;
172+ test ( 'Import JSON' , function ( ) {
173+ const workspace = new Blockly . Workspace ( ) ;
174+ Blockly . serialization . workspaces . load ( json , workspace ) ;
175+ } ) ;
176+ test ( 'Roundtrip JSON' , function ( ) {
177+ const workspace = new Blockly . Workspace ( ) ;
178+ Blockly . serialization . workspaces . load ( json , workspace ) ;
179+
180+ const jsonAfter = Blockly . serialization . workspaces . save ( workspace ) ;
181+
182+ assert . deepEqual ( jsonAfter , json ) ;
183+ } ) ;
72184} ) ;
0 commit comments