Preparation Code Preparation HTML (this will be inserted in the <body>
of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script >
function startsWithCharAt (string, pattern ) {
for (var i = 0 , length = pattern.length ; i < length; i += 1 ) {
if (pattern.charAt (i) !== string.charAt (i)) return false ;
}
return true ;
}
function startsWithArray (string, pattern ) {
for (var i = 0 , length = pattern.length ; i < length; i += 1 ) {
if (pattern[i] !== string[i]) return false ;
}
return true ;
}
</script >
Setup JS a = ["test" ];
for (var i = 0 ; i < 10000 ; i++) {
a.push ("some other stuff" );
}
s = a.join ();
re1 = new RegExp ("^test" );
re2 = new RegExp ("^not there" );
Teardown JS
Test cases
Test #1 Title *
Async
Code * r1 = (s.indexOf ("test" ) == 0 );
r2 = (s.indexOf ("not there" ) == 0 );
Test #2 Title *
Async
Code * r1 = (s.lastIndexOf ("test" , 0 ) == 0 );
r2 = (s.lastIndexOf ("not there" , 0 ) == 0 );
Title *
Async
Code * r1 = (s.substring (0 , "test" .length ) == "test" );
r2 = (s.substring (0 , "not there" .length ) == "not there" );
Title *
Async
Code * r1 = (s.slice (0 , "test" .length ) == "test" );
r2 = (s.slice (0 , "not there" .length ) == "not there" );
Title *
Async
Code * r1 = (/^test/ ).test (s);
r2 = (/^not there/ ).test (s);
Title *
Async
Code * r1 = re1.test (s);
r2 = re2.test (s);
Title *
Async
Code * r1 = startsWithCharAt (s, "test" );
r2 = startsWithCharAt (s, "not there" );
Title *
Async
Code * r1 = (s.substr (0 , "test" .length ) == "test" );
r2 = (s.substr (0 , "not there" .length ) == "not there" );
Title *
Async
Code * r1 = startsWithArray (s, "test" );
r2 = startsWithArray (s, "not there" );