Espruino/tests/test_string_trim.js
Gordon Williams 2d98b5bb7e Added more allowed types of whitespace
Added String.prototype.trim() (fix #507)
2015-03-30 16:53:46 +01:00

17 lines
506 B
JavaScript

function test(a,b) {
var ea = eval(a);
if (JSON.stringify(ea)!=JSON.stringify(b)) {
console.log(JSON.stringify(a)+" should be "+JSON.stringify(b)+", got "+JSON.stringify(ea))
result = 0;
}
}
result = 1;
test('"Hello World".trim()',"Hello World");
test('" \t\n\rHello World".trim()',"Hello World");
test('"Hello World \t\n\r".trim()',"Hello World");
test('" \t\n\rHello World \t\n\r".trim()',"Hello World");
test('"X".trim()',"X");
test('" X ".trim()',"X");
test('" ".trim()',"");