1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// check properties 16 17function length_configurable() 18{ 19 function is_es51() { 20 return (typeof g === "function"); 21 { function g() {} } 22 } 23 return is_es51() ? false : true; 24} 25 26assert(Object.getOwnPropertyDescriptor(String.prototype.trim, 'length').configurable === length_configurable()); 27 28assert(Object.getOwnPropertyDescriptor(String.prototype.trim, 'length').enumerable === false); 29 30assert(Object.getOwnPropertyDescriptor(String.prototype.trim, 'length').writable === false); 31 32assert(String.prototype.trim.length === 0); 33 34// check this value 35assert(String.prototype.trim.call(new String()) === ""); 36 37assert(String.prototype.trim.call({}) === "[object Object]"); 38 39// check undefined 40try { 41 String.prototype.trim.call(undefined); 42 assert(false); 43} catch(e) { 44 assert(e instanceof TypeError); 45} 46 47// check null 48try { 49 String.prototype.trim.call(null); 50 assert(false); 51} catch(e) { 52 assert(e instanceof TypeError); 53} 54 55// simple checks 56assert(" hello world".trim() === "hello world"); 57 58assert("hello world ".trim() === "hello world"); 59 60assert(" hello world ".trim() === "hello world"); 61 62assert("\t hello world\n".trim() === "hello world"); 63 64assert("\t\n hello world\t \n ".trim() === "hello world"); 65 66assert("hello world\n \t\t".trim() === "hello world"); 67 68assert(" hello world \\ ".trim() === "hello world \\"); 69 70assert("**hello world**".trim() === "**hello world**"); 71 72assert(" \t \n".trim() === ""); 73 74assert(" ".trim() === ""); 75 76assert("".trim() === ""); 77 78assert("\uf389".trim() === "\uf389"); 79assert(String.prototype.trim.call('\uf389') === "\uf389"); 80assert("\u20291\u00D0".trim() === "1\u00D0"); 81assert("\u20291\u00A0".trim() === "1"); 82 83assert("\u0009\u000B\u000C\u0020\u00A01".trim() === "1"); 84assert("\u000A\u000D\u2028\u202911".trim() === "11"); 85 86assert("\u0009\u000B\u000C\u0020\u00A01\u0009\u000B\u000C\u0020\u00A0".trim() === "1"); 87assert("\u000A\u000D\u2028\u202911\u000A\u000D\u2028\u2029".trim() === "11"); 88 89assert ("\u200B".trim() === '\u200B') 90