/* use Spidermonkey JS interpreter to run these tests. */ load("with.js"); print("startsWith:"); print(true == startsWith('hello', 'he')); print(true == startsWith('hello', 'hello')); print(false == startsWith('hello', 'hello world')); print(true == startsWith('hello', '')); print(false == startsWith('hello', 'ello')); print(true == startsWith('hello', 'ello', 1)); print(true == startsWith('hello', 'o', 4)); print(false == startsWith('hello', 'o', 5)); print(true == startsWith('hello', '', 5)); print(false == startsWith('hello', 'lo', 6)); print(true == startsWith('helloworld', 'lowo', 3)); print(true == startsWith('helloworld', 'lowo', 3, 7)); print(false == startsWith('helloworld', 'lowo', 3, 6)); // test negative indices print(true == startsWith('hello', 'he', 0, -1)); print(true == startsWith('hello', 'he', -53, -1)); print(false == startsWith('hello', 'hello', 0, -1)); print(false == startsWith('hello', 'hello world', -1, -10)); print(false == startsWith('hello', 'ello', -5)); print(true == startsWith('hello', 'ello', -4)); print(false == startsWith('hello', 'o', -2)); print(true == startsWith('hello', 'o', -1)); print(true == startsWith('hello', '', -3, -3)); print(false == startsWith('hello', 'lo', -9)); // non strings return false print(false == startsWith("hello", new Date())); print(false == startsWith("hello", 42)); // test array arguments print(true == startsWith('hello', ['he', 'ha'])); print(false == startsWith('hello', ['lo', 'llo'])); print(true == startsWith('hello', ['hellox', 'hello'])); print(false == startsWith('hello', [])); print(true == startsWith('helloworld', ['hellowo', 'rld', 'lowo'], 3)); print(false == startsWith('helloworld', ['hellowo', 'ello', 'rld'], 3)); print(true == startsWith('hello', ['lo', 'he'], 0, -1)); print(false == startsWith('hello', ['he', 'hel'], 0, 1)); print(true == startsWith('hello', ['he', 'hel'], 0, 2)); // array with non strings return false print(false == startsWith('hello', [42])); print(false == startsWith('hello', [new Date()])); try { startsWith(); print(false); } catch(TypeError) { print(true); } try { startsWith('hello'); print(false); } catch(TypeError) { print(true); } print("\nendsWith:"); print(true == endsWith('hello', 'lo')); print(false == endsWith('hello', 'he')); print(true == endsWith('hello', '')); print(false == endsWith('hello', 'hello world')); print(false == endsWith('helloworld', 'worl')); print(true == endsWith('helloworld', 'worl', 3, 9)); print(true == endsWith('helloworld', 'world', 3, 12)); print(true == endsWith('helloworld', 'lowo', 1, 7)); print(true == endsWith('helloworld', 'lowo', 2, 7)); print(true == endsWith('helloworld', 'lowo', 3, 7)); print(false == endsWith('helloworld', 'lowo', 4, 7)); print(false == endsWith('helloworld', 'lowo', 3, 8)); print(false == endsWith('ab', 'ab', 0, 1)); print(false == endsWith('ab', 'ab', 0, 0)); // test negative indices print(true == endsWith('hello', 'lo', -2)); print(false == endsWith('hello', 'he', -2)); print(true == endsWith('hello', '', -3, -3)); print(false == endsWith('hello', 'hello world', -10, -2)); print(false == endsWith('helloworld', 'worl', -6)); print(true == endsWith('helloworld', 'worl', -5, -1)); print(true == endsWith('helloworld', 'worl', -5, 9)); print(true == endsWith('helloworld', 'world', -7, 12)); print(true == endsWith('helloworld', 'lowo', -99, -3)); print(true == endsWith('helloworld', 'lowo', -8, -3)); print(true == endsWith('helloworld', 'lowo', -7, -3)); print(false == endsWith('helloworld', 'lowo', 3, -4)); print(false == endsWith('helloworld', 'lowo', -8, -2)); // non strings return false print(false == endsWith("hello", new Date())); print(false == endsWith("hello", 42)); // test array arguments print(false == endsWith('hello', ['he', 'ha'])); print(true == endsWith('hello', ['lo', 'llo'])); print(true == endsWith('hello', ['hellox', 'hello'])); print(false == endsWith('hello', [])); print(true == endsWith('helloworld', ['hellowo', 'rld', 'lowo'], 3)); print(false == endsWith('helloworld', ['hellowo', 'ello', 'rld'], 3, -1)); print(true == endsWith('hello', ['hell', 'ell'], 0, -1)); print(false == endsWith('hello', ['he', 'hel'], 0, 1)); print(true == endsWith('hello', ['he', 'hell'], 0, 4)); // array with non strings return false print(false == endsWith('hello', [42])); print(false == endsWith('hello', [new Date()])); try { endsWith(); print(false); } catch(TypeError) { print(true); } try { endsWith('hello'); print(false); } catch(TypeError) { print(true); }