Debian Codegraph @

rhino/testsrc/tests/ecma/String/15.5.4.6-1.js

raw symbols SCIP
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 gTestfile = '15.5.4.6-1.js';
7
8 /**
9 File Name: 15.5.4.6-1.js
10 ECMA Section: 15.5.4.6 String.prototype.indexOf( searchString, pos)
11 Description: If the given searchString appears as a substring of the
12 result of converting this object to a string, at one or
13 more positions that are at or to the right of the
14 specified position, then the index of the leftmost such
15 position is returned; otherwise -1 is returned. If
16 positionis undefined or not supplied, 0 is assumed, so
17 as to search all of the string.
18
19 When the indexOf method is called with two arguments,
20 searchString and pos, the following steps are taken:
21
22 1. Call ToString, giving it the this value as its
23 argument.
24 2. Call ToString(searchString).
25 3. Call ToInteger(position). (If position is undefined
26 or not supplied, this step produces the value 0).
27 4. Compute the number of characters in Result(1).
28 5. Compute min(max(Result(3), 0), Result(4)).
29 6. Compute the number of characters in the string that
30 is Result(2).
31 7. Compute the smallest possible integer k not smaller
32 than Result(5) such that k+Result(6) is not greater
33 than Result(4), and for all nonnegative integers j
34 less than Result(6), the character at position k+j
35 of Result(1) is the same as the character at position
36 j of Result(2); but if there is no such integer k,
37 then compute the value -1.
38 8. Return Result(7).
39
40 Note that the indexOf function is intentionally generic;
41 it does not require that its this value be a String object.
42 Therefore it can be transferred to other kinds of objects
43 for use as a method.
44
45 Author: [email protected]
46 Date: 2 october 1997
47 */
48 var SECTION = "15.5.4.6-1";
49 var VERSION = "ECMA_1";
50 startTest();
51 var TITLE = "String.protoype.indexOf";
52
53 var TEST_STRING = new String( " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" );
54
55 writeHeaderToLog( SECTION + " "+ TITLE);
56
57 var j = 0;
58
59 for ( k = 0, i = 0x0020; i < 0x007e; i++, j++, k++ ) {
60 new TestCase( SECTION,
61 "String.indexOf(" +String.fromCharCode(i)+ ", 0)",
62 k,
63 TEST_STRING.indexOf( String.fromCharCode(i), 0 ) );
64 }
65
66 for ( k = 0, i = 0x0020; i < 0x007e; i++, j++, k++ ) {
67 new TestCase( SECTION,
68 "String.indexOf("+String.fromCharCode(i)+ ", "+ k +")",
69 k,
70 TEST_STRING.indexOf( String.fromCharCode(i), k ) );
71 }
72
73 for ( k = 0, i = 0x0020; i < 0x007e; i++, j++, k++ ) {
74 new TestCase( SECTION,
75 "String.indexOf("+String.fromCharCode(i)+ ", "+k+1+")",
76 -1,
77 TEST_STRING.indexOf( String.fromCharCode(i), k+1 ) );
78 }
79
80 for ( k = 0, i = 0x0020; i < 0x007d; i++, j++, k++ ) {
81 new TestCase( SECTION,
82 "String.indexOf("+(String.fromCharCode(i) +
83 String.fromCharCode(i+1)+
84 String.fromCharCode(i+2)) +", "+0+")",
85 k,
86 TEST_STRING.indexOf( (String.fromCharCode(i)+
87 String.fromCharCode(i+1)+
88 String.fromCharCode(i+2)),
89 0 ) );
90 }
91
92 for ( k = 0, i = 0x0020; i < 0x007d; i++, j++, k++ ) {
93 new TestCase( SECTION,
94 "String.indexOf("+(String.fromCharCode(i) +
95 String.fromCharCode(i+1)+
96 String.fromCharCode(i+2)) +", "+ k +")",
97 k,
98 TEST_STRING.indexOf( (String.fromCharCode(i)+
99 String.fromCharCode(i+1)+
100 String.fromCharCode(i+2)),
101 k ) );
102 }
103 for ( k = 0, i = 0x0020; i < 0x007d; i++, j++, k++ ) {
104 new TestCase( SECTION,
105 "String.indexOf("+(String.fromCharCode(i) +
106 String.fromCharCode(i+1)+
107 String.fromCharCode(i+2)) +", "+ k+1 +")",
108 -1,
109 TEST_STRING.indexOf( (String.fromCharCode(i)+
110 String.fromCharCode(i+1)+
111 String.fromCharCode(i+2)),
112 k+1 ) );
113 }
114
115 new TestCase( SECTION, "String.indexOf(" +TEST_STRING + ", 0 )", 0, TEST_STRING.indexOf( TEST_STRING, 0 ) );
116
117 new TestCase( SECTION, "String.indexOf(" +TEST_STRING + ", 1 )", -1, TEST_STRING.indexOf( TEST_STRING, 1 ));
118
119 print( "TEST_STRING = new String(\" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\")" );
120
121
122 test();