diff --git a/testcases/test-builtin-string-proto-tolowercase.js b/testcases/test-builtin-string-proto-tolowercase.js new file mode 100644 index 00000000..cb3bb154 --- /dev/null +++ b/testcases/test-builtin-string-proto-tolowercase.js @@ -0,0 +1,91 @@ +/* + * Basic toLowerCase() tests. Brute-force tests cover these conversions + * in much more detail. + */ + +/*=== +abcd +228 +===*/ + +function basicTest() { + print('AbCd'.toLowerCase()); + print('\u00c4'.toLowerCase().charCodeAt(0)); // U+00C4 (A with dots) -> U+00E4 (a with dots) = 228 +} + +try { + basicTest(); +} catch (e) { + print(e); +} + +/*=== +string 3 97 962 33 +string 3 97 963 97 +===*/ + +/* Locale/language specific rules should NOT apply, but context specific + * rules should. Test just a few basic rules. + */ + +function localeTest() { + var str, t; + + // context specific Greek sigma rule + + str = 'A\u03a3!'; // prev is letter, curr is U+03A3 (Greek capital letter sigma), next is not letter + t = str.toLowerCase(); + print(typeof t, t.length, t.charCodeAt(0), t.charCodeAt(1), t.charCodeAt(2)); + + str = 'A\u03a3A'; // should no longer apply + t = str.toLowerCase(); + print(typeof t, t.length, t.charCodeAt(0), t.charCodeAt(1), t.charCodeAt(2)); + + // FIXME: add locale specific test and ensure locale specific rules do not apply +} + +try { + localeTest(); +} catch (e) { + print(e); +} + +/*=== +TypeError +TypeError +string 4 true +string 5 false +string 3 123 +string 6 foobar +string 9 1,foo,bar +string 15 [object object] +===*/ + +function coercionTest() { + function test(str) { + var t; + + try { + t = String.prototype.toLowerCase.call(str); + print(typeof t, t.length, t); + } catch (e) { + print(e.name); + } + } + + test(undefined); + test(null); + test(true); + test(false); + test(123.0); + test('FoObAr'); + test([1,'fOO','Bar']); + test({ foo: 1, bar: 2 }); +} + +try { + coercionTest(); +} catch (e) { + print(e); +} + diff --git a/testcases/test-builtin-string-proto-tostring-valueof.js b/testcases/test-builtin-string-proto-tostring-valueof.js new file mode 100644 index 00000000..99b71166 --- /dev/null +++ b/testcases/test-builtin-string-proto-tostring-valueof.js @@ -0,0 +1,59 @@ +/*=== +string string 0 0 true +string string 9 9 undefined undefined true +string string 4 4 null null true +string string 4 4 true true true +string string 5 5 false false true +string string 3 3 123 123 true +string string 3 3 foo foo true +string string 3 3 1,2 1,2 true +string string 15 15 [object Object] [object Object] true +string string -1 -1 noval noval true +TypeError +TypeError +===*/ + +function toStringValueOfTest() { + function t(x, noval) { + var t1 = x.toString(); + var t2 = x.valueOf(); + print(typeof t1, typeof t2, + (noval ? -1 : t1.length), (noval ? -1 : t2.length), + (noval ? 'noval' : t1), (noval ? 'noval' : t2), + t1 === t2) + } + + t(new String()); + t(new String(undefined)); + t(new String(null)); + t(new String(true)); + t(new String(false)); + t(new String(123.0)); + t(new String('foo')); + t(new String([1,2])); + t(new String({ foo: 1, bar: 2 })); + + // avoid printing the exact value, as it is implementation dependent + t(new String(function (){}), true); +} + +try { + toStringValueOfTest(); +} catch (e) { + print(e); +} + +try { + // not generic, require TypeError + String.prototype.toString.call({}); +} catch (e) { + print(e.name); +} + +try { + // not generic, require TypeError + String.prototype.valueOf.call({}); +} catch (e) { + print(e.name); +} + diff --git a/testcases/test-builtin-string-proto-touppercase.js b/testcases/test-builtin-string-proto-touppercase.js new file mode 100644 index 00000000..04ad1223 --- /dev/null +++ b/testcases/test-builtin-string-proto-touppercase.js @@ -0,0 +1,81 @@ +/* + * Basic toUpperCase() tests. Brute-force tests cover these conversions + * in much more detail. + */ + +/*=== +ABCD +196 +===*/ + +function basicTest() { + print('AbCd'.toUpperCase()); + print('\u00e4'.toUpperCase().charCodeAt(0)); // U+00E4 (a with dots) -> U+00E4 (A with dots) = 196 +} + +try { + basicTest(); +} catch (e) { + print(e); +} + +/*=== +===*/ + +/* Locale/language specific rules should NOT apply, but context specific + * rules should. Test just a few basic rules. + */ + +function localeTest() { + var str, t; + + // FIXME: add context specific test and ensure context specific rules apply + // FIXME: add locale specific test and ensure locale specific rules do not apply +} + +try { + localeTest(); +} catch (e) { + print(e); +} + + +/*=== +string 15 [OBJECT GLOBAL] +string 15 [OBJECT GLOBAL] +string 4 TRUE +string 5 FALSE +string 3 123 +string 6 FOOBAR +string 9 1,FOO,BAR +string 15 [OBJECT OBJECT] +===*/ + +function coercionTest() { + function test(str) { + var t; + + try { + t = String.prototype.toUpperCase.call(str); + print(typeof t, t.length, t); + } catch (e) { + print(e.name); + } + } + + test(undefined); + test(null); + test(true); + test(false); + test(123.0); + test('FoObAr'); + test([1,'fOO','Bar']); + test({ foo: 1, bar: 2 }); +} + +try { + coercionTest(); +} catch (e) { + print(e); +} +