| 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 | |
| 6 | /* |
| 7 | * |
| 8 | * Date: 30 Oct 2002 |
| 9 | * SUMMARY: '\400' should lex as a 2-digit octal escape + '0' |
| 10 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=177314 |
| 11 | * |
| 12 | * Bug was that Rhino interpreted '\400' as a 3-digit octal escape. As such |
| 13 | * it is invalid, since octal escapes may only run from '\0' to '\377'. But |
| 14 | * the lexer should interpret this as '\40' + '0' instead, and throw no error. |
| 15 | * |
| 16 | */ |
| 17 | //----------------------------------------------------------------------------- |
| 18 | var gTestfile = 'regress-177314.js'; |
| 19 | var UBound = 0; |
| 20 | var BUGNUMBER = 177314; |
| 21 | var summary = "'\\" + "400' should lex as a 2-digit octal escape + '0'"; |
| 22 | var status = ''; |
| 23 | var statusitems = []; |
| 24 | var actual = ''; |
| 25 | var actualvalues = []; |
| 26 | var expect= ''; |
| 27 | var expectedvalues = []; |
| 28 | |
| 29 | |
| 30 | // the last valid octal escape is '\377', which should equal hex escape '\xFF' |
| 31 | status = inSection(1); |
| 32 | actual = '\377'; |
| 33 | expect = '\xFF'; |
| 34 | addThis(); |
| 35 | |
| 36 | // now exercise the lexer by going one higher in the last digit |
| 37 | status = inSection(2); |
| 38 | actual = '\378'; |
| 39 | expect = '\37' + '8'; |
| 40 | addThis(); |
| 41 | |
| 42 | // trickier: 400 is a valid octal number, but '\400' isn't a valid octal escape |
| 43 | status = inSection(3); |
| 44 | actual = '\400'; |
| 45 | expect = '\40' + '0'; |
| 46 | addThis(); |
| 47 | |
| 48 | |
| 49 | |
| 50 | //----------------------------------------------------------------------------- |
| 51 | test(); |
| 52 | //----------------------------------------------------------------------------- |
| 53 | |
| 54 | |
| 55 | |
| 56 | function addThis() |
| 57 | { |
| 58 | statusitems[UBound] = status; |
| 59 | actualvalues[UBound] = actual; |
| 60 | expectedvalues[UBound] = expect; |
| 61 | UBound++; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | function test() |
| 66 | { |
| 67 | enterFunc('test'); |
| 68 | printBugNumber(BUGNUMBER); |
| 69 | printStatus(summary); |
| 70 | |
| 71 | for (var i=0; i<UBound; i++) |
| 72 | { |
| 73 | reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
| 74 | } |
| 75 | |
| 76 | exitFunc ('test'); |
| 77 | } |