Enable regular expressions.
- add regular expressions support to JS parser and interpreter; - add tests for regular expressions. JerryScript-DCO-1.0-Signed-off-by: Szilard Ledan szledan.u-szeged@partner.samsung.com JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
// Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
// Copyright 2015 University of Szeged.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var r;
|
||||
|
||||
r = new RegExp ("a|b");
|
||||
assert (r.exec("a") == "a");
|
||||
|
||||
r = new RegExp ("a|b");
|
||||
assert (r.exec("b") == "b");
|
||||
|
||||
r = new RegExp ("a|b|c");
|
||||
assert (r.exec("b") == "b");
|
||||
|
||||
r = new RegExp ("a|b|c");
|
||||
assert (r.exec("c") == "c");
|
||||
|
||||
r = new RegExp ("a|b|c|d");
|
||||
assert (r.exec("") == undefined);
|
||||
|
||||
r = new RegExp ("a|b|c|d");
|
||||
assert (r.exec("a") == "a");
|
||||
|
||||
r = new RegExp ("a|b|c|d");
|
||||
assert (r.exec("b") == "b");
|
||||
|
||||
r = new RegExp ("a|b|c|d");
|
||||
assert (r.exec("c") == "c");
|
||||
|
||||
r = new RegExp ("a|b|c|d");
|
||||
assert (r.exec("d") == "d");
|
||||
|
||||
r = new RegExp ("a|bb|c|d");
|
||||
assert (r.exec("e") == undefined);
|
||||
|
||||
r = new RegExp ("a|bb|c|d");
|
||||
assert (r.exec("bb") == "bb");
|
||||
|
||||
r = new RegExp ("a|bb|c|d");
|
||||
assert (r.exec("bba") == "bb");
|
||||
|
||||
r = new RegExp ("a|bb|c|d");
|
||||
assert (r.exec("bbbb") == "bb");
|
||||
|
||||
r = new RegExp ("a|bb|c|d");
|
||||
assert (r.exec("a") == "a");
|
||||
|
||||
r = new RegExp ("a|bb|c|d");
|
||||
assert (r.exec("b") == undefined);
|
||||
@@ -0,0 +1,152 @@
|
||||
// Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
// Copyright 2015 University of Szeged.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var t;
|
||||
|
||||
t = new RegExp ("^alma$").exec("alma");
|
||||
assert (t == "alma");
|
||||
|
||||
t = new RegExp ("^alma$").exec("almaa");
|
||||
assert (t == undefined);
|
||||
|
||||
t = new RegExp ("^alma$").exec("aalma");
|
||||
assert (t == undefined);
|
||||
|
||||
t = new RegExp ("^alma").exec("alma");
|
||||
assert (t == "alma");
|
||||
|
||||
t = new RegExp ("^alma").exec("almaa");
|
||||
assert (t == "alma");
|
||||
|
||||
t = new RegExp ("^alma").exec("aalma");
|
||||
assert (t == undefined);
|
||||
|
||||
t = new RegExp ("alma$").exec("alma");
|
||||
assert (t == "alma");
|
||||
|
||||
t = new RegExp ("alma$").exec("almaa");
|
||||
assert (t == undefined);
|
||||
|
||||
t = new RegExp ("alma$").exec("aalma");
|
||||
assert (t == "alma");
|
||||
|
||||
t = new RegExp ("\\bis\\b").exec("This island is beautiful");
|
||||
assert (t == "is");
|
||||
|
||||
t = new RegExp ("\\Bis\\B").exec("This island is beautiful");
|
||||
assert (t == undefined);
|
||||
|
||||
t = new RegExp ("\\Bis").exec("This island is beautiful");
|
||||
assert (t == "is");
|
||||
|
||||
t = new RegExp ("is\\B").exec("This island is beautiful");
|
||||
assert (t == "is");
|
||||
|
||||
t = new RegExp ("\\Bis\\b").exec("This island is beautiful");
|
||||
assert (t == "is");
|
||||
|
||||
t = new RegExp ("\\bis\\B").exec("This island is beautiful");
|
||||
assert (t == "is");
|
||||
|
||||
t = new RegExp ("al(?=(ma))").exec("al");
|
||||
assert (t == undefined);
|
||||
|
||||
t = new RegExp ("al(?!(ma))").exec("ala");
|
||||
assert (t[0] == "al");
|
||||
assert (t[1] == undefined);
|
||||
|
||||
t = new RegExp ("al(?=(ma))").exec("alma");
|
||||
assert (t[0] == "al");
|
||||
assert (t[1] == "ma");
|
||||
|
||||
t = new RegExp ("al(?=(ma))").exec("almama");
|
||||
assert (t[0] == "al");
|
||||
assert (t[1] == "ma");
|
||||
|
||||
t = new RegExp ("(al)(?=(ma))ma").exec("al");
|
||||
assert (t == undefined);
|
||||
|
||||
t = new RegExp ("(al)(?=(ma)ma)").exec("al");
|
||||
assert (t == undefined);
|
||||
|
||||
t = new RegExp ("al(?=(ma))*ma").exec("alma");
|
||||
assert (t[0] == "alma");
|
||||
assert (t[1] == undefined);
|
||||
|
||||
t = new RegExp ("al(?!(ma))*ma").exec("alma");
|
||||
assert (t[0] == "alma");
|
||||
assert (t[1] == undefined);
|
||||
|
||||
t = new RegExp ("al(?=(ma))ma").exec("alma");
|
||||
assert (t[0] == "alma");
|
||||
assert (t[1] == "ma");
|
||||
|
||||
t = new RegExp ("al(?!(ma))ma").exec("alma");
|
||||
assert (t == undefined);
|
||||
|
||||
t = new RegExp ("(al)(?=(ma))ma").exec("almama");
|
||||
t = new RegExp ("(al)(?=(ma)ma)").exec("almama");
|
||||
|
||||
t = new RegExp ("al(?=(ma))ma").exec("almama");
|
||||
assert (t[0] == "alma");
|
||||
assert (t[1] == "ma");
|
||||
|
||||
t = new RegExp ("al(?=(ma)ma)").exec("almama");
|
||||
assert (t[0] == "al");
|
||||
assert (t[1] == "ma");
|
||||
|
||||
t = new RegExp ("al(?!(ma))ma").exec("almama");
|
||||
assert (t == undefined);
|
||||
|
||||
t = new RegExp ("a(?=(a)(a))aab|aaac").exec("aaac");
|
||||
t = new RegExp ("a(?=(a)(a))aab|aaac").exec("aaab");
|
||||
|
||||
t = new RegExp ("(?!(a)b)|ab").exec("ab");
|
||||
assert (t[0] == "ab");
|
||||
assert (t[1] == undefined);
|
||||
|
||||
t = new RegExp ("(?=(a)b)|ab").exec("ab");
|
||||
assert (t[0] == "");
|
||||
assert (t[1] == "a");
|
||||
|
||||
t = new RegExp ("(?=a|.)Dt").exec("Dt");
|
||||
assert (t == "Dt");
|
||||
|
||||
t = new RegExp ("(?=.|a)Dt").exec("Dt");
|
||||
assert (t == "Dt");
|
||||
|
||||
t = new RegExp ("(?=a|b)Dt").exec("Dt");
|
||||
assert (t == undefined);
|
||||
|
||||
t = new RegExp ("(?=.|P)").exec("a");
|
||||
assert (t == "");
|
||||
|
||||
t = new RegExp ("(?=.)").exec("a");
|
||||
assert (t == "");
|
||||
|
||||
t = new RegExp ("(?!a|.)Dt").exec("Dt");
|
||||
assert (t == undefined);
|
||||
|
||||
t = new RegExp ("(?!.|a)Dt").exec("Dt");
|
||||
assert (t == undefined);
|
||||
|
||||
t = new RegExp ("(?!a|b)Dt").exec("Dt");
|
||||
assert (t == "Dt");
|
||||
|
||||
t = new RegExp ("(?!.|P)").exec("a");
|
||||
assert (t == "");
|
||||
|
||||
t = new RegExp ("(?!.)").exec("a");
|
||||
assert (t == "");
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
// Copyright 2015 University of Szeged.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var r;
|
||||
|
||||
r = new RegExp ("(a)b\\1").exec("aba");
|
||||
assert (r[0] == "aba");
|
||||
assert (r[1] == "a");
|
||||
|
||||
r = new RegExp ("(a)b\\1").exec("b");
|
||||
assert (r == undefined);
|
||||
|
||||
r = new RegExp ("(a)*b\\1").exec("b");
|
||||
assert (r[0] == "b");
|
||||
assert (r[1] == undefined);
|
||||
@@ -0,0 +1,199 @@
|
||||
// Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
// Copyright 2015 University of Szeged.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var r;
|
||||
|
||||
// Simple test cases
|
||||
r = new RegExp ("()");
|
||||
assert (r.exec ("a") == ",");
|
||||
|
||||
r = new RegExp ("(a)");
|
||||
assert (r.exec ("a") == "a,a");
|
||||
|
||||
r = new RegExp ("((a)b)c");
|
||||
assert (r.exec ("abc") == "abc,ab,a");
|
||||
|
||||
r = new RegExp ("(a)*");
|
||||
assert (r.exec ("b")[0] == "");
|
||||
assert (r.exec ("b")[1] == undefined);
|
||||
assert (r.exec ("aaaa") == "aaaa,a");
|
||||
|
||||
r = new RegExp ("(a)+");
|
||||
assert (r.exec ("aaaa") == "aaaa,a");
|
||||
|
||||
r = new RegExp ("(a){4}");
|
||||
assert (r.exec ("aaaa") == "aaaa,a");
|
||||
|
||||
r = new RegExp ("(a){1,2}");
|
||||
assert (r.exec ("a") == "a,a");
|
||||
assert (r.exec ("aa") == "aa,a");
|
||||
assert (r.exec ("aaaa") == "aa,a");
|
||||
|
||||
r = new RegExp ("(a)?");
|
||||
assert (r.exec ("a") == "a,a");
|
||||
assert (r.exec ("b")[0] == "");
|
||||
assert (r.exec ("b")[1] == undefined);
|
||||
|
||||
// Test greedy iterations
|
||||
r = new RegExp ("(a){1,3}a");
|
||||
assert (r.exec("aa") == "aa,a");
|
||||
|
||||
r = new RegExp ("(a){1,3}a");
|
||||
assert (r.exec("aaa") == "aaa,a");
|
||||
|
||||
r = new RegExp ("(a){1,3}");
|
||||
assert (r.exec("a") == "a,a");
|
||||
|
||||
r = new RegExp ("(a){1,3}");
|
||||
assert (r.exec("aaa") == "aaa,a");
|
||||
|
||||
r = new RegExp ("(a){1,3}");
|
||||
assert (r.exec("aaaa") == "aaa,a");
|
||||
|
||||
r = new RegExp ("(a){1,5}");
|
||||
assert (r.exec("aaaa") == "aaaa,a");
|
||||
|
||||
r = new RegExp ("(a|b){1,2}");
|
||||
assert (r.exec("a") == "a,a");
|
||||
|
||||
r = new RegExp ("(a|b){1,3}a");
|
||||
assert (r.exec("aaa") == "aaa,a");
|
||||
|
||||
r = new RegExp ("(a|b){1,3}a");
|
||||
assert (r.exec("aba") == "aba,b");
|
||||
|
||||
r = new RegExp ("(a|b){1,3}a");
|
||||
assert (r.exec("b") == undefined);
|
||||
|
||||
r = new RegExp ("(a|b){1,3}a");
|
||||
assert (r.exec("bbb") == undefined);
|
||||
|
||||
r = new RegExp ("(a|b){1,3}");
|
||||
assert (r.exec("a") == "a,a");
|
||||
|
||||
r = new RegExp ("(a|b){1,3}");
|
||||
assert (r.exec("aa") == "aa,a");
|
||||
|
||||
r = new RegExp ("(a|b){1,3}");
|
||||
assert (r.exec("aaa") == "aaa,a");
|
||||
|
||||
r = new RegExp ("(a|b){1,3}");
|
||||
assert (r.exec("ab") == "ab,b");
|
||||
|
||||
r = new RegExp ("(a|b){1,3}");
|
||||
assert (r.exec("aba") == "aba,a");
|
||||
|
||||
r = new RegExp ("(a|b){1,3}");
|
||||
assert (r.exec("bab") == "bab,b");
|
||||
|
||||
r = new RegExp ("(a|b){1,3}");
|
||||
assert (r.exec("bbb") == "bbb,b");
|
||||
|
||||
r = new RegExp ("(a|b){1,4}a");
|
||||
assert (r.exec("bbb") == undefined);
|
||||
|
||||
r = new RegExp ("(a|b){1,4}");
|
||||
assert (r.exec("ab") == "ab,b");
|
||||
|
||||
r = new RegExp ("(a|b){1,4}");
|
||||
assert (r.exec("aba") == "aba,a");
|
||||
|
||||
r = new RegExp ("(a|b){1,4}");
|
||||
assert (r.exec("bbb") == "bbb,b");
|
||||
|
||||
r = new RegExp ("(a|b){1,5}");
|
||||
assert (r.exec("aba") == "aba,a");
|
||||
|
||||
r = new RegExp ("(a|b){1,5}");
|
||||
assert (r.exec("abab") == "abab,b");
|
||||
|
||||
r = new RegExp ("(a|b){1,5}");
|
||||
assert (r.exec("bbb") == "bbb,b");
|
||||
|
||||
r = new RegExp ("(aba)*");
|
||||
assert (r.exec("aaaa") == ",");
|
||||
|
||||
r = new RegExp ("(aba)+");
|
||||
assert (r.exec("aaaa") == undefined);
|
||||
|
||||
r = new RegExp ("(a|bb|c|d)");
|
||||
assert (r.exec("a") == "a,a");
|
||||
|
||||
r = new RegExp ("(a|b)");
|
||||
assert (r.exec("a") == "a,a");
|
||||
|
||||
r = new RegExp ("(a|b)+");
|
||||
assert (r.exec("aba") == "aba,a");
|
||||
|
||||
r = new RegExp ("(a|b)");
|
||||
assert (r.exec("b") == "b,b");
|
||||
|
||||
r = new RegExp ("(a)");
|
||||
assert (r.exec("a") == "a,a");
|
||||
|
||||
r = new RegExp ("(a)*");
|
||||
assert (r.exec("a") == "a,a");
|
||||
|
||||
r = new RegExp ("(a)*");
|
||||
assert (r.exec("aaaa") == "aaaa,a");
|
||||
|
||||
r = new RegExp ("(a)+");
|
||||
assert (r.exec("aaaa") == "aaaa,a");
|
||||
|
||||
r = new RegExp ("(a|aa){0,3}b");
|
||||
assert (r.exec("aaaaaab") == "aaaaaab,aa");
|
||||
|
||||
r = new RegExp ("((a){2,3}){4}b");
|
||||
assert (r.exec("aaaaaaaab") == "aaaaaaaab,aa,a");
|
||||
|
||||
// Test non-greedy iterations
|
||||
r = new RegExp ("(a)+?");
|
||||
assert (r.exec("aaaa") == "a,a");
|
||||
|
||||
r = new RegExp ("(a)*?aa");
|
||||
assert (r.exec("aaaa") == "aa,");
|
||||
|
||||
r = new RegExp ("(aaa|aa)*?aa");
|
||||
assert (r.exec("aaaa")[0] == "aa");
|
||||
assert (r.exec("aaaa")[1] == undefined);
|
||||
|
||||
r = new RegExp ("(a)??aa");
|
||||
assert (r.exec("aaaa")[0] == "aa");
|
||||
assert (r.exec("aaaa")[1] == undefined);
|
||||
|
||||
r = new RegExp ("(a)?aa");
|
||||
assert (r.exec("aaaa") == "aaa,a");
|
||||
|
||||
r = new RegExp ("(()*?)*?a");
|
||||
assert (r.exec("ba")[0] == "a");
|
||||
assert (r.exec("ba")[1] == undefined);
|
||||
assert (r.exec("ba")[2] == undefined);
|
||||
|
||||
r = new RegExp ("((bb?)*)*a");
|
||||
assert (r.exec("bbba") == "bbba,bbb,b");
|
||||
|
||||
r = new RegExp ("((bb?)*)*bbb\\Ba");
|
||||
assert (r.exec("bbba")[0] == "bbba");
|
||||
assert (r.exec("bbba")[1] == undefined);
|
||||
assert (r.exec("bbba")[2] == undefined);
|
||||
|
||||
r = new RegExp ("(a??){0,1}a");
|
||||
assert (r.exec("aa") == "aa,a");
|
||||
|
||||
r = new RegExp ("(a?){0,1}a");
|
||||
assert (r.exec("aa") == "aa,a");
|
||||
|
||||
r = new RegExp ("(a{0,1}?){0,1}a");
|
||||
assert (r.exec("aa") == "aa,a");
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
// Copyright 2015 University of Szeged.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var r;
|
||||
|
||||
r = new RegExp ("[abc]*").exec("aaabbcccabcacbacabacbacab");
|
||||
assert (r == "aaabbcccabcacbacabacbacab");
|
||||
|
||||
r = new RegExp ("[abc]*").exec("aaabbcccabdcacb");
|
||||
assert (r == "aaabbcccab");
|
||||
|
||||
r = new RegExp ("[abc]*").exec("defghjklmnopqrstuvwxyz");
|
||||
assert (r == "");
|
||||
|
||||
r = new RegExp ("[a-z]*").exec("abcdefghjklmnopqrstuvwxyz");
|
||||
assert (r == "abcdefghjklmnopqrstuvwxyz");
|
||||
|
||||
r = new RegExp ("[A-Z]*").exec("abcdefghjklmnopqrstuvwxyz");
|
||||
assert (r == "");
|
||||
|
||||
// FIXME: Add more tescase when Unicode support is finished!
|
||||
@@ -0,0 +1,88 @@
|
||||
// Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
// Copyright 2015 University of Szeged.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var r;
|
||||
|
||||
r = new RegExp ();
|
||||
assert (r.source == "(?:)");
|
||||
assert (r.global == false);
|
||||
assert (r.ignoreCase == false);
|
||||
assert (r.multiline == false);
|
||||
|
||||
r = new RegExp ("a");
|
||||
assert (r.source == "a");
|
||||
assert (r.global == false);
|
||||
assert (r.ignoreCase == false);
|
||||
assert (r.multiline == false);
|
||||
|
||||
r = new RegExp ("a","gim");
|
||||
assert (r.source == "a");
|
||||
assert (r.global == true);
|
||||
assert (r.ignoreCase == true);
|
||||
assert (r.multiline == true);
|
||||
|
||||
r = RegExp ("a");
|
||||
assert (r.source == "a");
|
||||
assert (r.global == false);
|
||||
assert (r.ignoreCase == false);
|
||||
assert (r.multiline == false);
|
||||
|
||||
r = RegExp ("a","gim");
|
||||
assert (r.source == "a");
|
||||
assert (r.global == true);
|
||||
assert (r.ignoreCase == true);
|
||||
assert (r.multiline == true);
|
||||
|
||||
var r2;
|
||||
try {
|
||||
r2 = RegExp (r,"gim");
|
||||
assert(false);
|
||||
}
|
||||
catch ( e )
|
||||
{
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
r2 = RegExp (r);
|
||||
assert (r2.source == "a");
|
||||
assert (r2.global == true);
|
||||
assert (r2.ignoreCase == true);
|
||||
assert (r2.multiline == true);
|
||||
|
||||
r2 = RegExp (r, undefined);
|
||||
assert (r2.source == "a");
|
||||
assert (r2.global == true);
|
||||
assert (r2.ignoreCase == true);
|
||||
assert (r2.multiline == true);
|
||||
|
||||
r = /(?:)/;
|
||||
assert (r.source == "(?:)");
|
||||
assert (r.global == false);
|
||||
assert (r.ignoreCase == false);
|
||||
assert (r.multiline == false);
|
||||
|
||||
r = /a/;
|
||||
assert (r.source == "a");
|
||||
assert (r.global == false);
|
||||
assert (r.ignoreCase == false);
|
||||
assert (r.multiline == false);
|
||||
|
||||
r = /a/gim;
|
||||
assert (r.source == "a");
|
||||
assert (r.global == true);
|
||||
assert (r.ignoreCase == true);
|
||||
assert (r.multiline == true);
|
||||
|
||||
assert(Object.prototype.toString.call(RegExp.prototype) === '[object RegExp]');
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
// Copyright 2015 University of Szeged.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var t;
|
||||
|
||||
t = /\//.exec("/");
|
||||
assert (t == "/");
|
||||
|
||||
t = /[/]/.exec("/");
|
||||
assert ("a"+/x/+"b" == "a/x/b");
|
||||
|
||||
t = /\/\[[\]/]/.exec("/[/");
|
||||
assert (t == "/[/");
|
||||
@@ -0,0 +1,197 @@
|
||||
// Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
// Copyright 2015 University of Szeged.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var r;
|
||||
|
||||
// Simple test cases
|
||||
r = new RegExp ("(?:)");
|
||||
assert (r.exec ("a") == "");
|
||||
|
||||
r = new RegExp ("(?:a)");
|
||||
assert (r.exec ("a") == "a");
|
||||
|
||||
r = new RegExp ("(?:(?:a)b)c");
|
||||
assert (r.exec ("abc") == "abc");
|
||||
|
||||
r = new RegExp ("(?:a)*");
|
||||
assert (r.exec ("b") == "");
|
||||
assert (r.exec ("aaaa") == "aaaa");
|
||||
|
||||
r = new RegExp ("(?:a)+");
|
||||
assert (r.exec ("aaaa") == "aaaa");
|
||||
|
||||
r = new RegExp ("(?:a){4}");
|
||||
assert (r.exec ("aaaa") == "aaaa");
|
||||
|
||||
r = new RegExp ("(?:a){1,2}");
|
||||
assert (r.exec ("a") == "a");
|
||||
assert (r.exec ("aa") == "aa");
|
||||
assert (r.exec ("aaaa") == "aa");
|
||||
|
||||
r = new RegExp ("(?:a)?");
|
||||
assert (r.exec ("a") == "a");
|
||||
assert (r.exec ("b") == "");
|
||||
|
||||
// Test greedy iterations
|
||||
r = new RegExp ("(?:a){1,3}a");
|
||||
assert (r.exec ("aa") == "aa");
|
||||
|
||||
r = new RegExp ("(?:a){1,3}a");
|
||||
assert (r.exec ("aaa") == "aaa");
|
||||
|
||||
r = new RegExp ("(?:a){1,3}");
|
||||
assert (r.exec ("a") == "a");
|
||||
|
||||
r = new RegExp ("(?:a){1,3}");
|
||||
assert (r.exec ("aaa") == "aaa");
|
||||
|
||||
r = new RegExp ("(?:a){1,3}");
|
||||
assert (r.exec ("aaaa") == "aaa");
|
||||
|
||||
r = new RegExp ("(?:a){1,5}");
|
||||
assert (r.exec ("aaaa") == "aaaa");
|
||||
|
||||
r = new RegExp ("(?:a|b){1,2}");
|
||||
assert (r.exec ("a") == "a");
|
||||
|
||||
r = new RegExp ("(?:a|b){1,3}a");
|
||||
assert (r.exec ("aaa") == "aaa");
|
||||
|
||||
r = new RegExp ("(?:a|b){1,3}a");
|
||||
assert (r.exec ("aba") == "aba");
|
||||
|
||||
r = new RegExp ("(?:a|b){1,3}a");
|
||||
assert (r.exec ("b") == undefined);
|
||||
|
||||
r = new RegExp ("(?:a|b){1,3}a");
|
||||
assert (r.exec ("bbb") == undefined);
|
||||
|
||||
r = new RegExp ("(?:a|b){1,3}");
|
||||
assert (r.exec ("a") == "a");
|
||||
|
||||
r = new RegExp ("(?:a|b){1,3}");
|
||||
assert (r.exec ("aa") == "aa");
|
||||
|
||||
r = new RegExp ("(?:a|b){1,3}");
|
||||
assert (r.exec ("aaa") == "aaa");
|
||||
|
||||
r = new RegExp ("(?:a|b){1,3}");
|
||||
assert (r.exec ("ab") == "ab");
|
||||
|
||||
r = new RegExp ("(?:a|b){1,3}");
|
||||
assert (r.exec ("aba") == "aba");
|
||||
|
||||
r = new RegExp ("(?:a|b){1,3}");
|
||||
assert (r.exec ("bab") == "bab");
|
||||
|
||||
r = new RegExp ("(?:a|b){1,3}");
|
||||
assert (r.exec ("bbb") == "bbb");
|
||||
|
||||
r = new RegExp ("(?:a|b){1,4}a");
|
||||
assert (r.exec ("bbb") == undefined);
|
||||
|
||||
r = new RegExp ("(?:a|b){1,4}");
|
||||
assert (r.exec ("ab") == "ab");
|
||||
|
||||
r = new RegExp ("(?:a|b){1,4}");
|
||||
assert (r.exec ("aba") == "aba");
|
||||
|
||||
r = new RegExp ("(?:a|b){1,4}");
|
||||
assert (r.exec ("bbb") == "bbb");
|
||||
|
||||
r = new RegExp ("(?:a|b){1,5}");
|
||||
assert (r.exec ("abab") == "abab");
|
||||
|
||||
r = new RegExp ("(?:aba)*");
|
||||
assert (r.exec ("aaaa") == "");
|
||||
|
||||
r = new RegExp ("(?:aba)+");
|
||||
assert (r.exec ("aaaa") == undefined);
|
||||
|
||||
r = new RegExp ("(?:a|bb|c|d)");
|
||||
assert (r.exec ("a") == "a");
|
||||
|
||||
r = new RegExp ("(?:a|b|c|d)");
|
||||
assert (r.exec ("") == undefined);
|
||||
|
||||
r = new RegExp ("(?:a|b|c|d)");
|
||||
assert (r.exec ("a") == "a");
|
||||
|
||||
r = new RegExp ("(?:a|b|c|d)");
|
||||
assert (r.exec ("b") == "b");
|
||||
|
||||
r = new RegExp ("(?:a|b|c|d)");
|
||||
assert (r.exec ("c") == "c");
|
||||
|
||||
r = new RegExp ("(?:a|b|c|d)");
|
||||
assert (r.exec ("d") == "d");
|
||||
|
||||
r = new RegExp ("(?:a|b)+");
|
||||
assert (r.exec ("aba") == "aba");
|
||||
|
||||
r = new RegExp ("(?:a|b)");
|
||||
assert (r.exec ("b") == "b");
|
||||
|
||||
r = new RegExp ("(?:a)");
|
||||
assert (r.exec ("a") == "a");
|
||||
|
||||
r = new RegExp ("(?:a)*");
|
||||
assert (r.exec ("a") == "a");
|
||||
|
||||
r = new RegExp ("(?:a)*");
|
||||
assert (r.exec ("aaaa") == "aaaa");
|
||||
|
||||
r = new RegExp ("(?:a)+");
|
||||
assert (r.exec ("aaaa") == "aaaa");
|
||||
|
||||
r = new RegExp ("(?:a)?aa");
|
||||
assert (r.exec ("aaaa") == "aaa");
|
||||
|
||||
r = new RegExp ("(?:a?){0,1}a");
|
||||
assert (r.exec ("aa") == "aa");
|
||||
|
||||
r = new RegExp ("(?:a|aa){0,3}b");
|
||||
assert (r.exec ("aaaaaab") == "aaaaaab");
|
||||
|
||||
r = new RegExp ("(?:(?:a){2,3}){4}b");
|
||||
assert (r.exec ("aaaaaaaab") == "aaaaaaaab");
|
||||
|
||||
// Test non-greedy iterations
|
||||
r = new RegExp ("(?:a)+?");
|
||||
assert (r.exec ("aaaa") == "a");
|
||||
|
||||
r = new RegExp ("(?:a)*?aa");
|
||||
assert (r.exec ("aaaa") == "aa");
|
||||
|
||||
r = new RegExp ("(?:aaa|aa)*?aa");
|
||||
assert (r.exec ("aaaa") == "aa");
|
||||
|
||||
r = new RegExp ("(?:a)??aa");
|
||||
assert (r.exec ("aaaa") == "aa");
|
||||
|
||||
r = new RegExp ("(?:(?:)*?)*?a");
|
||||
assert (r.exec ("ba") == "a");
|
||||
|
||||
r = new RegExp ("(?:(?:bb?)*)*a");
|
||||
assert (r.exec ("bbba") == "bbba");
|
||||
|
||||
r = new RegExp ("(?:(?:bb?)*)*bbb\\Ba");
|
||||
assert (r.exec ("bbba") == "bbba");
|
||||
|
||||
r = new RegExp ("(?:a??){0,1}a");
|
||||
assert (r.exec ("aa") == "aa");
|
||||
|
||||
r = new RegExp ("(?:a{0,1}?){0,1}a");
|
||||
assert (r.exec ("aa") == "aa");
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
// Copyright 2015 University of Szeged.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var r;
|
||||
|
||||
r = new RegExp ("a");
|
||||
assert (r.exec ("a") == "a");
|
||||
assert (r.exec ("b") == undefined);
|
||||
try {
|
||||
r.exec.call({}, "a");
|
||||
assert (false)
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
assert (r.test ("a") == true);
|
||||
assert (r.test ("b") == false);
|
||||
try {
|
||||
r.test.call({}, "a");
|
||||
assert (false)
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
r = new RegExp ("a", "mig");
|
||||
assert (r.toString () == "/a/gim");
|
||||
try {
|
||||
r.toString.call({}, "a");
|
||||
assert (false)
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
// Copyright 2015 University of Szeged.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var r;
|
||||
|
||||
r = new RegExp ("a");
|
||||
assert (r.exec ("a") == "a");
|
||||
assert (r.exec ("b") == undefined);
|
||||
|
||||
r = new RegExp ("abc");
|
||||
assert (r.exec ("abc") == "abc");
|
||||
|
||||
r = new RegExp ("a*");
|
||||
assert (r.exec ("aaa") == "aaa");
|
||||
assert (r.exec ("b") == "");
|
||||
|
||||
r = new RegExp ("a+");
|
||||
assert (r.exec ("aaa") == "aaa");
|
||||
assert (r.exec ("b") == undefined);
|
||||
|
||||
r = new RegExp ("ab*");
|
||||
assert (r.exec ("a") == "a");
|
||||
assert (r.exec ("ab") == "ab");
|
||||
assert (r.exec ("abbbb") == "abbbb");
|
||||
assert (r.exec ("bbb") == undefined);
|
||||
|
||||
r = new RegExp ("a?");
|
||||
assert (r.exec ("a") == "a");
|
||||
assert (r.exec ("b") == "");
|
||||
|
||||
r = new RegExp ("a{4}");
|
||||
assert (r.exec ("aaa") == undefined);
|
||||
assert (r.exec ("aaaaa") == "aaaa");
|
||||
assert (r.exec ("aaaa") == "aaaa");
|
||||
|
||||
r = new RegExp ("a{2,6}");
|
||||
assert (r.exec ("a") == undefined);
|
||||
assert (r.exec ("aa") == "aa");
|
||||
assert (r.exec ("aaaaaa") == "aaaaaa");
|
||||
assert (r.exec ("aaaaaaa") == "aaaaaa");
|
||||
|
||||
r = new RegExp (".*");
|
||||
assert (r.exec ("abcdefghijkl") == "abcdefghijkl");
|
||||
Reference in New Issue
Block a user