@@ -24,7 +24,8 @@ test("label", async () => {
2424 { key : "next" , value : true }
2525 ] ,
2626 sentenceAssets : [ ] ,
27- subScene : [ ]
27+ subScene : [ ] ,
28+ inlineComment : ""
2829 } ;
2930 expect ( result . sentenceList ) . toContainEqual ( expectSentenceItem ) ;
3031} ) ;
@@ -49,7 +50,8 @@ test("args", async () => {
4950 { key : "next" , value : true }
5051 ] ,
5152 sentenceAssets : [ { name : "m2.png" , url : 'm2.png' , type : fileType . figure , lineNumber : 0 } ] ,
52- subScene : [ ]
53+ subScene : [ ] ,
54+ inlineComment : ""
5355 } ;
5456 expect ( result . sentenceList ) . toContainEqual ( expectSentenceItem ) ;
5557} ) ;
@@ -71,7 +73,8 @@ test("choose", async () => {
7173 content : "" ,
7274 args : [ ] ,
7375 sentenceAssets : [ ] ,
74- subScene : [ ]
76+ subScene : [ ] ,
77+ inlineComment : ""
7578 } ;
7679 expect ( result . sentenceList ) . toContainEqual ( expectSentenceItem ) ;
7780} ) ;
@@ -98,7 +101,8 @@ test("long-script", async () => {
98101 { key : "next" , value : true }
99102 ] ,
100103 sentenceAssets : [ ] ,
101- subScene : [ ]
104+ subScene : [ ] ,
105+ inlineComment : ""
102106 } ;
103107 expect ( result . sentenceList ) . toContainEqual ( expectSentenceItem ) ;
104108} ) ;
@@ -120,7 +124,8 @@ test("var", async () => {
120124 content : "a=1?" ,
121125 args : [ { key : 'speaker' , value : 'WebGAL' } , { key : 'when' , value : "a==1" } ] ,
122126 sentenceAssets : [ ] ,
123- subScene : [ ]
127+ subScene : [ ] ,
128+ inlineComment : ""
124129 } ;
125130 expect ( result . sentenceList ) . toContainEqual ( expectSentenceItem ) ;
126131} ) ;
@@ -185,14 +190,16 @@ test("say statement", async () => {
185190 } , ADD_NEXT_ARG_LIST , SCRIPT_CONFIG ) ;
186191
187192 const result = parser . parse ( `say:123 -speaker=xx;` , 'test' , 'test' ) ;
188- expect ( result . sentenceList ) . toContainEqual ( {
193+ const expectSentenceItem : ISentence = {
189194 command : commandType . say ,
190195 commandRaw : "say" ,
191196 content : "123" ,
192197 args : [ { key : 'speaker' , value : 'xx' } ] ,
193198 sentenceAssets : [ ] ,
194- subScene : [ ]
195- } ) ;
199+ subScene : [ ] ,
200+ inlineComment : ""
201+ } ;
202+ expect ( result . sentenceList ) . toContainEqual ( expectSentenceItem ) ;
196203} ) ;
197204
198205test ( "wait command" , async ( ) => {
@@ -202,14 +209,16 @@ test("wait command", async () => {
202209 } , ADD_NEXT_ARG_LIST , SCRIPT_CONFIG ) ;
203210
204211 const result = parser . parse ( `wait:1000;` , 'test' , 'test' ) ;
205- expect ( result . sentenceList ) . toContainEqual ( {
212+ const expectSentenceItem : ISentence = {
206213 command : commandType . wait ,
207214 commandRaw : "wait" ,
208215 content : "1000" ,
209216 args : [ ] ,
210217 sentenceAssets : [ ] ,
211- subScene : [ ]
212- } ) ;
218+ subScene : [ ] ,
219+ inlineComment : ""
220+ } ;
221+ expect ( result . sentenceList ) . toContainEqual ( expectSentenceItem ) ;
213222} ) ;
214223
215224test ( "changeFigure with duration and animation args" , async ( ) => {
@@ -219,7 +228,7 @@ test("changeFigure with duration and animation args", async () => {
219228 } , ADD_NEXT_ARG_LIST , SCRIPT_CONFIG ) ;
220229
221230 const result = parser . parse ( `changeFigure:stand.webp -duration=1000 -enter=fadeIn -exit=fadeOut;` , 'test' , 'test' ) ;
222- expect ( result . sentenceList ) . toContainEqual ( {
231+ const expectSentenceItem : ISentence = {
223232 command : commandType . changeFigure ,
224233 commandRaw : "changeFigure" ,
225234 content : "stand.webp" ,
@@ -229,8 +238,10 @@ test("changeFigure with duration and animation args", async () => {
229238 { key : 'exit' , value : 'fadeOut' }
230239 ] ,
231240 sentenceAssets : [ { name : "stand.webp" , url : 'stand.webp' , type : fileType . figure , lineNumber : 0 } ] ,
232- subScene : [ ]
233- } ) ;
241+ subScene : [ ] ,
242+ inlineComment : ""
243+ } ;
244+ expect ( result . sentenceList ) . toContainEqual ( expectSentenceItem ) ;
234245} ) ;
235246
236247test ( "changeBg with animation parameters" , async ( ) => {
@@ -240,7 +251,7 @@ test("changeBg with animation parameters", async () => {
240251 } , ADD_NEXT_ARG_LIST , SCRIPT_CONFIG ) ;
241252
242253 const result = parser . parse ( `changeBg:background.jpg -duration=2000 -enter=slideIn -transform={"alpha":0.8};` , 'test' , 'test' ) ;
243- expect ( result . sentenceList ) . toContainEqual ( {
254+ const expectSentenceItem : ISentence = {
244255 command : commandType . changeBg ,
245256 commandRaw : "changeBg" ,
246257 content : "background.jpg" ,
@@ -250,6 +261,65 @@ test("changeBg with animation parameters", async () => {
250261 { key : 'transform' , value : '{"alpha":0.8}' }
251262 ] ,
252263 sentenceAssets : [ { name : "background.jpg" , url : 'background.jpg' , type : fileType . background , lineNumber : 0 } ] ,
253- subScene : [ ]
254- } ) ;
264+ subScene : [ ] ,
265+ inlineComment : ""
266+ } ;
267+ expect ( result . sentenceList ) . toContainEqual ( expectSentenceItem ) ;
268+ } ) ;
269+
270+ test ( "inline comment is preserved on normal statement" , async ( ) => {
271+ const parser = new SceneParser ( ( assetList ) => {
272+ } , ( fileName , assetType ) => {
273+ return fileName ;
274+ } , ADD_NEXT_ARG_LIST , SCRIPT_CONFIG ) ;
275+
276+ const result = parser . parse ( `say:123 -speaker=xx; // this is an inline comment` , 'test' , 'test' ) ;
277+ const expectSentenceItem : ISentence = {
278+ command : commandType . say ,
279+ commandRaw : "say" ,
280+ content : "123" ,
281+ args : [ { key : 'speaker' , value : 'xx' } ] ,
282+ sentenceAssets : [ ] ,
283+ subScene : [ ] ,
284+ inlineComment : "// this is an inline comment"
285+ } ;
286+ expect ( result . sentenceList ) . toContainEqual ( expectSentenceItem ) ;
287+ } ) ;
288+
289+ test ( "escaped semicolon is preserved in content and inline comment is preserved" , async ( ) => {
290+ const parser = new SceneParser ( ( assetList ) => {
291+ } , ( fileName , assetType ) => {
292+ return fileName ;
293+ } , ADD_NEXT_ARG_LIST , SCRIPT_CONFIG ) ;
294+
295+ const result = parser . parse ( String . raw `say:price\;100;comment-part` , 'test' , 'test' ) ;
296+ const expectSentenceItem : ISentence = {
297+ command : commandType . say ,
298+ commandRaw : "say" ,
299+ content : "price;100" ,
300+ args : [ ] ,
301+ sentenceAssets : [ ] ,
302+ subScene : [ ] ,
303+ inlineComment : "comment-part"
304+ } ;
305+ expect ( result . sentenceList ) . toContainEqual ( expectSentenceItem ) ;
306+ } ) ;
307+
308+ test ( "comment-only line keeps comment in content" , async ( ) => {
309+ const parser = new SceneParser ( ( assetList ) => {
310+ } , ( fileName , assetType ) => {
311+ return fileName ;
312+ } , ADD_NEXT_ARG_LIST , SCRIPT_CONFIG ) ;
313+
314+ const result = parser . parse ( `; only comment here` , 'test' , 'test' ) ;
315+ const expectSentenceItem : ISentence = {
316+ command : commandType . comment ,
317+ commandRaw : "comment" ,
318+ content : "only comment here" ,
319+ args : [ { key : 'next' , value : true } ] ,
320+ sentenceAssets : [ ] ,
321+ subScene : [ ] ,
322+ inlineComment : ""
323+ } ;
324+ expect ( result . sentenceList ) . toContainEqual ( expectSentenceItem ) ;
255325} ) ;
0 commit comments