summaryrefslogtreecommitdiffstats
path: root/js/src/tests/js1_2/String
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/js1_2/String')
-rw-r--r--js/src/tests/js1_2/String/browser.js0
-rw-r--r--js/src/tests/js1_2/String/charCodeAt.js38
-rw-r--r--js/src/tests/js1_2/String/concat.js50
-rw-r--r--js/src/tests/js1_2/String/match.js29
-rw-r--r--js/src/tests/js1_2/String/shell.js0
-rw-r--r--js/src/tests/js1_2/String/slice.js90
6 files changed, 207 insertions, 0 deletions
diff --git a/js/src/tests/js1_2/String/browser.js b/js/src/tests/js1_2/String/browser.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/js1_2/String/browser.js
diff --git a/js/src/tests/js1_2/String/charCodeAt.js b/js/src/tests/js1_2/String/charCodeAt.js
new file mode 100644
index 000000000..b746a06fb
--- /dev/null
+++ b/js/src/tests/js1_2/String/charCodeAt.js
@@ -0,0 +1,38 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ Filename: charCodeAt.js
+ Description: 'This tests new String object method: charCodeAt'
+
+ Author: Nick Lerissa
+ Date: Fri Feb 13 09:58:28 PST 1998
+*/
+
+var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
+var VERSION = 'no version';
+startTest();
+var TITLE = 'String:charCodeAt';
+
+writeHeaderToLog('Executing script: charCodeAt.js');
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+var aString = new String("tEs5");
+
+new TestCase( SECTION, "aString.charCodeAt(-2)", NaN, aString.charCodeAt(-2));
+new TestCase( SECTION, "aString.charCodeAt(-1)", NaN, aString.charCodeAt(-1));
+new TestCase( SECTION, "aString.charCodeAt( 0)", 116, aString.charCodeAt( 0));
+new TestCase( SECTION, "aString.charCodeAt( 1)", 69, aString.charCodeAt( 1));
+new TestCase( SECTION, "aString.charCodeAt( 2)", 115, aString.charCodeAt( 2));
+new TestCase( SECTION, "aString.charCodeAt( 3)", 53, aString.charCodeAt( 3));
+new TestCase( SECTION, "aString.charCodeAt( 4)", NaN, aString.charCodeAt( 4));
+new TestCase( SECTION, "aString.charCodeAt( 5)", NaN, aString.charCodeAt( 5));
+new TestCase( SECTION, "aString.charCodeAt( Infinity)", NaN, aString.charCodeAt( Infinity));
+new TestCase( SECTION, "aString.charCodeAt(-Infinity)", NaN, aString.charCodeAt(-Infinity));
+//new TestCase( SECTION, "aString.charCodeAt( )", 116, aString.charCodeAt( ));
+
+test();
+
diff --git a/js/src/tests/js1_2/String/concat.js b/js/src/tests/js1_2/String/concat.js
new file mode 100644
index 000000000..a0828cf1c
--- /dev/null
+++ b/js/src/tests/js1_2/String/concat.js
@@ -0,0 +1,50 @@
+// |reftest| skip -- obsolete test
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ Filename: concat.js
+ Description: 'This tests the new String object method: concat'
+
+ Author: NickLerissa
+ Date: Fri Feb 13 09:58:28 PST 1998
+*/
+
+var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
+var VERSION = 'no version';
+startTest();
+var TITLE = 'String:concat';
+
+writeHeaderToLog('Executing script: concat.js');
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+var aString = new String("test string");
+var bString = new String(" another ");
+
+new TestCase( SECTION, "aString.concat(' more')", "test string more", aString.concat(' more').toString());
+new TestCase( SECTION, "aString.concat(bString)", "test string another ", aString.concat(bString).toString());
+new TestCase( SECTION, "aString ", "test string", aString.toString());
+new TestCase( SECTION, "bString ", " another ", bString.toString());
+new TestCase( SECTION, "aString.concat(345) ", "test string345", aString.concat(345).toString());
+new TestCase( SECTION, "aString.concat(true) ", "test stringtrue", aString.concat(true).toString());
+new TestCase( SECTION, "aString.concat(null) ", "test stringnull", aString.concat(null).toString());
+new TestCase( SECTION, "aString.concat([]) ", "test string[]", aString.concat([]).toString());
+new TestCase( SECTION, "aString.concat([1,2,3])", "test string[1, 2, 3]", aString.concat([1,2,3]).toString());
+
+new TestCase( SECTION, "'abcde'.concat(' more')", "abcde more", 'abcde'.concat(' more').toString());
+new TestCase( SECTION, "'abcde'.concat(bString)", "abcde another ", 'abcde'.concat(bString).toString());
+new TestCase( SECTION, "'abcde' ", "abcde", 'abcde');
+new TestCase( SECTION, "'abcde'.concat(345) ", "abcde345", 'abcde'.concat(345).toString());
+new TestCase( SECTION, "'abcde'.concat(true) ", "abcdetrue", 'abcde'.concat(true).toString());
+new TestCase( SECTION, "'abcde'.concat(null) ", "abcdenull", 'abcde'.concat(null).toString());
+new TestCase( SECTION, "'abcde'.concat([]) ", "abcde[]", 'abcde'.concat([]).toString());
+new TestCase( SECTION, "'abcde'.concat([1,2,3])", "abcde[1, 2, 3]", 'abcde'.concat([1,2,3]).toString());
+
+//what should this do:
+new TestCase( SECTION, "'abcde'.concat() ", "abcde", 'abcde'.concat().toString());
+
+test();
+
diff --git a/js/src/tests/js1_2/String/match.js b/js/src/tests/js1_2/String/match.js
new file mode 100644
index 000000000..ef4df16f9
--- /dev/null
+++ b/js/src/tests/js1_2/String/match.js
@@ -0,0 +1,29 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ Filename: match.js
+ Description: 'This tests the new String object method: match'
+
+ Author: NickLerissa
+ Date: Fri Feb 13 09:58:28 PST 1998
+*/
+
+var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
+var VERSION = 'no version';
+startTest();
+var TITLE = 'String:match';
+
+writeHeaderToLog('Executing script: match.js');
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+var aString = new String("this is a test string");
+
+new TestCase( SECTION, "aString.match(/is.*test/) ", String(["is is a test"]), String(aString.match(/is.*test/)));
+new TestCase( SECTION, "aString.match(/s.*s/) ", String(["s is a test s"]), String(aString.match(/s.*s/)));
+
+test();
+
diff --git a/js/src/tests/js1_2/String/shell.js b/js/src/tests/js1_2/String/shell.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/js1_2/String/shell.js
diff --git a/js/src/tests/js1_2/String/slice.js b/js/src/tests/js1_2/String/slice.js
new file mode 100644
index 000000000..e939434ae
--- /dev/null
+++ b/js/src/tests/js1_2/String/slice.js
@@ -0,0 +1,90 @@
+/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ Filename: slice.js
+ Description: 'This tests the String object method: slice'
+
+ Author: Nick Lerissa
+ Date: Fri Feb 13 09:58:28 PST 1998
+*/
+
+var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
+var VERSION = 'no version';
+startTest();
+var TITLE = 'String.slice';
+
+writeHeaderToLog('Executing script: slice.js');
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+var a = new String("abcdefghijklmnopqrstuvwxyz1234567890");
+var b = new String("this is a test string");
+
+exhaustiveStringSliceTest("exhaustive String.slice test 1", a);
+exhaustiveStringSliceTest("exhaustive String.slice test 2", b);
+
+test();
+
+
+function myStringSlice(a, from, to)
+{
+ var from2 = from;
+ var to2 = to;
+ var returnString = new String("");
+ var i;
+
+ if (from2 < 0) from2 = a.length + from;
+ if (to2 < 0) to2 = a.length + to;
+
+ if ((to2 > from2)&&(to2 > 0)&&(from2 < a.length))
+ {
+ if (from2 < 0) from2 = 0;
+ if (to2 > a.length) to2 = a.length;
+
+ for (i = from2; i < to2; ++i) returnString += a.charAt(i);
+ }
+ return returnString;
+}
+
+// This function tests the slice command on a String
+// passed in. The arguments passed into slice range in
+// value from -5 to the length of the array + 4. Every
+// combination of the two arguments is tested. The expected
+// result of the slice(...) method is calculated and
+// compared to the actual result from the slice(...) method.
+// If the Strings are not similar false is returned.
+function exhaustiveStringSliceTest(testname, a)
+{
+ var x = 0;
+ var y = 0;
+ var errorMessage;
+ var reason = "";
+ var passed = true;
+
+ for (x = -(2 + a.length); x <= (2 + a.length); x++)
+ for (y = (2 + a.length); y >= -(2 + a.length); y--)
+ {
+ var b = a.slice(x,y);
+ var c = myStringSlice(a,x,y);
+
+ if (String(b) != String(c))
+ {
+ errorMessage =
+ "ERROR: 'TEST FAILED' ERROR: 'TEST FAILED' ERROR: 'TEST FAILED'\n" +
+ " test: " + "a.slice(" + x + "," + y + ")\n" +
+ " a: " + String(a) + "\n" +
+ " actual result: " + String(b) + "\n" +
+ " expected result: " + String(c) + "\n";
+ writeHeaderToLog(errorMessage);
+ reason = reason + errorMessage;
+ passed = false;
+ }
+ }
+ var testCase = new TestCase(SECTION, testname, true, passed);
+ if (passed == false)
+ testCase.reason = reason;
+ return testCase;
+}