• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2013 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6//     * Redistributions of source code must retain the above copyright
7//       notice, this list of conditions and the following disclaimer.
8//     * Redistributions in binary form must reproduce the above
9//       copyright notice, this list of conditions and the following
10//       disclaimer in the documentation and/or other materials provided
11//       with the distribution.
12//     * Neither the name of Google Inc. nor the names of its
13//       contributors may be used to endorse or promote products derived
14//       from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28assertEquals(String.fromCharCode(97, 220, 256), 'a' + '\u00DC' + '\u0100');
29assertEquals(String.fromCharCode(97, 220, 256), 'a\u00DC\u0100');
30
31assertEquals(0x80, JSON.stringify("\x80").charCodeAt(1));
32assertEquals(0x80, JSON.stringify("\x80", 0, null).charCodeAt(1));
33
34assertEquals(['a', 'b', '\xdc'], ['b', '\xdc', 'a'].sort());
35
36assertEquals(['\xfc\xdc', '\xfc'], new RegExp('(\xdc)\\1', 'i').exec('\xfc\xdc'));
37// Same test but for all values in Latin-1 range.
38var total_lo = 0;
39for (var i = 0; i < 0xff; i++) {
40  var base = String.fromCharCode(i);
41  var escaped = base;
42  if (base == '(' || base == ')' || base == '*' || base == '+' ||
43      base == '?' || base == '[' || base == ']' || base == '\\' ||
44      base == '$' || base == '^' || base == '|') {
45    escaped = '\\' + base;
46  }
47  var lo = String.fromCharCode(i + 0x20);
48  base_result = new RegExp('(' + escaped + ')\\1', 'i').exec(base + base);
49  assertEquals( base_result, [base + base, base]);
50  lo_result = new RegExp('(' + escaped + ')\\1', 'i').exec(base + lo);
51  if (base.toLowerCase() == lo) {
52    assertEquals([base + lo, base], lo_result);
53    total_lo++;
54  } else {
55    assertEquals(null, lo_result);
56  }
57}
58// Should have hit the branch for the following char codes:
59// [A-Z], [192-222] but not 215
60assertEquals((90-65+1)+(222-192-1+1), total_lo);
61
62// Latin-1 whitespace character
63assertEquals( 1, +(String.fromCharCode(0xA0) + '1') );
64
65// Latin-1 \W characters
66assertEquals(["+\u00a3", "=="], "+\u00a3==".match(/\W\W/g));
67
68// Latin-1 character that uppercases out of Latin-1.
69assertTrue(/\u0178/i.test('\u00ff'));
70
71// Unicode equivalence
72assertTrue(/\u039c/i.test('\u00b5'));
73assertTrue(/\u039c/i.test('\u03bc'));
74assertTrue(/\u00b5/i.test('\u03bc'));
75// Unicode equivalence ranges
76assertTrue(/[\u039b-\u039d]/i.test('\u00b5'));
77assertFalse(/[^\u039b-\u039d]/i.test('\u00b5'));
78assertFalse(/[\u039b-\u039d]/.test('\u00b5'));
79assertTrue(/[^\u039b-\u039d]/.test('\u00b5'));
80
81// Check a regression in QuoteJsonSlow and WriteQuoteJsonString
82for (var testNumber = 0; testNumber < 2; testNumber++) {
83  var testString = "\xdc";
84  var loopLength = testNumber == 0 ? 0 : 20;
85  for (var i = 0; i < loopLength; i++ ) {
86    testString += testString;
87  }
88  var stringified = JSON.stringify({"test" : testString}, null, 0);
89  var stringifiedExpected = '{"test":"' + testString + '"}';
90  assertEquals(stringifiedExpected, stringified);
91}
92