diff --git a/tests/parse/parse.js b/tests/parse/parse.js index ebadc4813d..eb45e25371 100644 --- a/tests/parse/parse.js +++ b/tests/parse/parse.js @@ -226,6 +226,23 @@ R(["pyret-base/js/pyret-tokenizer", "pyret-base/js/pyret-parser", "fs"], functio expect(parse("```asd``\\````")).not.toBe(false); expect(parse("```asd```asd```")).toBe(false); }); + + it('should lex octal escape sequences', function() { + const escapeSequences = ['\\0', '\\77', '\\101']; + const expectedSequences = ['0', '77', '101']; + for (let i = 0; i < escapeSequences.length; ++i) { + const expectedValues = ['\\', expectedSequences[i], undefined]; + + const lexedValues = lex(escapeSequences[i]).map(token => token.value); + expect(lexedValues).toEqual(expectedValues); + + const parseStr = `str = "${escapeSequences[i]}"`; + expect(parse(parseStr)).not.toBe(false); + } + + // invalid escape sequence + expect(parse('str = \'\\8\'')).toBe(false); + }); }); describe("parsing", function() { it("should parse lets and letrecs", function() { @@ -762,19 +779,6 @@ R(["pyret-base/js/pyret-tokenizer", "pyret-base/js/pyret-parser", "fs"], functio expect(parse("spy \"five\": x end")).not.toBe(false); expect(parse("spy \"five\": x: 5 end")).not.toBe(false); }); - - it("should parse octal escape squences", function() { - expect(parse("a = '\\0'").toString()).toContain(stringAst('\\u0000')); - expect(parse("a = '\\101'").toString()).toContain(stringAst('A')); - expect(parse("a = '\\101bc'").toString()).toContain(stringAst('Abc')); - expect(parse("a = '\\77'").toString()).toContain(stringAst('?')); - - expect(parse("a = '\\88'")).toBe(false); - - function stringAst(str) { - return `'STRING "'${str}'"`; - } - }); }); jazz.execute(); diff --git a/tests/pyret/tests/test-strings.arr b/tests/pyret/tests/test-strings.arr index fb193fa7ee..2fdced6acb 100644 --- a/tests/pyret/tests/test-strings.arr +++ b/tests/pyret/tests/test-strings.arr @@ -137,6 +137,11 @@ check: string-to-code-points("abcd") is [list: 97, 98, 99, 100] string-to-code-points("") is [list:] + # octal escape sequences + string-to-code-point("\0") is 0 + string-to-code-point("\77") is 63 + string-to-code-point("\101") is 65 + string-from-code-points([list: 955, 97, 10]) is "λa\n" string-from-code-points([list: 955, -1]) raises "Natural Number" string-from-code-points([list:]) is ""