summaryrefslogtreecommitdiff
path: root/test/built-ins/String/S9.8_A5_T1.js
blob: c7e55c818bb7f9d1bd445672d8e32b19e478253d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2009 the Sputnik authors.  All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
info: >
    Result of String conversion from Object value is conversion
    from primitive value
es5id: 9.8_A5_T1
description: Some objects convert to String by explicit transformation
---*/

// CHECK#1
if (String(new Number()) !== "0") {
  $ERROR('#1: String(new Number()) === "0". Actual: ' + (String(new Number())));
}

// CHECK#2
if (String(new Number(0)) !== "0") {
  $ERROR('#2: String(new Number(0)) === "0". Actual: ' + (String(new Number(0))));
}

// CHECK#3
if (String(new Number(Number.NaN)) !== "NaN") {
  $ERROR('#3: String(new Number(Number.NaN)) === Not-a-Number. Actual: ' + (String(new Number(Number.NaN))));
}

// CHECK#4
if (String(new Number(null)) !== "0") {
  $ERROR('#4: String(new Number(null)) === "0". Actual: ' + (String(new Number(null)))); 
}

// CHECK#5
if (String(new Number(void 0)) !== "NaN") {
  $ERROR('#5: String(new Number(void 0)) === Not-a-Number. Actual: ' + (String(new Number(void 0))));
}

// CHECK#6
if (String(new Number(true)) !== "1") {
  $ERROR('#6: String(new Number(true)) === "1". Actual: ' + (String(new Number(true))));
}

// CHECK#7
if (String(new Number(false)) !== "0") {
  $ERROR('#7: String(new Number(false)) === "0". Actual: ' + (String(new Number(false))));
}

// CHECK#8
if (String(new Boolean(true)) !== "true") {
  $ERROR('#8: String(new Boolean(true)) === "true". Actual: ' + (String(new Boolean(true))));
}

// CHECK#9
if (String(new Boolean(false)) !== "false") {
  $ERROR('#9: Number(new Boolean(false)) === "false". Actual: ' + (Number(new Boolean(false))));
}

// CHECK#10
if (String(new Array(2,4,8,16,32)) !== "2,4,8,16,32") {
  $ERROR('#10: String(new Array(2,4,8,16,32)) === "2,4,8,16,32". Actual: ' + (String(new Array(2,4,8,16,32))));
}

// CHECK#11
var myobj1 = {
                toNumber : function(){return 12345;}, 
                toString : function(){return 67890;},
                valueOf  : function(){return "[object MyObj]";} 
            };

if (String(myobj1) !== "67890"){
  $ERROR("#11: String(myobj) calls ToPrimitive with hint String");
}

// CHECK#12
var myobj2 = {
                toNumber : function(){return 12345;},
                toString : function(){return {}}, 
                valueOf  : function(){return "[object MyObj]";} 
            };

if (String(myobj2) !== "[object MyObj]"){
  $ERROR("#12: String(myobj) calls ToPrimitive with hint String");
}

// CHECK#13
var myobj3 = {
                toNumber : function(){return 12345;},
                valueOf  : function(){return "[object MyObj]";} 
            };

if (String(myobj3) !== "[object Object]"){
  $ERROR("#13: String(myobj) calls ToPrimitive with hint String");
}