js/src/tests/js1_8_1/String/regress-305064.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_8_1/String/regress-305064.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,144 @@
     1.4 +// |reftest| fails
     1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +//-----------------------------------------------------------------------------
    1.11 +var BUGNUMBER = 305064;
    1.12 +var summary = 'Tests the trim, trimRight  and trimLeft methods';
    1.13 +var actual = '';
    1.14 +var expect = '';
    1.15 +
    1.16 +printBugNumber(BUGNUMBER);
    1.17 +printStatus (summary);
    1.18 +
    1.19 +var trimMethods = ['trim', 'trimLeft', 'trimRight'];
    1.20 +
    1.21 +/** List from ES 3.1 Recommendation for String.trim (bug 305064) **/
    1.22 +var whitespace = [
    1.23 +  {s : '\u0009', t : 'HORIZONTAL TAB'},
    1.24 +  {s : '\u000B', t : 'VERTICAL TAB'},
    1.25 +  {s : '\u000C', t : 'FORMFEED'},
    1.26 +  {s : '\u0020', t : 'SPACE'},
    1.27 +  {s : '\u00A0', t : 'NO-BREAK SPACE'},
    1.28 +  {s : '\u1680', t : 'OGHAM SPACE MARK'},
    1.29 +  {s : '\u180E', t : 'MONGOLIAN VOWEL SEPARATOR'},
    1.30 +  {s : '\u2000', t : 'EN QUAD'},
    1.31 +  {s : '\u2001', t : 'EM QUAD'},
    1.32 +  {s : '\u2002', t : 'EN SPACE'},
    1.33 +  {s : '\u2003', t : 'EM SPACE'},
    1.34 +  {s : '\u2004', t : 'THREE-PER-EM SPACE'},
    1.35 +  {s : '\u2005', t : 'FOUR-PER-EM SPACE'},
    1.36 +  {s : '\u2006', t : 'SIX-PER-EM SPACE'},
    1.37 +  {s : '\u2007', t : 'FIGURE SPACE'},
    1.38 +  {s : '\u2008', t : 'PUNCTUATION SPACE'},
    1.39 +  {s : '\u2009', t : 'THIN SPACE'},
    1.40 +  {s : '\u200A', t : 'HAIR SPACE'},
    1.41 +  {s : '\u202F', t : 'NARROW NO-BREAK SPACE'},
    1.42 +  {s : '\u205F', t : 'MEDIUM MATHEMATICAL SPACE'},
    1.43 +  {s : '\u3000', t : 'IDEOGRAPHIC SPACE'},
    1.44 +  {s : '\u000A', t : 'LINE FEED OR NEW LINE'},
    1.45 +  {s : '\u000D', t : 'CARRIAGE RETURN'},
    1.46 +  {s : '\u2028', t : 'LINE SEPARATOR'},
    1.47 +  {s : '\u2029', t : 'PARAGRAPH SEPARATOR'},
    1.48 +  {s : '\u200B', t : 'ZERO WIDTH SPACE (category Cf)'}
    1.49 +  ];
    1.50 +
    1.51 +for (var j = 0; j < trimMethods.length; ++j)
    1.52 +{
    1.53 +  var str;
    1.54 +
    1.55 +  var method = trimMethods[j];
    1.56 +
    1.57 +  if (typeof String.prototype[method] == 'undefined')
    1.58 +  {
    1.59 +    reportCompare(true, true, 'Test skipped. String.prototype.' + method + ' is not supported');
    1.60 +    continue;
    1.61 +  }
    1.62 +
    1.63 +  print('Test empty string.');
    1.64 +  str      = '';
    1.65 +  expected = '';
    1.66 +  actual   = str[method]();
    1.67 +  reportCompare(expected, actual, '"' + toPrinted(str) + '".' + method + '()');                        
    1.68 +
    1.69 +  print('Test string with no whitespace.');
    1.70 +  str      = 'a';
    1.71 +  expected = 'a';
    1.72 +  actual   = str[method]();
    1.73 +  reportCompare(expected, actual, '"' + toPrinted(str) + '".' + method + '()');                        
    1.74 +
    1.75 +  for (var i = 0; i < whitespace.length; ++i)
    1.76 +  {
    1.77 +    var v = whitespace[i].s;
    1.78 +    var t = whitespace[i].t;
    1.79 +    v = v + v + v;
    1.80 +
    1.81 +    print('=======================================');
    1.82 +    print('Test ' + method + ' with with only whitespace. : ' + t);
    1.83 +    str      = v;
    1.84 +    expected = '';
    1.85 +    actual   = str[method]();
    1.86 +    reportCompare(expected, actual, t + ':' + '"' + toPrinted(str) + '".' + method + '()');
    1.87 +
    1.88 +    print('Test ' + method + ' with with no leading or trailing whitespace. : ' + t);
    1.89 +    str      = 'a' + v + 'b';
    1.90 +    expected = str;
    1.91 +    actual   = str[method]();
    1.92 +    reportCompare(expected, actual, t + ':' + '"' + toPrinted(str) + '".' + method + '()');
    1.93 +
    1.94 +    print('Test ' + method + ' with with leading whitespace. : ' + t);
    1.95 +    str = v + 'a';
    1.96 +    switch(method)
    1.97 +    {
    1.98 +    case 'trim':
    1.99 +      expected = 'a';
   1.100 +      break;
   1.101 +    case 'trimLeft':
   1.102 +      expected = 'a';
   1.103 +      break;
   1.104 +    case 'trimRight':
   1.105 +      expected = str;
   1.106 +      break;
   1.107 +    }
   1.108 +    actual   = str[method]();
   1.109 +    reportCompare(expected, actual, t + ':' + '"' + toPrinted(str) + '".' + method + '()');
   1.110 +      
   1.111 +    print('Test ' + method + ' with with trailing whitespace. : ' + t);
   1.112 +    str = 'a' + v;
   1.113 +    switch(method)
   1.114 +    {
   1.115 +    case 'trim':
   1.116 +      expected = 'a';
   1.117 +      break;
   1.118 +    case 'trimLeft':
   1.119 +      expected = str;
   1.120 +      break;
   1.121 +    case 'trimRight':
   1.122 +      expected = 'a';
   1.123 +      break;
   1.124 +    }
   1.125 +    actual = str[method]();
   1.126 +    reportCompare(expected, actual, t + ':' + '"' + toPrinted(str) + '".' + method + '()');
   1.127 +
   1.128 +    print('Test ' + method + ' with with leading and trailing whitepace.');
   1.129 +    str = v + 'a' + v;
   1.130 +    switch(method)
   1.131 +    {
   1.132 +    case 'trim':
   1.133 +      expected = 'a';
   1.134 +      break;
   1.135 +    case 'trimLeft':
   1.136 +      expected = 'a' + v;
   1.137 +      break;
   1.138 +    case 'trimRight':
   1.139 +      expected = v + 'a';
   1.140 +      break;
   1.141 +    }
   1.142 +    actual = str[method]();
   1.143 +    reportCompare(expected, actual, t + ':' + '"' + toPrinted(str) + '".' + method + '()');
   1.144 +      
   1.145 +  }
   1.146 +}
   1.147 +

mercurial