@@ -226,6 +226,23 @@ R(["pyret-base/js/pyret-tokenizer", "pyret-base/js/pyret-parser", "fs"], functio
226226 expect ( parse ( "```asd``\\````" ) ) . not . toBe ( false ) ;
227227 expect ( parse ( "```asd```asd```" ) ) . toBe ( false ) ;
228228 } ) ;
229+
230+ it ( 'should lex octal escape sequences' , function ( ) {
231+ const escapeSequences = [ '\\0' , '\\77' , '\\101' ] ;
232+ const expectedSequences = [ '0' , '77' , '101' ] ;
233+ for ( let i = 0 ; i < escapeSequences . length ; ++ i ) {
234+ const expectedValues = [ '\\' , expectedSequences [ i ] , undefined ] ;
235+
236+ const lexedValues = lex ( escapeSequences [ i ] ) . map ( token => token . value ) ;
237+ expect ( lexedValues ) . toEqual ( expectedValues ) ;
238+
239+ const parseStr = `str = "${ escapeSequences [ i ] } "` ;
240+ expect ( parse ( parseStr ) ) . not . toBe ( false ) ;
241+ }
242+
243+ // invalid escape sequence
244+ expect ( parse ( 'str = \'\\8\'' ) ) . toBe ( false ) ;
245+ } ) ;
229246 } ) ;
230247 describe ( "parsing" , function ( ) {
231248 it ( "should parse lets and letrecs" , function ( ) {
@@ -762,19 +779,6 @@ R(["pyret-base/js/pyret-tokenizer", "pyret-base/js/pyret-parser", "fs"], functio
762779 expect ( parse ( "spy \"five\": x end" ) ) . not . toBe ( false ) ;
763780 expect ( parse ( "spy \"five\": x: 5 end" ) ) . not . toBe ( false ) ;
764781 } ) ;
765-
766- it ( "should parse octal escape squences" , function ( ) {
767- expect ( parse ( "a = '\\0'" ) . toString ( ) ) . toContain ( stringAst ( '\\u0000' ) ) ;
768- expect ( parse ( "a = '\\101'" ) . toString ( ) ) . toContain ( stringAst ( 'A' ) ) ;
769- expect ( parse ( "a = '\\101bc'" ) . toString ( ) ) . toContain ( stringAst ( 'Abc' ) ) ;
770- expect ( parse ( "a = '\\77'" ) . toString ( ) ) . toContain ( stringAst ( '?' ) ) ;
771-
772- expect ( parse ( "a = '\\88'" ) ) . toBe ( false ) ;
773-
774- function stringAst ( str ) {
775- return `'STRING "'${ str } '"` ;
776- }
777- } ) ;
778782 } ) ;
779783
780784 jazz . execute ( ) ;
0 commit comments