QML_RUNTIME_TESTING should be disabled by default.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / parserstress / tests / ecma / String / 15.5.4.6-1.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 gTestfile = '15.5.4.6-1.js';
40
41 /**
42    File Name:          15.5.4.6-1.js
43    ECMA Section:       15.5.4.6 String.prototype.indexOf( searchString, pos)
44    Description:        If the given searchString appears as a substring of the
45    result of converting this object to a string, at one or
46    more positions that are at or to the right of the
47    specified position, then the index of the leftmost such
48    position is returned; otherwise -1 is returned.  If
49    positionis undefined or not supplied, 0 is assumed, so
50    as to search all of the string.
51
52    When the indexOf method is called with two arguments,
53    searchString and pos, the following steps are taken:
54
55    1. Call ToString, giving it the this value as its
56    argument.
57    2. Call ToString(searchString).
58    3. Call ToInteger(position). (If position is undefined
59    or not supplied, this step produces the value 0).
60    4. Compute the number of characters in Result(1).
61    5. Compute min(max(Result(3), 0), Result(4)).
62    6. Compute the number of characters in the string that
63    is Result(2).
64    7. Compute the smallest possible integer k not smaller
65    than Result(5) such that k+Result(6) is not greater
66    than Result(4), and for all nonnegative integers j
67    less than Result(6), the character at position k+j
68    of Result(1) is the same as the character at position
69    j of Result(2); but if there is no such integer k,
70    then compute the value -1.
71    8. Return Result(7).
72
73    Note that the indexOf function is intentionally generic;
74    it does not require that its this value be a String object.
75    Therefore it can be transferred to other kinds of objects
76    for use as a method.
77
78    Author:             christine@netscape.com
79    Date:               2 october 1997
80 */
81 var SECTION = "15.5.4.6-1";
82 var VERSION = "ECMA_1";
83 startTest();
84 var TITLE   = "String.protoype.indexOf";
85
86 var TEST_STRING = new String( " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" );
87
88 writeHeaderToLog( SECTION + " "+ TITLE);
89
90 var j = 0;
91
92 for ( k = 0, i = 0x0020; i < 0x007e; i++, j++, k++ ) {
93   new TestCase( SECTION,
94                 "String.indexOf(" +String.fromCharCode(i)+ ", 0)",
95                 k,
96                 TEST_STRING.indexOf( String.fromCharCode(i), 0 ) );
97 }
98
99 for ( k = 0, i = 0x0020; i < 0x007e; i++, j++, k++ ) {
100   new TestCase( SECTION,
101                 "String.indexOf("+String.fromCharCode(i)+ ", "+ k +")",
102                 k,
103                 TEST_STRING.indexOf( String.fromCharCode(i), k ) );
104 }
105
106 for ( k = 0, i = 0x0020; i < 0x007e; i++, j++, k++ ) {
107   new TestCase( SECTION,
108                 "String.indexOf("+String.fromCharCode(i)+ ", "+k+1+")",
109                 -1,
110                 TEST_STRING.indexOf( String.fromCharCode(i), k+1 ) );
111 }
112
113 for ( k = 0, i = 0x0020; i < 0x007d; i++, j++, k++ ) {
114   new TestCase( SECTION,
115                 "String.indexOf("+(String.fromCharCode(i) +
116                                    String.fromCharCode(i+1)+
117                                    String.fromCharCode(i+2)) +", "+0+")",
118                 k,
119                 TEST_STRING.indexOf( (String.fromCharCode(i)+
120                                       String.fromCharCode(i+1)+
121                                       String.fromCharCode(i+2)),
122                                      0 ) );
123 }
124
125 for ( k = 0, i = 0x0020; i < 0x007d; i++, j++, k++ ) {
126   new TestCase( SECTION,
127                 "String.indexOf("+(String.fromCharCode(i) +
128                                    String.fromCharCode(i+1)+
129                                    String.fromCharCode(i+2)) +", "+ k +")",
130                 k,
131                 TEST_STRING.indexOf( (String.fromCharCode(i)+
132                                       String.fromCharCode(i+1)+
133                                       String.fromCharCode(i+2)),
134                                      k ) );
135 }
136 for ( k = 0, i = 0x0020; i < 0x007d; i++, j++, k++ ) {
137   new TestCase( SECTION,
138                 "String.indexOf("+(String.fromCharCode(i) +
139                                    String.fromCharCode(i+1)+
140                                    String.fromCharCode(i+2)) +", "+ k+1 +")",
141                 -1,
142                 TEST_STRING.indexOf( (String.fromCharCode(i)+
143                                       String.fromCharCode(i+1)+
144                                       String.fromCharCode(i+2)),
145                                      k+1 ) );
146 }
147
148 new TestCase( SECTION,  "String.indexOf(" +TEST_STRING + ", 0 )", 0, TEST_STRING.indexOf( TEST_STRING, 0 ) );
149
150 new TestCase( SECTION,  "String.indexOf(" +TEST_STRING + ", 1 )", -1, TEST_STRING.indexOf( TEST_STRING, 1 ));
151
152 print( "TEST_STRING = new String(\" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\")" );
153
154
155 test();