js/src/tests/ecma/String/15.5.1.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/String/15.5.1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +/**
    1.11 +   File Name:          15.5.1.js
    1.12 +   ECMA Section:       15.5.1 The String Constructor called as a Function
    1.13 +   15.5.1.1 String(value)
    1.14 +   15.5.1.2 String()
    1.15 +
    1.16 +   Description:	When String is called as a function rather than as
    1.17 +   a constructor, it performs a type conversion.
    1.18 +   - String(value) returns a string value (not a String
    1.19 +   object) computed by ToString(value)
    1.20 +   - String() returns the empty string ""
    1.21 +
    1.22 +   Author:             christine@netscape.com
    1.23 +   Date:               1 october 1997
    1.24 +*/
    1.25 +
    1.26 +var SECTION = "15.5.1";
    1.27 +var VERSION = "ECMA_1";
    1.28 +startTest();
    1.29 +var TITLE   = "The String Constructor Called as a Function";
    1.30 +
    1.31 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.32 +
    1.33 +new TestCase( SECTION,	"String('string primitive')",	"string primitive",	String('string primitive') );
    1.34 +new TestCase( SECTION,	"String(void 0)",		"undefined",		String( void 0) );
    1.35 +new TestCase( SECTION,	"String(null)",			    "null",			String( null ) );
    1.36 +new TestCase( SECTION,	"String(true)",			    "true",			String( true) );
    1.37 +new TestCase( SECTION,	"String(false)",		    "false",		String( false ) );
    1.38 +new TestCase( SECTION,	"String(Boolean(true))",	"true",			String(Boolean(true)) );
    1.39 +new TestCase( SECTION,	"String(Boolean(false))",	"false",		String(Boolean(false)) );
    1.40 +new TestCase( SECTION,	"String(Boolean())",		"false",		String(Boolean(false)) );
    1.41 +new TestCase( SECTION,	"String(new Array())",		"",			    String( new Array()) );
    1.42 +new TestCase( SECTION,	"String(new Array(1,2,3))",	"1,2,3",		String( new Array(1,2,3)) );
    1.43 +
    1.44 +
    1.45 +new TestCase( SECTION,    "String( Number.NaN )",       "NaN",                  String( Number.NaN ) );
    1.46 +new TestCase( SECTION,    "String( 0 )",                "0",                    String( 0 ) );
    1.47 +new TestCase( SECTION,    "String( -0 )",               "0",                   String( -0 ) );
    1.48 +new TestCase( SECTION,    "String( Number.POSITIVE_INFINITY )", "Infinity",     String( Number.POSITIVE_INFINITY ) );
    1.49 +new TestCase( SECTION,    "String( Number.NEGATIVE_INFINITY )", "-Infinity",    String( Number.NEGATIVE_INFINITY ) );
    1.50 +new TestCase( SECTION,    "String( -1 )",               "-1",                   String( -1 ) );
    1.51 +
    1.52 +// cases in step 6:  integers  1e21 > x >= 1 or -1 >= x > -1e21
    1.53 +
    1.54 +new TestCase( SECTION,    "String( 1 )",                    "1",                    String( 1 ) );
    1.55 +new TestCase( SECTION,    "String( 10 )",                   "10",                   String( 10 ) );
    1.56 +new TestCase( SECTION,    "String( 100 )",                  "100",                  String( 100 ) );
    1.57 +new TestCase( SECTION,    "String( 1000 )",                 "1000",                 String( 1000 ) );
    1.58 +new TestCase( SECTION,    "String( 10000 )",                "10000",                String( 10000 ) );
    1.59 +new TestCase( SECTION,    "String( 10000000000 )",          "10000000000",          String( 10000000000 ) );
    1.60 +new TestCase( SECTION,    "String( 10000000000000000000 )", "10000000000000000000", String( 10000000000000000000 ) );
    1.61 +new TestCase( SECTION,    "String( 100000000000000000000 )","100000000000000000000",String( 100000000000000000000 ) );
    1.62 +
    1.63 +new TestCase( SECTION,    "String( 12345 )",                    "12345",                    String( 12345 ) );
    1.64 +new TestCase( SECTION,    "String( 1234567890 )",               "1234567890",               String( 1234567890 ) );
    1.65 +
    1.66 +new TestCase( SECTION,    "String( -1 )",                       "-1",                       String( -1 ) );
    1.67 +new TestCase( SECTION,    "String( -10 )",                      "-10",                      String( -10 ) );
    1.68 +new TestCase( SECTION,    "String( -100 )",                     "-100",                     String( -100 ) );
    1.69 +new TestCase( SECTION,    "String( -1000 )",                    "-1000",                    String( -1000 ) );
    1.70 +new TestCase( SECTION,    "String( -1000000000 )",              "-1000000000",              String( -1000000000 ) );
    1.71 +new TestCase( SECTION,    "String( -1000000000000000 )",        "-1000000000000000",        String( -1000000000000000 ) );
    1.72 +new TestCase( SECTION,    "String( -100000000000000000000 )",   "-100000000000000000000",   String( -100000000000000000000 ) );
    1.73 +new TestCase( SECTION,    "String( -1000000000000000000000 )",  "-1e+21",                   String( -1000000000000000000000 ) );
    1.74 +
    1.75 +new TestCase( SECTION,    "String( -12345 )",                    "-12345",                  String( -12345 ) );
    1.76 +new TestCase( SECTION,    "String( -1234567890 )",               "-1234567890",             String( -1234567890 ) );
    1.77 +
    1.78 +// cases in step 7: numbers with a fractional component, 1e21> x >1 or  -1 > x > -1e21,
    1.79 +new TestCase( SECTION,    "String( 1.0000001 )",                "1.0000001",                String( 1.0000001 ) );
    1.80 +
    1.81 +
    1.82 +// cases in step 8:  fractions between 1 > x > -1, exclusive of 0 and -0
    1.83 +
    1.84 +// cases in step 9:  numbers with 1 significant digit >= 1e+21 or <= 1e-6
    1.85 +
    1.86 +new TestCase( SECTION,    "String( 1000000000000000000000 )",   "1e+21",             String( 1000000000000000000000 ) );
    1.87 +new TestCase( SECTION,    "String( 10000000000000000000000 )",   "1e+22",            String( 10000000000000000000000 ) );
    1.88 +
    1.89 +//  cases in step 10:  numbers with more than 1 significant digit >= 1e+21 or <= 1e-6
    1.90 +new TestCase( SECTION,    "String( 1.2345 )",                    "1.2345",                  String( 1.2345));
    1.91 +new TestCase( SECTION,    "String( 1.234567890 )",               "1.23456789",             String( 1.234567890 ));
    1.92 +
    1.93 +new TestCase( SECTION,    "String( .12345 )",                   "0.12345",               String(.12345 )     );
    1.94 +new TestCase( SECTION,    "String( .012345 )",                  "0.012345",              String(.012345)     );
    1.95 +new TestCase( SECTION,    "String( .0012345 )",                 "0.0012345",             String(.0012345)    );
    1.96 +new TestCase( SECTION,    "String( .00012345 )",                "0.00012345",            String(.00012345)   );
    1.97 +new TestCase( SECTION,    "String( .000012345 )",               "0.000012345",           String(.000012345)  );
    1.98 +new TestCase( SECTION,    "String( .0000012345 )",              "0.0000012345",          String(.0000012345) );
    1.99 +new TestCase( SECTION,    "String( .00000012345 )",             "1.2345e-7",            String(.00000012345));
   1.100 +
   1.101 +new TestCase( "15.5.2",	"String()",			        "",			    String() );
   1.102 +
   1.103 +test();

mercurial