@@ -341,3 +341,83 @@ describe('Template syntax', () => {
341341 } ) ;
342342} ) ;
343343
344+ describe ( 'Escape sequence' , ( ) => {
345+ describe ( 'valid' , ( ) => {
346+ const cases : [ string , string ] [ ] = [
347+ [ '\\t' , '\t' ] , // horizontal tab
348+ [ '\\n' , '\n' ] , // line feed
349+ [ '\\r' , '\r' ] , // carriage return
350+ [ '\\"' , '"' ] ,
351+ [ '\\\'' , '\'' ] ,
352+ [ '\\\\' , '\\' ] ,
353+ [ '\\`' , '`' ] ,
354+ [ '\\{' , '{' ] ,
355+ [ '\\}' , '}' ] ,
356+ [ '\\u0041' , 'A' ] ,
357+ [ '\\u85cd' , '藍' ] ,
358+ [ '\\u85CD' , '藍' ] ,
359+ [ '\\ud842\\udfb7' , '𠮷' ] ,
360+ [ '\\uD842\\uDFB7' , '𠮷' ] ,
361+ ] ;
362+
363+ describe ( 'double quote' , ( ) => {
364+ test . each ( cases ) ( 'value of escape sequence "%s" must be "%s"' , async ( char , expected ) => {
365+ const res = await exe ( `
366+ <: "${ char } "
367+ ` ) ;
368+ eq ( res , STR ( expected ) ) ;
369+ } ) ;
370+ } ) ;
371+
372+ describe ( 'single quote' , ( ) => {
373+ test . each ( cases ) ( 'value of escape sequence "%s" must be "%s"' , async ( char , expected ) => {
374+ const res = await exe ( `
375+ <: '${ char } '
376+ ` ) ;
377+ eq ( res , STR ( expected ) ) ;
378+ } ) ;
379+ } ) ;
380+
381+ describe ( 'template' , ( ) => {
382+ test . each ( cases ) ( 'value of escape sequence "%s" must be "%s"' , async ( string , expected ) => {
383+ const res = await exe ( `
384+ <: \`${ string } \`
385+ ` ) ;
386+ eq ( res , STR ( expected ) ) ;
387+ } ) ;
388+ } ) ;
389+ } ) ;
390+
391+ describe ( 'invalid' , ( ) => {
392+ const cases : [ string ] [ ] = [
393+ [ '\\x' ] ,
394+ [ '\\b' ] ,
395+ [ '\\v' ] ,
396+ [ '\\f' ] ,
397+ ] ;
398+
399+ describe ( 'double quote' , ( ) => {
400+ test . each ( cases ) ( 'value of escape sequence "%s" must not be allowed' , async ( char ) => {
401+ await expect ( async ( ) => await exe ( `
402+ <: "${ char } "
403+ ` ) ) . rejects . toThrow ( AiScriptSyntaxError ) ;
404+ } ) ;
405+ } ) ;
406+
407+ describe ( 'single quote' , ( ) => {
408+ test . each ( cases ) ( 'value of escape sequence "%s" must not be allowed' , async ( char ) => {
409+ await expect ( async ( ) => await exe ( `
410+ <: '${ char } '
411+ ` ) ) . rejects . toThrow ( AiScriptSyntaxError ) ;
412+ } ) ;
413+ } ) ;
414+
415+ describe ( 'template' , ( ) => {
416+ test . each ( cases ) ( 'value of escape sequence "%s" must not be allowed' , async ( string ) => {
417+ await expect ( async ( ) => await exe ( `
418+ <: \`${ string } \`
419+ ` ) ) . rejects . toThrow ( AiScriptSyntaxError ) ;
420+ } ) ;
421+ } ) ;
422+ } ) ;
423+ } ) ;
0 commit comments