diff options
Diffstat (limited to 'js/src/tests/js1_2/regexp')
48 files changed, 2978 insertions, 0 deletions
diff --git a/js/src/tests/js1_2/regexp/RegExp_dollar_number.js b/js/src/tests/js1_2/regexp/RegExp_dollar_number.js new file mode 100644 index 000000000..5bc1c8e51 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_dollar_number.js @@ -0,0 +1,77 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: RegExp_dollar_number.js + Description: 'Tests RegExps $1, ..., $9 properties' + + Author: Nick Lerissa + Date: March 12, 1998 +*/ + +var SECTION = 'As described in Netscape doc "What\'s new in JavaScript 1.2"'; +var VERSION = 'no version'; +var TITLE = 'RegExp: $1, ..., $9'; +var BUGNUMBER="123802"; + +startTest(); +writeHeaderToLog('Executing script: RegExp_dollar_number.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$1 +'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); +new TestCase ( SECTION, "'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$1", + 'abcdefghi', RegExp.$1); + +// 'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$2 +new TestCase ( SECTION, "'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$2", + 'bcdefgh', RegExp.$2); + +// 'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$3 +new TestCase ( SECTION, "'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$3", + 'cdefg', RegExp.$3); + +// 'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$4 +new TestCase ( SECTION, "'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$4", + 'def', RegExp.$4); + +// 'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$5 +new TestCase ( SECTION, "'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$5", + 'e', RegExp.$5); + +// 'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$6 +new TestCase ( SECTION, "'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$6", + '', RegExp.$6); + +var a_to_z = 'abcdefghijklmnopqrstuvwxyz'; +var regexp1 = /(a)b(c)d(e)f(g)h(i)j(k)l(m)n(o)p(q)r(s)t(u)v(w)x(y)z/ + // 'abcdefghijklmnopqrstuvwxyz'.match(/(a)b(c)d(e)f(g)h(i)j(k)l(m)n(o)p(q)r(s)t(u)v(w)x(y)z/); RegExp.$1 + a_to_z.match(regexp1); + +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$1", + 'a', RegExp.$1); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$2", + 'c', RegExp.$2); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$3", + 'e', RegExp.$3); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$4", + 'g', RegExp.$4); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$5", + 'i', RegExp.$5); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$6", + 'k', RegExp.$6); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$7", + 'm', RegExp.$7); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$8", + 'o', RegExp.$8); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$9", + 'q', RegExp.$9); +/* + new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$10", + 's', RegExp.$10); +*/ +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_lastIndex.js b/js/src/tests/js1_2/regexp/RegExp_lastIndex.js new file mode 100644 index 000000000..a8ace2542 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_lastIndex.js @@ -0,0 +1,52 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: RegExp_lastIndex.js + Description: 'Tests RegExps lastIndex property' + + Author: Nick Lerissa + Date: March 17, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +var TITLE = 'RegExp: lastIndex'; +var BUGNUMBER="123802"; + +startTest(); +writeHeaderToLog('Executing script: RegExp_lastIndex.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// re=/x./g; re.lastIndex=4; re.exec('xyabcdxa'); +re=/x./g; +re.lastIndex=4; +new TestCase ( SECTION, "re=/x./g; re.lastIndex=4; re.exec('xyabcdxa')", + '["xa"]', String(re.exec('xyabcdxa'))); + +// re.lastIndex +new TestCase ( SECTION, "re.lastIndex", + 8, re.lastIndex); + +// re.exec('xyabcdef'); +new TestCase ( SECTION, "re.exec('xyabcdef')", + null, re.exec('xyabcdef')); + +// re.lastIndex +new TestCase ( SECTION, "re.lastIndex", + 0, re.lastIndex); + +// re.exec('xyabcdef'); +new TestCase ( SECTION, "re.exec('xyabcdef')", + '["xy"]', String(re.exec('xyabcdef'))); + +// re.lastIndex=30; re.exec('123xaxbxc456'); +re.lastIndex=30; +new TestCase ( SECTION, "re.lastIndex=30; re.exec('123xaxbxc456')", + null, re.exec('123xaxbxc456')); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_lastMatch.js b/js/src/tests/js1_2/regexp/RegExp_lastMatch.js new file mode 100644 index 000000000..a525d1cbe --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_lastMatch.js @@ -0,0 +1,54 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: RegExp_lastMatch.js + Description: 'Tests RegExps lastMatch property' + + Author: Nick Lerissa + Date: March 12, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: lastMatch'; + +writeHeaderToLog('Executing script: RegExp_lastMatch.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'foo'.match(/foo/); RegExp.lastMatch +'foo'.match(/foo/); +new TestCase ( SECTION, "'foo'.match(/foo/); RegExp.lastMatch", + 'foo', RegExp.lastMatch); + +// 'foo'.match(new RegExp('foo')); RegExp.lastMatch +'foo'.match(new RegExp('foo')); +new TestCase ( SECTION, "'foo'.match(new RegExp('foo')); RegExp.lastMatch", + 'foo', RegExp.lastMatch); + +// 'xxx'.match(/bar/); RegExp.lastMatch +'xxx'.match(/bar/); +new TestCase ( SECTION, "'xxx'.match(/bar/); RegExp.lastMatch", + 'foo', RegExp.lastMatch); + +// 'xxx'.match(/$/); RegExp.lastMatch +'xxx'.match(/$/); +new TestCase ( SECTION, "'xxx'.match(/$/); RegExp.lastMatch", + '', RegExp.lastMatch); + +// 'abcdefg'.match(/^..(cd)[a-z]+/); RegExp.lastMatch +'abcdefg'.match(/^..(cd)[a-z]+/); +new TestCase ( SECTION, "'abcdefg'.match(/^..(cd)[a-z]+/); RegExp.lastMatch", + 'abcdefg', RegExp.lastMatch); + +// 'abcdefgabcdefg'.match(/(a(b(c(d)e)f)g)\1/); RegExp.lastMatch +'abcdefgabcdefg'.match(/(a(b(c(d)e)f)g)\1/); +new TestCase ( SECTION, "'abcdefgabcdefg'.match(/(a(b(c(d)e)f)g)\\1/); RegExp.lastMatch", + 'abcdefgabcdefg', RegExp.lastMatch); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_lastMatch_as_array.js b/js/src/tests/js1_2/regexp/RegExp_lastMatch_as_array.js new file mode 100644 index 000000000..48405ae6f --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_lastMatch_as_array.js @@ -0,0 +1,54 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: RegExp_lastMatch_as_array.js + Description: 'Tests RegExps $& property (same tests as RegExp_lastMatch.js but using $&)' + + Author: Nick Lerissa + Date: March 13, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: $&'; + +writeHeaderToLog('Executing script: RegExp_lastMatch_as_array.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'foo'.match(/foo/); RegExp['$&'] +'foo'.match(/foo/); +new TestCase ( SECTION, "'foo'.match(/foo/); RegExp['$&']", + 'foo', RegExp['$&']); + +// 'foo'.match(new RegExp('foo')); RegExp['$&'] +'foo'.match(new RegExp('foo')); +new TestCase ( SECTION, "'foo'.match(new RegExp('foo')); RegExp['$&']", + 'foo', RegExp['$&']); + +// 'xxx'.match(/bar/); RegExp['$&'] +'xxx'.match(/bar/); +new TestCase ( SECTION, "'xxx'.match(/bar/); RegExp['$&']", + 'foo', RegExp['$&']); + +// 'xxx'.match(/$/); RegExp['$&'] +'xxx'.match(/$/); +new TestCase ( SECTION, "'xxx'.match(/$/); RegExp['$&']", + '', RegExp['$&']); + +// 'abcdefg'.match(/^..(cd)[a-z]+/); RegExp['$&'] +'abcdefg'.match(/^..(cd)[a-z]+/); +new TestCase ( SECTION, "'abcdefg'.match(/^..(cd)[a-z]+/); RegExp['$&']", + 'abcdefg', RegExp['$&']); + +// 'abcdefgabcdefg'.match(/(a(b(c(d)e)f)g)\1/); RegExp['$&'] +'abcdefgabcdefg'.match(/(a(b(c(d)e)f)g)\1/); +new TestCase ( SECTION, "'abcdefgabcdefg'.match(/(a(b(c(d)e)f)g)\\1/); RegExp['$&']", + 'abcdefgabcdefg', RegExp['$&']); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_lastParen.js b/js/src/tests/js1_2/regexp/RegExp_lastParen.js new file mode 100644 index 000000000..81c106ab8 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_lastParen.js @@ -0,0 +1,68 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: RegExp_lastParen.js + Description: 'Tests RegExps lastParen property' + + Author: Nick Lerissa + Date: March 12, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: lastParen'; + +writeHeaderToLog('Executing script: RegExp_lastParen.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 'abcd'.match(/(abc)d/); RegExp.lastParen +'abcd'.match(/(abc)d/); +new TestCase ( SECTION, "'abcd'.match(/(abc)d/); RegExp.lastParen", + 'abc', RegExp.lastParen); + +// 'abcd'.match(new RegExp('(abc)d')); RegExp.lastParen +'abcd'.match(new RegExp('(abc)d')); +new TestCase ( SECTION, "'abcd'.match(new RegExp('(abc)d')); RegExp.lastParen", + 'abc', RegExp.lastParen); + +// 'abcd'.match(/(bcd)e/); RegExp.lastParen +'abcd'.match(/(bcd)e/); +new TestCase ( SECTION, "'abcd'.match(/(bcd)e/); RegExp.lastParen", + 'abc', RegExp.lastParen); + +// 'abcdefg'.match(/(a(b(c(d)e)f)g)/); RegExp.lastParen +'abcdefg'.match(/(a(b(c(d)e)f)g)/); +new TestCase ( SECTION, "'abcdefg'.match(/(a(b(c(d)e)f)g)/); RegExp.lastParen", + 'd', RegExp.lastParen); + +// 'abcdefg'.match(/(a(b)c)(d(e)f)/); RegExp.lastParen +'abcdefg'.match(/(a(b)c)(d(e)f)/); +new TestCase ( SECTION, "'abcdefg'.match(/(a(b)c)(d(e)f)/); RegExp.lastParen", + 'e', RegExp.lastParen); + +// 'abcdefg'.match(/(^)abc/); RegExp.lastParen +'abcdefg'.match(/(^)abc/); +new TestCase ( SECTION, "'abcdefg'.match(/(^)abc/); RegExp.lastParen", + '', RegExp.lastParen); + +// 'abcdefg'.match(/(^a)bc/); RegExp.lastParen +'abcdefg'.match(/(^a)bc/); +new TestCase ( SECTION, "'abcdefg'.match(/(^a)bc/); RegExp.lastParen", + 'a', RegExp.lastParen); + +// 'abcdefg'.match(new RegExp('(^a)bc')); RegExp.lastParen +'abcdefg'.match(new RegExp('(^a)bc')); +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('(^a)bc')); RegExp.lastParen", + 'a', RegExp.lastParen); + +// 'abcdefg'.match(/bc/); RegExp.lastParen +'abcdefg'.match(/bc/); +new TestCase ( SECTION, "'abcdefg'.match(/bc/); RegExp.lastParen", + '', RegExp.lastParen); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_lastParen_as_array.js b/js/src/tests/js1_2/regexp/RegExp_lastParen_as_array.js new file mode 100644 index 000000000..68bf35029 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_lastParen_as_array.js @@ -0,0 +1,68 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: RegExp_lastParen_as_array.js + Description: 'Tests RegExps $+ property (same tests as RegExp_lastParen.js but using $+)' + + Author: Nick Lerissa + Date: March 13, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: $+'; + +writeHeaderToLog('Executing script: RegExp_lastParen_as_array.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 'abcd'.match(/(abc)d/); RegExp['$+'] +'abcd'.match(/(abc)d/); +new TestCase ( SECTION, "'abcd'.match(/(abc)d/); RegExp['$+']", + 'abc', RegExp['$+']); + +// 'abcd'.match(/(bcd)e/); RegExp['$+'] +'abcd'.match(/(bcd)e/); +new TestCase ( SECTION, "'abcd'.match(/(bcd)e/); RegExp['$+']", + 'abc', RegExp['$+']); + +// 'abcdefg'.match(/(a(b(c(d)e)f)g)/); RegExp['$+'] +'abcdefg'.match(/(a(b(c(d)e)f)g)/); +new TestCase ( SECTION, "'abcdefg'.match(/(a(b(c(d)e)f)g)/); RegExp['$+']", + 'd', RegExp['$+']); + +// 'abcdefg'.match(new RegExp('(a(b(c(d)e)f)g)')); RegExp['$+'] +'abcdefg'.match(new RegExp('(a(b(c(d)e)f)g)')); +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('(a(b(c(d)e)f)g)')); RegExp['$+']", + 'd', RegExp['$+']); + +// 'abcdefg'.match(/(a(b)c)(d(e)f)/); RegExp['$+'] +'abcdefg'.match(/(a(b)c)(d(e)f)/); +new TestCase ( SECTION, "'abcdefg'.match(/(a(b)c)(d(e)f)/); RegExp['$+']", + 'e', RegExp['$+']); + +// 'abcdefg'.match(/(^)abc/); RegExp['$+'] +'abcdefg'.match(/(^)abc/); +new TestCase ( SECTION, "'abcdefg'.match(/(^)abc/); RegExp['$+']", + '', RegExp['$+']); + +// 'abcdefg'.match(/(^a)bc/); RegExp['$+'] +'abcdefg'.match(/(^a)bc/); +new TestCase ( SECTION, "'abcdefg'.match(/(^a)bc/); RegExp['$+']", + 'a', RegExp['$+']); + +// 'abcdefg'.match(new RegExp('(^a)bc')); RegExp['$+'] +'abcdefg'.match(new RegExp('(^a)bc')); +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('(^a)bc')); RegExp['$+']", + 'a', RegExp['$+']); + +// 'abcdefg'.match(/bc/); RegExp['$+'] +'abcdefg'.match(/bc/); +new TestCase ( SECTION, "'abcdefg'.match(/bc/); RegExp['$+']", + '', RegExp['$+']); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_leftContext.js b/js/src/tests/js1_2/regexp/RegExp_leftContext.js new file mode 100644 index 000000000..2fdb38975 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_leftContext.js @@ -0,0 +1,58 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: RegExp_leftContext.js + Description: 'Tests RegExps leftContext property' + + Author: Nick Lerissa + Date: March 12, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: leftContext'; + +writeHeaderToLog('Executing script: RegExp_leftContext.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 'abc123xyz'.match(/123/); RegExp.leftContext +'abc123xyz'.match(/123/); +new TestCase ( SECTION, "'abc123xyz'.match(/123/); RegExp.leftContext", + 'abc', RegExp.leftContext); + +// 'abc123xyz'.match(/456/); RegExp.leftContext +'abc123xyz'.match(/456/); +new TestCase ( SECTION, "'abc123xyz'.match(/456/); RegExp.leftContext", + 'abc', RegExp.leftContext); + +// 'abc123xyz'.match(/abc123xyz/); RegExp.leftContext +'abc123xyz'.match(/abc123xyz/); +new TestCase ( SECTION, "'abc123xyz'.match(/abc123xyz/); RegExp.leftContext", + '', RegExp.leftContext); + +// 'xxxx'.match(/$/); RegExp.leftContext +'xxxx'.match(/$/); +new TestCase ( SECTION, "'xxxx'.match(/$/); RegExp.leftContext", + 'xxxx', RegExp.leftContext); + +// 'test'.match(/^/); RegExp.leftContext +'test'.match(/^/); +new TestCase ( SECTION, "'test'.match(/^/); RegExp.leftContext", + '', RegExp.leftContext); + +// 'xxxx'.match(new RegExp('$')); RegExp.leftContext +'xxxx'.match(new RegExp('$')); +new TestCase ( SECTION, "'xxxx'.match(new RegExp('$')); RegExp.leftContext", + 'xxxx', RegExp.leftContext); + +// 'test'.match(new RegExp('^')); RegExp.leftContext +'test'.match(new RegExp('^')); +new TestCase ( SECTION, "'test'.match(new RegExp('^')); RegExp.leftContext", + '', RegExp.leftContext); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_leftContext_as_array.js b/js/src/tests/js1_2/regexp/RegExp_leftContext_as_array.js new file mode 100644 index 000000000..ffde0f7c3 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_leftContext_as_array.js @@ -0,0 +1,58 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: RegExp_leftContext_as_array.js + Description: 'Tests RegExps leftContext property (same tests as RegExp_leftContext.js but using $`)' + + Author: Nick Lerissa + Date: March 12, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: $`'; + +writeHeaderToLog('Executing script: RegExp_leftContext_as_array.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 'abc123xyz'.match(/123/); RegExp['$`'] +'abc123xyz'.match(/123/); +new TestCase ( SECTION, "'abc123xyz'.match(/123/); RegExp['$`']", + 'abc', RegExp['$`']); + +// 'abc123xyz'.match(/456/); RegExp['$`'] +'abc123xyz'.match(/456/); +new TestCase ( SECTION, "'abc123xyz'.match(/456/); RegExp['$`']", + 'abc', RegExp['$`']); + +// 'abc123xyz'.match(/abc123xyz/); RegExp['$`'] +'abc123xyz'.match(/abc123xyz/); +new TestCase ( SECTION, "'abc123xyz'.match(/abc123xyz/); RegExp['$`']", + '', RegExp['$`']); + +// 'xxxx'.match(/$/); RegExp['$`'] +'xxxx'.match(/$/); +new TestCase ( SECTION, "'xxxx'.match(/$/); RegExp['$`']", + 'xxxx', RegExp['$`']); + +// 'test'.match(/^/); RegExp['$`'] +'test'.match(/^/); +new TestCase ( SECTION, "'test'.match(/^/); RegExp['$`']", + '', RegExp['$`']); + +// 'xxxx'.match(new RegExp('$')); RegExp['$`'] +'xxxx'.match(new RegExp('$')); +new TestCase ( SECTION, "'xxxx'.match(new RegExp('$')); RegExp['$`']", + 'xxxx', RegExp['$`']); + +// 'test'.match(new RegExp('^')); RegExp['$`'] +'test'.match(new RegExp('^')); +new TestCase ( SECTION, "'test'.match(new RegExp('^')); RegExp['$`']", + '', RegExp['$`']); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_object.js b/js/src/tests/js1_2/regexp/RegExp_object.js new file mode 100644 index 000000000..4c39474ea --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_object.js @@ -0,0 +1,56 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: RegExp_object.js + Description: 'Tests regular expressions creating RexExp Objects' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: object'; + +writeHeaderToLog('Executing script: RegExp_object.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +var SSN_pattern = new RegExp("\\d{3}-\\d{2}-\\d{4}"); + +// testing SSN pattern +new TestCase ( SECTION, "'Test SSN is 123-34-4567'.match(SSN_pattern))", + String(["123-34-4567"]), String('Test SSN is 123-34-4567'.match(SSN_pattern))); + +// testing SSN pattern +new TestCase ( SECTION, "'Test SSN is 123-34-4567'.match(SSN_pattern))", + String(["123-34-4567"]), String('Test SSN is 123-34-4567'.match(SSN_pattern))); + +var PHONE_pattern = new RegExp("\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})"); +// testing PHONE pattern +new TestCase ( SECTION, "'Our phone number is (408)345-2345.'.match(PHONE_pattern))", + String(["(408)345-2345","408","345","2345"]), String('Our phone number is (408)345-2345.'.match(PHONE_pattern))); + +// testing PHONE pattern +new TestCase ( SECTION, "'The phone number is 408-345-2345!'.match(PHONE_pattern))", + String(["408-345-2345","408","345","2345"]), String('The phone number is 408-345-2345!'.match(PHONE_pattern))); + +// testing PHONE pattern +new TestCase ( SECTION, "String(PHONE_pattern.toString())", + "/\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})/", String(PHONE_pattern.toString())); + +// testing conversion to String +new TestCase ( SECTION, "PHONE_pattern + ' is the string'", + "/\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})/ is the string",PHONE_pattern + ' is the string'); + +// testing conversion to int +new TestCase ( SECTION, "SSN_pattern - 8", + NaN,SSN_pattern - 8); + +var testPattern = new RegExp("(\\d+)45(\\d+)90"); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_rightContext.js b/js/src/tests/js1_2/regexp/RegExp_rightContext.js new file mode 100644 index 000000000..f618cedf3 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_rightContext.js @@ -0,0 +1,58 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: RegExp_rightContext.js + Description: 'Tests RegExps rightContext property' + + Author: Nick Lerissa + Date: March 12, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: rightContext'; + +writeHeaderToLog('Executing script: RegExp_rightContext.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 'abc123xyz'.match(/123/); RegExp.rightContext +'abc123xyz'.match(/123/); +new TestCase ( SECTION, "'abc123xyz'.match(/123/); RegExp.rightContext", + 'xyz', RegExp.rightContext); + +// 'abc123xyz'.match(/456/); RegExp.rightContext +'abc123xyz'.match(/456/); +new TestCase ( SECTION, "'abc123xyz'.match(/456/); RegExp.rightContext", + 'xyz', RegExp.rightContext); + +// 'abc123xyz'.match(/abc123xyz/); RegExp.rightContext +'abc123xyz'.match(/abc123xyz/); +new TestCase ( SECTION, "'abc123xyz'.match(/abc123xyz/); RegExp.rightContext", + '', RegExp.rightContext); + +// 'xxxx'.match(/$/); RegExp.rightContext +'xxxx'.match(/$/); +new TestCase ( SECTION, "'xxxx'.match(/$/); RegExp.rightContext", + '', RegExp.rightContext); + +// 'test'.match(/^/); RegExp.rightContext +'test'.match(/^/); +new TestCase ( SECTION, "'test'.match(/^/); RegExp.rightContext", + 'test', RegExp.rightContext); + +// 'xxxx'.match(new RegExp('$')); RegExp.rightContext +'xxxx'.match(new RegExp('$')); +new TestCase ( SECTION, "'xxxx'.match(new RegExp('$')); RegExp.rightContext", + '', RegExp.rightContext); + +// 'test'.match(new RegExp('^')); RegExp.rightContext +'test'.match(new RegExp('^')); +new TestCase ( SECTION, "'test'.match(new RegExp('^')); RegExp.rightContext", + 'test', RegExp.rightContext); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_rightContext_as_array.js b/js/src/tests/js1_2/regexp/RegExp_rightContext_as_array.js new file mode 100644 index 000000000..24c4ae069 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_rightContext_as_array.js @@ -0,0 +1,58 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: RegExp_rightContext_as_array.js + Description: 'Tests RegExps $\' property (same tests as RegExp_rightContext.js but using $\)' + + Author: Nick Lerissa + Date: March 12, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: $\''; + +writeHeaderToLog('Executing script: RegExp_rightContext.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 'abc123xyz'.match(/123/); RegExp['$\''] +'abc123xyz'.match(/123/); +new TestCase ( SECTION, "'abc123xyz'.match(/123/); RegExp['$\'']", + 'xyz', RegExp['$\'']); + +// 'abc123xyz'.match(/456/); RegExp['$\''] +'abc123xyz'.match(/456/); +new TestCase ( SECTION, "'abc123xyz'.match(/456/); RegExp['$\'']", + 'xyz', RegExp['$\'']); + +// 'abc123xyz'.match(/abc123xyz/); RegExp['$\''] +'abc123xyz'.match(/abc123xyz/); +new TestCase ( SECTION, "'abc123xyz'.match(/abc123xyz/); RegExp['$\'']", + '', RegExp['$\'']); + +// 'xxxx'.match(/$/); RegExp['$\''] +'xxxx'.match(/$/); +new TestCase ( SECTION, "'xxxx'.match(/$/); RegExp['$\'']", + '', RegExp['$\'']); + +// 'test'.match(/^/); RegExp['$\''] +'test'.match(/^/); +new TestCase ( SECTION, "'test'.match(/^/); RegExp['$\'']", + 'test', RegExp['$\'']); + +// 'xxxx'.match(new RegExp('$')); RegExp['$\''] +'xxxx'.match(new RegExp('$')); +new TestCase ( SECTION, "'xxxx'.match(new RegExp('$')); RegExp['$\'']", + '', RegExp['$\'']); + +// 'test'.match(new RegExp('^')); RegExp['$\''] +'test'.match(new RegExp('^')); +new TestCase ( SECTION, "'test'.match(new RegExp('^')); RegExp['$\'']", + 'test', RegExp['$\'']); + +test(); diff --git a/js/src/tests/js1_2/regexp/alphanumeric.js b/js/src/tests/js1_2/regexp/alphanumeric.js new file mode 100644 index 000000000..1dc3fb2e3 --- /dev/null +++ b/js/src/tests/js1_2/regexp/alphanumeric.js @@ -0,0 +1,97 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: alphanumeric.js + Description: 'Tests regular expressions with \w and \W special characters' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: \\w and \\W'; + +writeHeaderToLog('Executing script: alphanumeric.js'); +writeHeaderToLog( SECTION + " " + TITLE); + +var non_alphanumeric = "~`!@#$%^&*()-+={[}]|\\:;'<,>./?\f\n\r\t\v " + '"'; +var alphanumeric = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; + +// be sure all alphanumerics are matched by \w +new TestCase ( SECTION, + "'" + alphanumeric + "'.match(new RegExp('\\w+'))", + String([alphanumeric]), String(alphanumeric.match(new RegExp('\\w+')))); + +// be sure all non-alphanumerics are matched by \W +new TestCase ( SECTION, + "'" + non_alphanumeric + "'.match(new RegExp('\\W+'))", + String([non_alphanumeric]), String(non_alphanumeric.match(new RegExp('\\W+')))); + +// be sure all non-alphanumerics are not matched by \w +new TestCase ( SECTION, + "'" + non_alphanumeric + "'.match(new RegExp('\\w'))", + null, non_alphanumeric.match(new RegExp('\\w'))); + +// be sure all alphanumerics are not matched by \W +new TestCase ( SECTION, + "'" + alphanumeric + "'.match(new RegExp('\\W'))", + null, alphanumeric.match(new RegExp('\\W'))); + +var s = non_alphanumeric + alphanumeric; + +// be sure all alphanumerics are matched by \w +new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\w+'))", + String([alphanumeric]), String(s.match(new RegExp('\\w+')))); + +s = alphanumeric + non_alphanumeric; + +// be sure all non-alphanumerics are matched by \W +new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\W+'))", + String([non_alphanumeric]), String(s.match(new RegExp('\\W+')))); + +// be sure all alphanumerics are matched by \w (using literals) +new TestCase ( SECTION, + "'" + s + "'.match(/\w+/)", + String([alphanumeric]), String(s.match(/\w+/))); + +s = alphanumeric + non_alphanumeric; + +// be sure all non-alphanumerics are matched by \W (using literals) +new TestCase ( SECTION, + "'" + s + "'.match(/\W+/)", + String([non_alphanumeric]), String(s.match(/\W+/))); + +s = 'abcd*&^%$$'; +// be sure the following test behaves consistently +new TestCase ( SECTION, + "'" + s + "'.match(/(\w+)...(\W+)/)", + String([s , 'abcd' , '%$$']), String(s.match(/(\w+)...(\W+)/))); + +var i; + +// be sure all alphanumeric characters match individually +for (i = 0; i < alphanumeric.length; ++i) +{ + s = '#$' + alphanumeric[i] + '%^'; + new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\w'))", + String([alphanumeric[i]]), String(s.match(new RegExp('\\w')))); +} +// be sure all non_alphanumeric characters match individually +for (i = 0; i < non_alphanumeric.length; ++i) +{ + s = 'sd' + non_alphanumeric[i] + String((i+10) * (i+10) - 2 * (i+10)); + new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\W'))", + String([non_alphanumeric[i]]), String(s.match(new RegExp('\\W')))); +} + +test(); diff --git a/js/src/tests/js1_2/regexp/asterisk.js b/js/src/tests/js1_2/regexp/asterisk.js new file mode 100644 index 000000000..373c9554e --- /dev/null +++ b/js/src/tests/js1_2/regexp/asterisk.js @@ -0,0 +1,73 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: asterisk.js + Description: 'Tests regular expressions containing *' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: *'; + +writeHeaderToLog('Executing script: aterisk.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 'abcddddefg'.match(new RegExp('d*')) +new TestCase ( SECTION, "'abcddddefg'.match(new RegExp('d*'))", + String([""]), String('abcddddefg'.match(new RegExp('d*')))); + +// 'abcddddefg'.match(new RegExp('cd*')) +new TestCase ( SECTION, "'abcddddefg'.match(new RegExp('cd*'))", + String(["cdddd"]), String('abcddddefg'.match(new RegExp('cd*')))); + +// 'abcdefg'.match(new RegExp('cx*d')) +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('cx*d'))", + String(["cd"]), String('abcdefg'.match(new RegExp('cx*d')))); + +// 'xxxxxxx'.match(new RegExp('(x*)(x+)')) +new TestCase ( SECTION, "'xxxxxxx'.match(new RegExp('(x*)(x+)'))", + String(["xxxxxxx","xxxxxx","x"]), String('xxxxxxx'.match(new RegExp('(x*)(x+)')))); + +// '1234567890'.match(new RegExp('(\\d*)(\\d+)')) +new TestCase ( SECTION, "'1234567890'.match(new RegExp('(\\d*)(\\d+)'))", + String(["1234567890","123456789","0"]), + String('1234567890'.match(new RegExp('(\\d*)(\\d+)')))); + +// '1234567890'.match(new RegExp('(\\d*)\\d(\\d+)')) +new TestCase ( SECTION, "'1234567890'.match(new RegExp('(\\d*)\\d(\\d+)'))", + String(["1234567890","12345678","0"]), + String('1234567890'.match(new RegExp('(\\d*)\\d(\\d+)')))); + +// 'xxxxxxx'.match(new RegExp('(x+)(x*)')) +new TestCase ( SECTION, "'xxxxxxx'.match(new RegExp('(x+)(x*)'))", + String(["xxxxxxx","xxxxxxx",""]), String('xxxxxxx'.match(new RegExp('(x+)(x*)')))); + +// 'xxxxxxyyyyyy'.match(new RegExp('x*y+$')) +new TestCase ( SECTION, "'xxxxxxyyyyyy'.match(new RegExp('x*y+$'))", + String(["xxxxxxyyyyyy"]), String('xxxxxxyyyyyy'.match(new RegExp('x*y+$')))); + +// 'abcdef'.match(/[\d]*[\s]*bc./) +new TestCase ( SECTION, "'abcdef'.match(/[\\d]*[\\s]*bc./)", + String(["bcd"]), String('abcdef'.match(/[\d]*[\s]*bc./))); + +// 'abcdef'.match(/bc..[\d]*[\s]*/) +new TestCase ( SECTION, "'abcdef'.match(/bc..[\\d]*[\\s]*/)", + String(["bcde"]), String('abcdef'.match(/bc..[\d]*[\s]*/))); + +// 'a1b2c3'.match(/.*/) +new TestCase ( SECTION, "'a1b2c3'.match(/.*/)", + String(["a1b2c3"]), String('a1b2c3'.match(/.*/))); + +// 'a0.b2.c3'.match(/[xyz]*1/) +new TestCase ( SECTION, "'a0.b2.c3'.match(/[xyz]*1/)", + null, 'a0.b2.c3'.match(/[xyz]*1/)); + +test(); diff --git a/js/src/tests/js1_2/regexp/backslash.js b/js/src/tests/js1_2/regexp/backslash.js new file mode 100644 index 000000000..6ad35809e --- /dev/null +++ b/js/src/tests/js1_2/regexp/backslash.js @@ -0,0 +1,47 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: backslash.js + Description: 'Tests regular expressions containing \' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: \\'; + +writeHeaderToLog('Executing script: backslash.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 'abcde'.match(new RegExp('\e')) +new TestCase ( SECTION, "'abcde'.match(new RegExp('\e'))", + String(["e"]), String('abcde'.match(new RegExp('\e')))); + +// 'ab\\cde'.match(new RegExp('\\\\')) +new TestCase ( SECTION, "'ab\\cde'.match(new RegExp('\\\\'))", + String(["\\"]), String('ab\\cde'.match(new RegExp('\\\\')))); + +// 'ab\\cde'.match(/\\/) (using literal) +new TestCase ( SECTION, "'ab\\cde'.match(/\\\\/)", + String(["\\"]), String('ab\\cde'.match(/\\/))); + +// 'before ^$*+?.()|{}[] after'.match(new RegExp('\^\$\*\+\?\.\(\)\|\{\}\[\]')) +new TestCase ( SECTION, + "'before ^$*+?.()|{}[] after'.match(new RegExp('\\^\\$\\*\\+\\?\\.\\(\\)\\|\\{\\}\\[\\]'))", + String(["^$*+?.()|{}[]"]), + String('before ^$*+?.()|{}[] after'.match(new RegExp('\\^\\$\\*\\+\\?\\.\\(\\)\\|\\{\\}\\[\\]')))); + +// 'before ^$*+?.()|{}[] after'.match(/\^\$\*\+\?\.\(\)\|\{\}\[\]/) (using literal) +new TestCase ( SECTION, + "'before ^$*+?.()|{}[] after'.match(/\\^\\$\\*\\+\\?\\.\\(\\)\\|\\{\\}\\[\\]/)", + String(["^$*+?.()|{}[]"]), + String('before ^$*+?.()|{}[] after'.match(/\^\$\*\+\?\.\(\)\|\{\}\[\]/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/backspace.js b/js/src/tests/js1_2/regexp/backspace.js new file mode 100644 index 000000000..3e7a0003a --- /dev/null +++ b/js/src/tests/js1_2/regexp/backspace.js @@ -0,0 +1,47 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: backspace.js + Description: 'Tests regular expressions containing [\b]' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: [\b]'; + +writeHeaderToLog('Executing script: backspace.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 'abc\bdef'.match(new RegExp('.[\b].')) +new TestCase ( SECTION, "'abc\bdef'.match(new RegExp('.[\\b].'))", + String(["c\bd"]), String('abc\bdef'.match(new RegExp('.[\\b].')))); + +// 'abc\\bdef'.match(new RegExp('.[\b].')) +new TestCase ( SECTION, "'abc\\bdef'.match(new RegExp('.[\\b].'))", + null, 'abc\\bdef'.match(new RegExp('.[\\b].'))); + +// 'abc\b\b\bdef'.match(new RegExp('c[\b]{3}d')) +new TestCase ( SECTION, "'abc\b\b\bdef'.match(new RegExp('c[\\b]{3}d'))", + String(["c\b\b\bd"]), String('abc\b\b\bdef'.match(new RegExp('c[\\b]{3}d')))); + +// 'abc\bdef'.match(new RegExp('[^\\[\b\\]]+')) +new TestCase ( SECTION, "'abc\bdef'.match(new RegExp('[^\\[\\b\\]]+'))", + String(["abc"]), String('abc\bdef'.match(new RegExp('[^\\[\\b\\]]+')))); + +// 'abcdef'.match(new RegExp('[^\\[\b\\]]+')) +new TestCase ( SECTION, "'abcdef'.match(new RegExp('[^\\[\\b\\]]+'))", + String(["abcdef"]), String('abcdef'.match(new RegExp('[^\\[\\b\\]]+')))); + +// 'abcdef'.match(/[^\[\b\]]+/) +new TestCase ( SECTION, "'abcdef'.match(/[^\\[\\b\\]]+/)", + String(["abcdef"]), String('abcdef'.match(/[^\[\b\]]+/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/beginLine.js b/js/src/tests/js1_2/regexp/beginLine.js new file mode 100644 index 000000000..464f12e8b --- /dev/null +++ b/js/src/tests/js1_2/regexp/beginLine.js @@ -0,0 +1,44 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: beginLine.js + Description: 'Tests regular expressions containing ^' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: ^'; + +writeHeaderToLog('Executing script: beginLine.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'abcde'.match(new RegExp('^ab')) +new TestCase ( SECTION, "'abcde'.match(new RegExp('^ab'))", + String(["ab"]), String('abcde'.match(new RegExp('^ab')))); + +// 'ab\ncde'.match(new RegExp('^..^e')) +new TestCase ( SECTION, "'ab\ncde'.match(new RegExp('^..^e'))", + null, 'ab\ncde'.match(new RegExp('^..^e'))); + +// 'yyyyy'.match(new RegExp('^xxx')) +new TestCase ( SECTION, "'yyyyy'.match(new RegExp('^xxx'))", + null, 'yyyyy'.match(new RegExp('^xxx'))); + +// '^^^x'.match(new RegExp('^\\^+')) +new TestCase ( SECTION, "'^^^x'.match(new RegExp('^\\^+'))", + String(['^^^']), String('^^^x'.match(new RegExp('^\\^+')))); + +// '^^^x'.match(/^\^+/) +new TestCase ( SECTION, "'^^^x'.match(/^\\^+/)", + String(['^^^']), String('^^^x'.match(/^\^+/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/browser.js b/js/src/tests/js1_2/regexp/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/regexp/browser.js diff --git a/js/src/tests/js1_2/regexp/character_class.js b/js/src/tests/js1_2/regexp/character_class.js new file mode 100644 index 000000000..800de9a09 --- /dev/null +++ b/js/src/tests/js1_2/regexp/character_class.js @@ -0,0 +1,76 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: character_class.js + Description: 'Tests regular expressions containing []' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: []'; + +writeHeaderToLog('Executing script: character_class.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'abcde'.match(new RegExp('ab[ercst]de')) +new TestCase ( SECTION, "'abcde'.match(new RegExp('ab[ercst]de'))", + String(["abcde"]), String('abcde'.match(new RegExp('ab[ercst]de')))); + +// 'abcde'.match(new RegExp('ab[erst]de')) +new TestCase ( SECTION, "'abcde'.match(new RegExp('ab[erst]de'))", + null, 'abcde'.match(new RegExp('ab[erst]de'))); + +// 'abcdefghijkl'.match(new RegExp('[d-h]+')) +new TestCase ( SECTION, "'abcdefghijkl'.match(new RegExp('[d-h]+'))", + String(["defgh"]), String('abcdefghijkl'.match(new RegExp('[d-h]+')))); + +// 'abc6defghijkl'.match(new RegExp('[1234567].{2}')) +new TestCase ( SECTION, "'abc6defghijkl'.match(new RegExp('[1234567].{2}'))", + String(["6de"]), String('abc6defghijkl'.match(new RegExp('[1234567].{2}')))); + +// '\n\n\abc324234\n'.match(new RegExp('[a-c\d]+')) +new TestCase ( SECTION, "'\n\n\abc324234\n'.match(new RegExp('[a-c\\d]+'))", + String(["abc324234"]), String('\n\n\abc324234\n'.match(new RegExp('[a-c\\d]+')))); + +// 'abc'.match(new RegExp('ab[.]?c')) +new TestCase ( SECTION, "'abc'.match(new RegExp('ab[.]?c'))", + String(["abc"]), String('abc'.match(new RegExp('ab[.]?c')))); + +// 'abc'.match(new RegExp('a[b]c')) +new TestCase ( SECTION, "'abc'.match(new RegExp('a[b]c'))", + String(["abc"]), String('abc'.match(new RegExp('a[b]c')))); + +// 'a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]')) +new TestCase ( SECTION, "'a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]'))", + String(["def"]), String('a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]')))); + +// '123*&$abc'.match(new RegExp('[*&$]{3}')) +new TestCase ( SECTION, "'123*&$abc'.match(new RegExp('[*&$]{3}'))", + String(["*&$"]), String('123*&$abc'.match(new RegExp('[*&$]{3}')))); + +// 'abc'.match(new RegExp('a[^1-9]c')) +new TestCase ( SECTION, "'abc'.match(new RegExp('a[^1-9]c'))", + String(["abc"]), String('abc'.match(new RegExp('a[^1-9]c')))); + +// 'abc'.match(new RegExp('a[^b]c')) +new TestCase ( SECTION, "'abc'.match(new RegExp('a[^b]c'))", + null, 'abc'.match(new RegExp('a[^b]c'))); + +// 'abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}')) +new TestCase ( SECTION, "'abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}'))", + String(["%&*@"]), String('abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}')))); + +// 'abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/) +new TestCase ( SECTION, "'abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/)", + String(["%&*@"]), String('abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/compile.js b/js/src/tests/js1_2/regexp/compile.js new file mode 100644 index 000000000..c1d4acc81 --- /dev/null +++ b/js/src/tests/js1_2/regexp/compile.js @@ -0,0 +1,62 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: compile.js + Description: 'Tests regular expressions method compile' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: compile'; + +writeHeaderToLog('Executing script: compile.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +var regularExpression = new RegExp(); + +regularExpression.compile("[0-9]{3}x[0-9]{4}","i"); + +new TestCase ( SECTION, + "(compile '[0-9]{3}x[0-9]{4}','i')", + String(["456X7890"]), String('234X456X7890'.match(regularExpression))); + +new TestCase ( SECTION, + "source of (compile '[0-9]{3}x[0-9]{4}','i')", + "[0-9]{3}x[0-9]{4}", regularExpression.source); + +new TestCase ( SECTION, + "global of (compile '[0-9]{3}x[0-9]{4}','i')", + false, regularExpression.global); + +new TestCase ( SECTION, + "ignoreCase of (compile '[0-9]{3}x[0-9]{4}','i')", + true, regularExpression.ignoreCase); + +regularExpression.compile("[0-9]{3}X[0-9]{3}","g"); + +new TestCase ( SECTION, + "(compile '[0-9]{3}X[0-9]{3}','g')", + String(["234X456"]), String('234X456X7890'.match(regularExpression))); + +new TestCase ( SECTION, + "source of (compile '[0-9]{3}X[0-9]{3}','g')", + "[0-9]{3}X[0-9]{3}", regularExpression.source); + +new TestCase ( SECTION, + "global of (compile '[0-9]{3}X[0-9]{3}','g')", + true, regularExpression.global); + +new TestCase ( SECTION, + "ignoreCase of (compile '[0-9]{3}X[0-9]{3}','g')", + false, regularExpression.ignoreCase); + + +test(); diff --git a/js/src/tests/js1_2/regexp/control_characters.js b/js/src/tests/js1_2/regexp/control_characters.js new file mode 100644 index 000000000..82857e6f7 --- /dev/null +++ b/js/src/tests/js1_2/regexp/control_characters.js @@ -0,0 +1,40 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: control_characters.js + Description: 'Tests regular expressions containing .' + + Author: Nick Lerissa + Date: April 8, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +var TITLE = 'RegExp: .'; +var BUGNUMBER="123802"; + +startTest(); +writeHeaderToLog('Executing script: control_characters.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'àOÐ ê:i¢Ø'.match(new RegExp('.+')) +new TestCase ( SECTION, "'àOÐ ê:i¢Ø'.match(new RegExp('.+'))", + String(['àOÐ ê:i¢Ø']), String('àOÐ ê:i¢Ø'.match(new RegExp('.+')))); + +// string1.match(new RegExp(string1)) +var string1 = 'àOÐ ê:i¢Ø'; +new TestCase ( SECTION, "string1 = " + string1 + " string1.match(string1)", + String([string1]), String(string1.match(string1))); + +string1 = ""; +for (var i = 0; i < 32; i++) + string1 += String.fromCharCode(i); +new TestCase ( SECTION, "string1 = " + string1 + " string1.match(string1)", + String([string1]), String(string1.match(string1))); + +test(); diff --git a/js/src/tests/js1_2/regexp/digit.js b/js/src/tests/js1_2/regexp/digit.js new file mode 100644 index 000000000..ce3c6554d --- /dev/null +++ b/js/src/tests/js1_2/regexp/digit.js @@ -0,0 +1,86 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: digit.js + Description: 'Tests regular expressions containing \d' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: \\d'; + +writeHeaderToLog('Executing script: digit.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +var non_digits = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\f\n\r\t\v~`!@#$%^&*()-+={[}]|\\:;'<,>./? " + '"'; + +var digits = "1234567890"; + +// be sure all digits are matched by \d +new TestCase ( SECTION, + "'" + digits + "'.match(new RegExp('\\d+'))", + String([digits]), String(digits.match(new RegExp('\\d+')))); + +// be sure all non-digits are matched by \D +new TestCase ( SECTION, + "'" + non_digits + "'.match(new RegExp('\\D+'))", + String([non_digits]), String(non_digits.match(new RegExp('\\D+')))); + +// be sure all non-digits are not matched by \d +new TestCase ( SECTION, + "'" + non_digits + "'.match(new RegExp('\\d'))", + null, non_digits.match(new RegExp('\\d'))); + +// be sure all digits are not matched by \D +new TestCase ( SECTION, + "'" + digits + "'.match(new RegExp('\\D'))", + null, digits.match(new RegExp('\\D'))); + +var s = non_digits + digits; + +// be sure all digits are matched by \d +new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\d+'))", + String([digits]), String(s.match(new RegExp('\\d+')))); + +var s = digits + non_digits; + +// be sure all non-digits are matched by \D +new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\D+'))", + String([non_digits]), String(s.match(new RegExp('\\D+')))); + +var i; + +// be sure all digits match individually +for (i = 0; i < digits.length; ++i) +{ + s = 'ab' + digits[i] + 'cd'; + new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\d'))", + String([digits[i]]), String(s.match(new RegExp('\\d')))); + new TestCase ( SECTION, + "'" + s + "'.match(/\\d/)", + String([digits[i]]), String(s.match(/\d/))); +} +// be sure all non_digits match individually +for (i = 0; i < non_digits.length; ++i) +{ + s = '12' + non_digits[i] + '34'; + new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\D'))", + String([non_digits[i]]), String(s.match(new RegExp('\\D')))); + new TestCase ( SECTION, + "'" + s + "'.match(/\\D/)", + String([non_digits[i]]), String(s.match(/\D/))); +} + +test(); diff --git a/js/src/tests/js1_2/regexp/dot.js b/js/src/tests/js1_2/regexp/dot.js new file mode 100644 index 000000000..9bcb9dfc4 --- /dev/null +++ b/js/src/tests/js1_2/regexp/dot.js @@ -0,0 +1,64 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: dot.js + Description: 'Tests regular expressions containing .' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: .'; + +writeHeaderToLog('Executing script: dot.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'abcde'.match(new RegExp('ab.de')) +new TestCase ( SECTION, "'abcde'.match(new RegExp('ab.de'))", + String(["abcde"]), String('abcde'.match(new RegExp('ab.de')))); + +// 'line 1\nline 2'.match(new RegExp('.+')) +new TestCase ( SECTION, "'line 1\nline 2'.match(new RegExp('.+'))", + String(["line 1"]), String('line 1\nline 2'.match(new RegExp('.+')))); + +// 'this is a test'.match(new RegExp('.*a.*')) +new TestCase ( SECTION, "'this is a test'.match(new RegExp('.*a.*'))", + String(["this is a test"]), String('this is a test'.match(new RegExp('.*a.*')))); + +// 'this is a *&^%$# test'.match(new RegExp('.+')) +new TestCase ( SECTION, "'this is a *&^%$# test'.match(new RegExp('.+'))", + String(["this is a *&^%$# test"]), String('this is a *&^%$# test'.match(new RegExp('.+')))); + +// '....'.match(new RegExp('.+')) +new TestCase ( SECTION, "'....'.match(new RegExp('.+'))", + String(["...."]), String('....'.match(new RegExp('.+')))); + +// 'abcdefghijklmnopqrstuvwxyz'.match(new RegExp('.+')) +new TestCase ( SECTION, "'abcdefghijklmnopqrstuvwxyz'.match(new RegExp('.+'))", + String(["abcdefghijklmnopqrstuvwxyz"]), String('abcdefghijklmnopqrstuvwxyz'.match(new RegExp('.+')))); + +// 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.match(new RegExp('.+')) +new TestCase ( SECTION, "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.match(new RegExp('.+'))", + String(["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]), String('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.match(new RegExp('.+')))); + +// '`1234567890-=~!@#$%^&*()_+'.match(new RegExp('.+')) +new TestCase ( SECTION, "'`1234567890-=~!@#$%^&*()_+'.match(new RegExp('.+'))", + String(["`1234567890-=~!@#$%^&*()_+"]), String('`1234567890-=~!@#$%^&*()_+'.match(new RegExp('.+')))); + +// '|\\[{]};:"\',<>.?/'.match(new RegExp('.+')) +new TestCase ( SECTION, "'|\\[{]};:\"\',<>.?/'.match(new RegExp('.+'))", + String(["|\\[{]};:\"\',<>.?/"]), String('|\\[{]};:\"\',<>.?/'.match(new RegExp('.+')))); + +// '|\\[{]};:"\',<>.?/'.match(/.+/) +new TestCase ( SECTION, "'|\\[{]};:\"\',<>.?/'.match(/.+/)", + String(["|\\[{]};:\"\',<>.?/"]), String('|\\[{]};:\"\',<>.?/'.match(/.+/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/endLine.js b/js/src/tests/js1_2/regexp/endLine.js new file mode 100644 index 000000000..2edbccccb --- /dev/null +++ b/js/src/tests/js1_2/regexp/endLine.js @@ -0,0 +1,44 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: endLine.js + Description: 'Tests regular expressions containing $' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: $'; + +writeHeaderToLog('Executing script: endLine.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'abcde'.match(new RegExp('de$')) +new TestCase ( SECTION, "'abcde'.match(new RegExp('de$'))", + String(["de"]), String('abcde'.match(new RegExp('de$')))); + +// 'ab\ncde'.match(new RegExp('..$e$')) +new TestCase ( SECTION, "'ab\ncde'.match(new RegExp('..$e$'))", + null, 'ab\ncde'.match(new RegExp('..$e$'))); + +// 'yyyyy'.match(new RegExp('xxx$')) +new TestCase ( SECTION, "'yyyyy'.match(new RegExp('xxx$'))", + null, 'yyyyy'.match(new RegExp('xxx$'))); + +// 'a$$$'.match(new RegExp('\\$+$')) +new TestCase ( SECTION, "'a$$$'.match(new RegExp('\\$+$'))", + String(['$$$']), String('a$$$'.match(new RegExp('\\$+$')))); + +// 'a$$$'.match(/\$+$/) +new TestCase ( SECTION, "'a$$$'.match(/\\$+$/)", + String(['$$$']), String('a$$$'.match(/\$+$/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/everything.js b/js/src/tests/js1_2/regexp/everything.js new file mode 100644 index 000000000..c1947a390 --- /dev/null +++ b/js/src/tests/js1_2/regexp/everything.js @@ -0,0 +1,49 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: everything.js + Description: 'Tests regular expressions' + + Author: Nick Lerissa + Date: March 24, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp'; + +writeHeaderToLog('Executing script: everything.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'Sally and Fred are sure to come.'.match(/^[a-z\s]*/i) +new TestCase ( SECTION, "'Sally and Fred are sure to come'.match(/^[a-z\\s]*/i)", + String(["Sally and Fred are sure to come"]), String('Sally and Fred are sure to come'.match(/^[a-z\s]*/i))); + +// 'test123W+xyz'.match(new RegExp('^[a-z]*[0-9]+[A-Z]?.(123|xyz)$')) +new TestCase ( SECTION, "'test123W+xyz'.match(new RegExp('^[a-z]*[0-9]+[A-Z]?.(123|xyz)$'))", + String(["test123W+xyz","xyz"]), String('test123W+xyz'.match(new RegExp('^[a-z]*[0-9]+[A-Z]?.(123|xyz)$')))); + +// 'number one 12365 number two 9898'.match(/(\d+)\D+(\d+)/) +new TestCase ( SECTION, "'number one 12365 number two 9898'.match(/(\d+)\D+(\d+)/)", + String(["12365 number two 9898","12365","9898"]), String('number one 12365 number two 9898'.match(/(\d+)\D+(\d+)/))); + +var simpleSentence = /(\s?[^\!\?\.]+[\!\?\.])+/; +// 'See Spot run.'.match(simpleSentence) +new TestCase ( SECTION, "'See Spot run.'.match(simpleSentence)", + String(["See Spot run.","See Spot run."]), String('See Spot run.'.match(simpleSentence))); + +// 'I like it. What's up? I said NO!'.match(simpleSentence) +new TestCase ( SECTION, "'I like it. What's up? I said NO!'.match(simpleSentence)", + String(["I like it. What's up? I said NO!",' I said NO!']), String('I like it. What\'s up? I said NO!'.match(simpleSentence))); + +// 'the quick brown fox jumped over the lazy dogs'.match(/((\w+)\s*)+/) +new TestCase ( SECTION, "'the quick brown fox jumped over the lazy dogs'.match(/((\\w+)\\s*)+/)", + String(['the quick brown fox jumped over the lazy dogs','dogs','dogs']),String('the quick brown fox jumped over the lazy dogs'.match(/((\w+)\s*)+/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/exec.js b/js/src/tests/js1_2/regexp/exec.js new file mode 100644 index 000000000..783260145 --- /dev/null +++ b/js/src/tests/js1_2/regexp/exec.js @@ -0,0 +1,45 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: exec.js + Description: 'Tests regular expressions exec compile' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: exec'; + +writeHeaderToLog('Executing script: exec.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +new TestCase ( SECTION, + "/[0-9]{3}/.exec('23 2 34 678 9 09')", + String(["678"]), String(/[0-9]{3}/.exec('23 2 34 678 9 09'))); + +new TestCase ( SECTION, + "/3.{4}8/.exec('23 2 34 678 9 09')", + String(["34 678"]), String(/3.{4}8/.exec('23 2 34 678 9 09'))); + +var re = new RegExp('3.{4}8'); +new TestCase ( SECTION, + "re.exec('23 2 34 678 9 09')", + String(["34 678"]), String(re.exec('23 2 34 678 9 09'))); + +new TestCase ( SECTION, + "(/3.{4}8/.exec('23 2 34 678 9 09').length", + 1, (/3.{4}8/.exec('23 2 34 678 9 09')).length); + +re = new RegExp('3.{4}8'); +new TestCase ( SECTION, + "(re.exec('23 2 34 678 9 09').length", + 1, (re.exec('23 2 34 678 9 09')).length); + +test(); diff --git a/js/src/tests/js1_2/regexp/flags.js b/js/src/tests/js1_2/regexp/flags.js new file mode 100644 index 000000000..e2529a844 --- /dev/null +++ b/js/src/tests/js1_2/regexp/flags.js @@ -0,0 +1,53 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: regexp.js + Description: 'Tests regular expressions using flags "i" and "g"' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'regular expression flags with flags "i" and "g"'; + +writeHeaderToLog('Executing script: flags.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// testing optional flag 'i' +new TestCase ( SECTION, "'aBCdEfGHijKLmno'.match(/fghijk/i)", + String(["fGHijK"]), String('aBCdEfGHijKLmno'.match(/fghijk/i))); + +new TestCase ( SECTION, "'aBCdEfGHijKLmno'.match(new RegExp('fghijk','i'))", + String(["fGHijK"]), String('aBCdEfGHijKLmno'.match(new RegExp("fghijk","i")))); + +// testing optional flag 'g' +new TestCase ( SECTION, "'xa xb xc xd xe xf'.match(/x./g)", + String(["xa","xb","xc","xd","xe","xf"]), String('xa xb xc xd xe xf'.match(/x./g))); + +new TestCase ( SECTION, "'xa xb xc xd xe xf'.match(new RegExp('x.','g'))", + String(["xa","xb","xc","xd","xe","xf"]), String('xa xb xc xd xe xf'.match(new RegExp('x.','g')))); + +// testing optional flags 'g' and 'i' +new TestCase ( SECTION, "'xa Xb xc xd Xe xf'.match(/x./gi)", + String(["xa","Xb","xc","xd","Xe","xf"]), String('xa Xb xc xd Xe xf'.match(/x./gi))); + +new TestCase ( SECTION, "'xa Xb xc xd Xe xf'.match(new RegExp('x.','gi'))", + String(["xa","Xb","xc","xd","Xe","xf"]), String('xa Xb xc xd Xe xf'.match(new RegExp('x.','gi')))); + +new TestCase ( SECTION, "'xa Xb xc xd Xe xf'.match(/x./ig)", + String(["xa","Xb","xc","xd","Xe","xf"]), String('xa Xb xc xd Xe xf'.match(/x./ig))); + +new TestCase ( SECTION, "'xa Xb xc xd Xe xf'.match(new RegExp('x.','ig'))", + String(["xa","Xb","xc","xd","Xe","xf"]), String('xa Xb xc xd Xe xf'.match(new RegExp('x.','ig')))); + + +test(); + diff --git a/js/src/tests/js1_2/regexp/global.js b/js/src/tests/js1_2/regexp/global.js new file mode 100644 index 000000000..442374cd9 --- /dev/null +++ b/js/src/tests/js1_2/regexp/global.js @@ -0,0 +1,63 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: global.js + Description: 'Tests RegExp attribute global' + + Author: Nick Lerissa + Date: March 13, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: global'; + +writeHeaderToLog('Executing script: global.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// /xyz/g.global +new TestCase ( SECTION, "/xyz/g.global", + true, /xyz/g.global); + +// /xyz/.global +new TestCase ( SECTION, "/xyz/.global", + false, /xyz/.global); + +// '123 456 789'.match(/\d+/g) +new TestCase ( SECTION, "'123 456 789'.match(/\\d+/g)", + String(["123","456","789"]), String('123 456 789'.match(/\d+/g))); + +// '123 456 789'.match(/(\d+)/g) +new TestCase ( SECTION, "'123 456 789'.match(/(\\d+)/g)", + String(["123","456","789"]), String('123 456 789'.match(/(\d+)/g))); + +// '123 456 789'.match(/\d+/) +new TestCase ( SECTION, "'123 456 789'.match(/\\d+/)", + String(["123"]), String('123 456 789'.match(/\d+/))); + +// (new RegExp('[a-z]','g')).global +new TestCase ( SECTION, "(new RegExp('[a-z]','g')).global", + true, (new RegExp('[a-z]','g')).global); + +// (new RegExp('[a-z]','i')).global +new TestCase ( SECTION, "(new RegExp('[a-z]','i')).global", + false, (new RegExp('[a-z]','i')).global); + +// '123 456 789'.match(new RegExp('\\d+','g')) +new TestCase ( SECTION, "'123 456 789'.match(new RegExp('\\\\d+','g'))", + String(["123","456","789"]), String('123 456 789'.match(new RegExp('\\d+','g')))); + +// '123 456 789'.match(new RegExp('(\\d+)','g')) +new TestCase ( SECTION, "'123 456 789'.match(new RegExp('(\\\\d+)','g'))", + String(["123","456","789"]), String('123 456 789'.match(new RegExp('(\\d+)','g')))); + +// '123 456 789'.match(new RegExp('\\d+','i')) +new TestCase ( SECTION, "'123 456 789'.match(new RegExp('\\\\d+','i'))", + String(["123"]), String('123 456 789'.match(new RegExp('\\d+','i')))); + +test(); diff --git a/js/src/tests/js1_2/regexp/hexadecimal.js b/js/src/tests/js1_2/regexp/hexadecimal.js new file mode 100644 index 000000000..09ecea77b --- /dev/null +++ b/js/src/tests/js1_2/regexp/hexadecimal.js @@ -0,0 +1,75 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: hexadecimal.js + Description: 'Tests regular expressions containing \<number> ' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: \\x# (hex) '; + +writeHeaderToLog('Executing script: hexadecimal.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +var testPattern = '\\x41\\x42\\x43\\x44\\x45\\x46\\x47\\x48\\x49\\x4A\\x4B\\x4C\\x4D\\x4E\\x4F\\x50\\x51\\x52\\x53\\x54\\x55\\x56\\x57\\x58\\x59\\x5A'; + +var testString = "12345ABCDEFGHIJKLMNOPQRSTUVWXYZ67890"; + +new TestCase ( SECTION, + "'" + testString + "'.match(new RegExp('" + testPattern + "'))", + String(["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]), String(testString.match(new RegExp(testPattern)))); + +testPattern = '\\x61\\x62\\x63\\x64\\x65\\x66\\x67\\x68\\x69\\x6A\\x6B\\x6C\\x6D\\x6E\\x6F\\x70\\x71\\x72\\x73\\x74\\x75\\x76\\x77\\x78\\x79\\x7A'; + +testString = "12345AabcdefghijklmnopqrstuvwxyzZ67890"; + +new TestCase ( SECTION, + "'" + testString + "'.match(new RegExp('" + testPattern + "'))", + String(["abcdefghijklmnopqrstuvwxyz"]), String(testString.match(new RegExp(testPattern)))); + +testPattern = '\\x20\\x21\\x22\\x23\\x24\\x25\\x26\\x27\\x28\\x29\\x2A\\x2B\\x2C\\x2D\\x2E\\x2F\\x30\\x31\\x32\\x33'; + +testString = "abc !\"#$%&'()*+,-./0123ZBC"; + +new TestCase ( SECTION, + "'" + testString + "'.match(new RegExp('" + testPattern + "'))", + String([" !\"#$%&'()*+,-./0123"]), String(testString.match(new RegExp(testPattern)))); + +testPattern = '\\x34\\x35\\x36\\x37\\x38\\x39\\x3A\\x3B\\x3C\\x3D\\x3E\\x3F\\x40'; + +testString = "123456789:;<=>?@ABC"; + +new TestCase ( SECTION, + "'" + testString + "'.match(new RegExp('" + testPattern + "'))", + String(["456789:;<=>?@"]), String(testString.match(new RegExp(testPattern)))); + +testPattern = '\\x7B\\x7C\\x7D\\x7E'; + +testString = "1234{|}~ABC"; + +new TestCase ( SECTION, + "'" + testString + "'.match(new RegExp('" + testPattern + "'))", + String(["{|}~"]), String(testString.match(new RegExp(testPattern)))); + +new TestCase ( SECTION, + "'canthisbeFOUND'.match(new RegExp('[A-\\x5A]+'))", + String(["FOUND"]), String('canthisbeFOUND'.match(new RegExp('[A-\\x5A]+')))); + +new TestCase ( SECTION, + "'canthisbeFOUND'.match(new RegExp('[\\x61-\\x7A]+'))", + String(["canthisbe"]), String('canthisbeFOUND'.match(new RegExp('[\\x61-\\x7A]+')))); + +new TestCase ( SECTION, + "'canthisbeFOUND'.match(/[\\x61-\\x7A]+/)", + String(["canthisbe"]), String('canthisbeFOUND'.match(/[\x61-\x7A]+/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/ignoreCase.js b/js/src/tests/js1_2/regexp/ignoreCase.js new file mode 100644 index 000000000..f02ba91b0 --- /dev/null +++ b/js/src/tests/js1_2/regexp/ignoreCase.js @@ -0,0 +1,80 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: ignoreCase.js + Description: 'Tests RegExp attribute ignoreCase' + + Author: Nick Lerissa + Date: March 13, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: ignoreCase'; + +writeHeaderToLog('Executing script: ignoreCase.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// /xyz/i.ignoreCase +new TestCase ( SECTION, "/xyz/i.ignoreCase", + true, /xyz/i.ignoreCase); + +// /xyz/.ignoreCase +new TestCase ( SECTION, "/xyz/.ignoreCase", + false, /xyz/.ignoreCase); + +// 'ABC def ghi'.match(/[a-z]+/ig) +new TestCase ( SECTION, "'ABC def ghi'.match(/[a-z]+/ig)", + String(["ABC","def","ghi"]), String('ABC def ghi'.match(/[a-z]+/ig))); + +// 'ABC def ghi'.match(/[a-z]+/i) +new TestCase ( SECTION, "'ABC def ghi'.match(/[a-z]+/i)", + String(["ABC"]), String('ABC def ghi'.match(/[a-z]+/i))); + +// 'ABC def ghi'.match(/([a-z]+)/ig) +new TestCase ( SECTION, "'ABC def ghi'.match(/([a-z]+)/ig)", + String(["ABC","def","ghi"]), String('ABC def ghi'.match(/([a-z]+)/ig))); + +// 'ABC def ghi'.match(/([a-z]+)/i) +new TestCase ( SECTION, "'ABC def ghi'.match(/([a-z]+)/i)", + String(["ABC","ABC"]), String('ABC def ghi'.match(/([a-z]+)/i))); + +// 'ABC def ghi'.match(/[a-z]+/) +new TestCase ( SECTION, "'ABC def ghi'.match(/[a-z]+/)", + String(["def"]), String('ABC def ghi'.match(/[a-z]+/))); + +// (new RegExp('xyz','i')).ignoreCase +new TestCase ( SECTION, "(new RegExp('xyz','i')).ignoreCase", + true, (new RegExp('xyz','i')).ignoreCase); + +// (new RegExp('xyz')).ignoreCase +new TestCase ( SECTION, "(new RegExp('xyz')).ignoreCase", + false, (new RegExp('xyz')).ignoreCase); + +// 'ABC def ghi'.match(new RegExp('[a-z]+','ig')) +new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('[a-z]+','ig'))", + String(["ABC","def","ghi"]), String('ABC def ghi'.match(new RegExp('[a-z]+','ig')))); + +// 'ABC def ghi'.match(new RegExp('[a-z]+','i')) +new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('[a-z]+','i'))", + String(["ABC"]), String('ABC def ghi'.match(new RegExp('[a-z]+','i')))); + +// 'ABC def ghi'.match(new RegExp('([a-z]+)','ig')) +new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('([a-z]+)','ig'))", + String(["ABC","def","ghi"]), String('ABC def ghi'.match(new RegExp('([a-z]+)','ig')))); + +// 'ABC def ghi'.match(new RegExp('([a-z]+)','i')) +new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('([a-z]+)','i'))", + String(["ABC","ABC"]), String('ABC def ghi'.match(new RegExp('([a-z]+)','i')))); + +// 'ABC def ghi'.match(new RegExp('[a-z]+')) +new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('[a-z]+'))", + String(["def"]), String('ABC def ghi'.match(new RegExp('[a-z]+')))); + +test(); diff --git a/js/src/tests/js1_2/regexp/interval.js b/js/src/tests/js1_2/regexp/interval.js new file mode 100644 index 000000000..1cd681817 --- /dev/null +++ b/js/src/tests/js1_2/regexp/interval.js @@ -0,0 +1,83 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: interval.js + Description: 'Tests regular expressions containing {}' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: {}'; + +writeHeaderToLog('Executing script: interval.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{2}c')) +new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{2}c'))", + String(["bbc"]), String('aaabbbbcccddeeeefffff'.match(new RegExp('b{2}c')))); + +// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{8}')) +new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{8}'))", + null, 'aaabbbbcccddeeeefffff'.match(new RegExp('b{8}'))); + +// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{2,}c')) +new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{2,}c'))", + String(["bbbbc"]), String('aaabbbbcccddeeeefffff'.match(new RegExp('b{2,}c')))); + +// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{8,}c')) +new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{8,}c'))", + null, 'aaabbbbcccddeeeefffff'.match(new RegExp('b{8,}c'))); + +// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{2,3}c')) +new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{2,3}c'))", + String(["bbbc"]), String('aaabbbbcccddeeeefffff'.match(new RegExp('b{2,3}c')))); + +// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{42,93}c')) +new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{42,93}c'))", + null, 'aaabbbbcccddeeeefffff'.match(new RegExp('b{42,93}c'))); + +// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{0,93}c')) +new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{0,93}c'))", + String(["bbbbc"]), String('aaabbbbcccddeeeefffff'.match(new RegExp('b{0,93}c')))); + +// 'aaabbbbcccddeeeefffff'.match(new RegExp('bx{0,93}c')) +new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('bx{0,93}c'))", + String(["bc"]), String('aaabbbbcccddeeeefffff'.match(new RegExp('bx{0,93}c')))); + +// 'weirwerdf'.match(new RegExp('.{0,93}')) +new TestCase ( SECTION, "'weirwerdf'.match(new RegExp('.{0,93}'))", + String(["weirwerdf"]), String('weirwerdf'.match(new RegExp('.{0,93}')))); + +// 'wqe456646dsff'.match(new RegExp('\d{1,}')) +new TestCase ( SECTION, "'wqe456646dsff'.match(new RegExp('\\d{1,}'))", + String(["456646"]), String('wqe456646dsff'.match(new RegExp('\\d{1,}')))); + +// '123123'.match(new RegExp('(123){1,}')) +new TestCase ( SECTION, "'123123'.match(new RegExp('(123){1,}'))", + String(["123123","123"]), String('123123'.match(new RegExp('(123){1,}')))); + +// '123123x123'.match(new RegExp('(123){1,}x\1')) +new TestCase ( SECTION, "'123123x123'.match(new RegExp('(123){1,}x\\1'))", + String(["123123x123","123"]), String('123123x123'.match(new RegExp('(123){1,}x\\1')))); + +// '123123x123'.match(/(123){1,}x\1/) +new TestCase ( SECTION, "'123123x123'.match(/(123){1,}x\\1/)", + String(["123123x123","123"]), String('123123x123'.match(/(123){1,}x\1/))); + +// 'xxxxxxx'.match(new RegExp('x{1,2}x{1,}')) +new TestCase ( SECTION, "'xxxxxxx'.match(new RegExp('x{1,2}x{1,}'))", + String(["xxxxxxx"]), String('xxxxxxx'.match(new RegExp('x{1,2}x{1,}')))); + +// 'xxxxxxx'.match(/x{1,2}x{1,}/) +new TestCase ( SECTION, "'xxxxxxx'.match(/x{1,2}x{1,}/)", + String(["xxxxxxx"]), String('xxxxxxx'.match(/x{1,2}x{1,}/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/octal.js b/js/src/tests/js1_2/regexp/octal.js new file mode 100644 index 000000000..79228428b --- /dev/null +++ b/js/src/tests/js1_2/regexp/octal.js @@ -0,0 +1,75 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: octal.js + Description: 'Tests regular expressions containing \<number> ' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: \# (octal) '; + +writeHeaderToLog('Executing script: octal.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +var testPattern = '\\101\\102\\103\\104\\105\\106\\107\\110\\111\\112\\113\\114\\115\\116\\117\\120\\121\\122\\123\\124\\125\\126\\127\\130\\131\\132'; + +var testString = "12345ABCDEFGHIJKLMNOPQRSTUVWXYZ67890"; + +new TestCase ( SECTION, + "'" + testString + "'.match(new RegExp('" + testPattern + "'))", + String(["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]), String(testString.match(new RegExp(testPattern)))); + +testPattern = '\\141\\142\\143\\144\\145\\146\\147\\150\\151\\152\\153\\154\\155\\156\\157\\160\\161\\162\\163\\164\\165\\166\\167\\170\\171\\172'; + +testString = "12345AabcdefghijklmnopqrstuvwxyzZ67890"; + +new TestCase ( SECTION, + "'" + testString + "'.match(new RegExp('" + testPattern + "'))", + String(["abcdefghijklmnopqrstuvwxyz"]), String(testString.match(new RegExp(testPattern)))); + +testPattern = '\\40\\41\\42\\43\\44\\45\\46\\47\\50\\51\\52\\53\\54\\55\\56\\57\\60\\61\\62\\63'; + +testString = "abc !\"#$%&'()*+,-./0123ZBC"; + +new TestCase ( SECTION, + "'" + testString + "'.match(new RegExp('" + testPattern + "'))", + String([" !\"#$%&'()*+,-./0123"]), String(testString.match(new RegExp(testPattern)))); + +testPattern = '\\64\\65\\66\\67\\70\\71\\72\\73\\74\\75\\76\\77\\100'; + +testString = "123456789:;<=>?@ABC"; + +new TestCase ( SECTION, + "'" + testString + "'.match(new RegExp('" + testPattern + "'))", + String(["456789:;<=>?@"]), String(testString.match(new RegExp(testPattern)))); + +testPattern = '\\173\\174\\175\\176'; + +testString = "1234{|}~ABC"; + +new TestCase ( SECTION, + "'" + testString + "'.match(new RegExp('" + testPattern + "'))", + String(["{|}~"]), String(testString.match(new RegExp(testPattern)))); + +new TestCase ( SECTION, + "'canthisbeFOUND'.match(new RegExp('[A-\\132]+'))", + String(["FOUND"]), String('canthisbeFOUND'.match(new RegExp('[A-\\132]+')))); + +new TestCase ( SECTION, + "'canthisbeFOUND'.match(new RegExp('[\\141-\\172]+'))", + String(["canthisbe"]), String('canthisbeFOUND'.match(new RegExp('[\\141-\\172]+')))); + +new TestCase ( SECTION, + "'canthisbeFOUND'.match(/[\\141-\\172]+/)", + String(["canthisbe"]), String('canthisbeFOUND'.match(/[\141-\172]+/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/parentheses.js b/js/src/tests/js1_2/regexp/parentheses.js new file mode 100644 index 000000000..90209cf0b --- /dev/null +++ b/js/src/tests/js1_2/regexp/parentheses.js @@ -0,0 +1,75 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: parentheses.js + Description: 'Tests regular expressions containing ()' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: ()'; + +writeHeaderToLog('Executing script: parentheses.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 'abc'.match(new RegExp('(abc)')) +new TestCase ( SECTION, "'abc'.match(new RegExp('(abc)'))", + String(["abc","abc"]), String('abc'.match(new RegExp('(abc)')))); + +// 'abcdefg'.match(new RegExp('a(bc)d(ef)g')) +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('a(bc)d(ef)g'))", + String(["abcdefg","bc","ef"]), String('abcdefg'.match(new RegExp('a(bc)d(ef)g')))); + +// 'abcdefg'.match(new RegExp('(.{3})(.{4})')) +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('(.{3})(.{4})'))", + String(["abcdefg","abc","defg"]), String('abcdefg'.match(new RegExp('(.{3})(.{4})')))); + +// 'aabcdaabcd'.match(new RegExp('(aa)bcd\1')) +new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(aa)bcd\\1'))", + String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(aa)bcd\\1')))); + +// 'aabcdaabcd'.match(new RegExp('(aa).+\1')) +new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(aa).+\\1'))", + String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(aa).+\\1')))); + +// 'aabcdaabcd'.match(new RegExp('(.{2}).+\1')) +new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(.{2}).+\\1'))", + String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(.{2}).+\\1')))); + +// '123456123456'.match(new RegExp('(\d{3})(\d{3})\1\2')) +new TestCase ( SECTION, "'123456123456'.match(new RegExp('(\\d{3})(\\d{3})\\1\\2'))", + String(["123456123456","123","456"]), String('123456123456'.match(new RegExp('(\\d{3})(\\d{3})\\1\\2')))); + +// 'abcdefg'.match(new RegExp('a(..(..)..)')) +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('a(..(..)..)'))", + String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(new RegExp('a(..(..)..)')))); + +// 'abcdefg'.match(/a(..(..)..)/) +new TestCase ( SECTION, "'abcdefg'.match(/a(..(..)..)/)", + String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(/a(..(..)..)/))); + +// 'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))')) +new TestCase ( SECTION, "'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))'))", + String(["abcdef","abc","bc","c","def","ef","f"]), String('xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))')))); + +// 'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\2\5')) +new TestCase ( SECTION, "'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\2\\5'))", + String(["abcdefbcef","abc","bc","c","def","ef","f"]), String('xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\2\\5')))); + +// 'abcd'.match(new RegExp('a(.?)b\1c\1d\1')) +new TestCase ( SECTION, "'abcd'.match(new RegExp('a(.?)b\\1c\\1d\\1'))", + String(["abcd",""]), String('abcd'.match(new RegExp('a(.?)b\\1c\\1d\\1')))); + +// 'abcd'.match(/a(.?)b\1c\1d\1/) +new TestCase ( SECTION, "'abcd'.match(/a(.?)b\\1c\\1d\\1/)", + String(["abcd",""]), String('abcd'.match(/a(.?)b\1c\1d\1/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/plus.js b/js/src/tests/js1_2/regexp/plus.js new file mode 100644 index 000000000..0d5c40f33 --- /dev/null +++ b/js/src/tests/js1_2/regexp/plus.js @@ -0,0 +1,55 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: plus.js + Description: 'Tests regular expressions containing +' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: +'; + +writeHeaderToLog('Executing script: plus.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 'abcdddddefg'.match(new RegExp('d+')) +new TestCase ( SECTION, "'abcdddddefg'.match(new RegExp('d+'))", + String(["ddddd"]), String('abcdddddefg'.match(new RegExp('d+')))); + +// 'abcdefg'.match(new RegExp('o+')) +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('o+'))", + null, 'abcdefg'.match(new RegExp('o+'))); + +// 'abcdefg'.match(new RegExp('d+')) +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('d+'))", + String(['d']), String('abcdefg'.match(new RegExp('d+')))); + +// 'abbbbbbbc'.match(new RegExp('(b+)(b+)(b+)')) +new TestCase ( SECTION, "'abbbbbbbc'.match(new RegExp('(b+)(b+)(b+)'))", + String(["bbbbbbb","bbbbb","b","b"]), String('abbbbbbbc'.match(new RegExp('(b+)(b+)(b+)')))); + +// 'abbbbbbbc'.match(new RegExp('(b+)(b*)')) +new TestCase ( SECTION, "'abbbbbbbc'.match(new RegExp('(b+)(b*)'))", + String(["bbbbbbb","bbbbbbb",""]), String('abbbbbbbc'.match(new RegExp('(b+)(b*)')))); + +// 'abbbbbbbc'.match(new RegExp('b*b+')) +new TestCase ( SECTION, "'abbbbbbbc'.match(new RegExp('b*b+'))", + String(['bbbbbbb']), String('abbbbbbbc'.match(new RegExp('b*b+')))); + +// 'abbbbbbbc'.match(/(b+)(b*)/) +new TestCase ( SECTION, "'abbbbbbbc'.match(/(b+)(b*)/)", + String(["bbbbbbb","bbbbbbb",""]), String('abbbbbbbc'.match(/(b+)(b*)/))); + +// 'abbbbbbbc'.match(new RegExp('b*b+')) +new TestCase ( SECTION, "'abbbbbbbc'.match(/b*b+/)", + String(['bbbbbbb']), String('abbbbbbbc'.match(/b*b+/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/question_mark.js b/js/src/tests/js1_2/regexp/question_mark.js new file mode 100644 index 000000000..e159be8bb --- /dev/null +++ b/js/src/tests/js1_2/regexp/question_mark.js @@ -0,0 +1,67 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: question_mark.js + Description: 'Tests regular expressions containing ?' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: ?'; + +writeHeaderToLog('Executing script: question_mark.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 'abcdef'.match(new RegExp('cd?e')) +new TestCase ( SECTION, "'abcdef'.match(new RegExp('cd?e'))", + String(["cde"]), String('abcdef'.match(new RegExp('cd?e')))); + +// 'abcdef'.match(new RegExp('cdx?e')) +new TestCase ( SECTION, "'abcdef'.match(new RegExp('cdx?e'))", + String(["cde"]), String('abcdef'.match(new RegExp('cdx?e')))); + +// 'pqrstuvw'.match(new RegExp('o?pqrst')) +new TestCase ( SECTION, "'pqrstuvw'.match(new RegExp('o?pqrst'))", + String(["pqrst"]), String('pqrstuvw'.match(new RegExp('o?pqrst')))); + +// 'abcd'.match(new RegExp('x?y?z?')) +new TestCase ( SECTION, "'abcd'.match(new RegExp('x?y?z?'))", + String([""]), String('abcd'.match(new RegExp('x?y?z?')))); + +// 'abcd'.match(new RegExp('x?ay?bz?c')) +new TestCase ( SECTION, "'abcd'.match(new RegExp('x?ay?bz?c'))", + String(["abc"]), String('abcd'.match(new RegExp('x?ay?bz?c')))); + +// 'abcd'.match(/x?ay?bz?c/) +new TestCase ( SECTION, "'abcd'.match(/x?ay?bz?c/)", + String(["abc"]), String('abcd'.match(/x?ay?bz?c/))); + +// 'abbbbc'.match(new RegExp('b?b?b?b')) +new TestCase ( SECTION, "'abbbbc'.match(new RegExp('b?b?b?b'))", + String(["bbbb"]), String('abbbbc'.match(new RegExp('b?b?b?b')))); + +// '123az789'.match(new RegExp('ab?c?d?x?y?z')) +new TestCase ( SECTION, "'123az789'.match(new RegExp('ab?c?d?x?y?z'))", + String(["az"]), String('123az789'.match(new RegExp('ab?c?d?x?y?z')))); + +// '123az789'.match(/ab?c?d?x?y?z/) +new TestCase ( SECTION, "'123az789'.match(/ab?c?d?x?y?z/)", + String(["az"]), String('123az789'.match(/ab?c?d?x?y?z/))); + +// '?????'.match(new RegExp('\\??\\??\\??\\??\\??')) +new TestCase ( SECTION, "'?????'.match(new RegExp('\\??\\??\\??\\??\\??'))", + String(["?????"]), String('?????'.match(new RegExp('\\??\\??\\??\\??\\??')))); + +// 'test'.match(new RegExp('.?.?.?.?.?.?.?')) +new TestCase ( SECTION, "'test'.match(new RegExp('.?.?.?.?.?.?.?'))", + String(["test"]), String('test'.match(new RegExp('.?.?.?.?.?.?.?')))); + +test(); diff --git a/js/src/tests/js1_2/regexp/regress-6359.js b/js/src/tests/js1_2/regexp/regress-6359.js new file mode 100644 index 000000000..5a63f0ac2 --- /dev/null +++ b/js/src/tests/js1_2/regexp/regress-6359.js @@ -0,0 +1,53 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: regress-6359.js + * Reference: ** replace with bugzilla URL or document reference ** + * Description: ** replace with description of test ** + * Author: ** replace with your e-mail address ** + */ + +var SECTION = "js1_2"; // provide a document reference (ie, ECMA section) +var VERSION = "ECMA_2"; // Version of JavaScript or ECMA +var TITLE = "Regression test for bugzilla # 6359"; // Provide ECMA section title or a description +var BUGNUMBER = "http://bugzilla.mozilla.org/show_bug.cgi?id=6359"; // Provide URL to bugsplat or bugzilla report + +startTest(); // leave this alone + +/* + * Calls to AddTestCase here. AddTestCase is a function that is defined + * in shell.js and takes three arguments: + * - a string representation of what is being tested + * - the expected result + * - the actual result + * + * For example, a test might look like this: + * + * var zip = /[\d]{5}$/; + * + * AddTestCase( + * "zip = /[\d]{5}$/; \"PO Box 12345 Boston, MA 02134\".match(zip)", // description of the test + * "02134", // expected result + * "PO Box 12345 Boston, MA 02134".match(zip) ); // actual result + * + */ + +AddTestCase( '/(a*)b\1+/.exec("baaac").length', + 2, + /(a*)b\1+/.exec("baaac").length ); + +AddTestCase( '/(a*)b\1+/.exec("baaac")[0]', + "b", + /(a*)b\1+/.exec("baaac")[0]); + +AddTestCase( '/(a*)b\1+/.exec("baaac")[1]', + "", + /(a*)b\1+/.exec("baaac")[1]); + + +test(); // leave this alone. this executes the test cases and +// displays results. diff --git a/js/src/tests/js1_2/regexp/regress-9141.js b/js/src/tests/js1_2/regexp/regress-9141.js new file mode 100644 index 000000000..987995feb --- /dev/null +++ b/js/src/tests/js1_2/regexp/regress-9141.js @@ -0,0 +1,72 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + + +/** + * File Name: regress-9141.js + * Reference: "http://bugzilla.mozilla.org/show_bug.cgi?id=9141"; + * Description: + * From waldemar@netscape.com: + * + * The following page crashes the system: + * + * <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" + * "http://www.w3.org/TR/REC-html40/loose.dtd"> + * <HTML> + * <HEAD> + * </HEAD> + * <BODY> + * <SCRIPT type="text/javascript"> + * var s = "x"; + * for (var i = 0; i != 13; i++) s += s; + * var a = /(?:xx|x)*[slash](s); + * var b = /(xx|x)*[slash](s); + * document.write("Results = " + a.length + "," + b.length); + * </SCRIPT> + * </BODY> + */ + +var SECTION = "js1_2"; // provide a document reference (ie, ECMA section) +var VERSION = "ECMA_2"; // Version of JavaScript or ECMA +var TITLE = "Regression test for bugzilla # 9141"; // Provide ECMA section title or a description +var BUGNUMBER = "http://bugzilla.mozilla.org/show_bug.cgi?id=9141"; // Provide URL to bugsplat or bugzilla report + +startTest(); // leave this alone + +/* + * Calls to AddTestCase here. AddTestCase is a function that is defined + * in shell.js and takes three arguments: + * - a string representation of what is being tested + * - the expected result + * - the actual result + * + * For example, a test might look like this: + * + * var zip = /[\d]{5}$/; + * + * AddTestCase( + * "zip = /[\d]{5}$/; \"PO Box 12345 Boston, MA 02134\".match(zip)", // description of the test + * "02134", // expected result + * "PO Box 12345 Boston, MA 02134".match(zip) ); // actual result + * + */ + +var s = "x"; +for (var i = 0; i != 13; i++) s += s; +var a = /(?:xx|x)*/.exec(s); +var b = /(xx|x)*/.exec(s); + +AddTestCase( "var s = 'x'; for (var i = 0; i != 13; i++) s += s; " + + "a = /(?:xx|x)*/.exec(s); a.length", + 1, + a.length ); + +AddTestCase( "var b = /(xx|x)*/.exec(s); b.length", + 2, + b.length ); + +test(); // leave this alone. this executes the test cases and +// displays results. diff --git a/js/src/tests/js1_2/regexp/shell.js b/js/src/tests/js1_2/regexp/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/regexp/shell.js diff --git a/js/src/tests/js1_2/regexp/simple_form.js b/js/src/tests/js1_2/regexp/simple_form.js new file mode 100644 index 000000000..3c3e98dad --- /dev/null +++ b/js/src/tests/js1_2/regexp/simple_form.js @@ -0,0 +1,58 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: simple_form.js + Description: 'Tests regular expressions using simple form: re.exec(...)' + + Author: Nick Lerissa + Date: March 19, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: simple form'; + +writeHeaderToLog('Executing script: simple_form.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +new TestCase ( SECTION, + "/[0-9]{3}/.exec('23 2 34 678 9 09')", + String(["678"]), String(/[0-9]{3}/.exec('23 2 34 678 9 09'))); + +new TestCase ( SECTION, + "/3.{4}8/.exec('23 2 34 678 9 09')", + String(["34 678"]), String(/3.{4}8/.exec('23 2 34 678 9 09'))); + +new TestCase ( SECTION, + "(/3.{4}8/.exec('23 2 34 678 9 09').length", + 1, (/3.{4}8/.exec('23 2 34 678 9 09')).length); + +var re = /[0-9]{3}/; +new TestCase ( SECTION, + "re.exec('23 2 34 678 9 09')", + String(["678"]), String(re.exec('23 2 34 678 9 09'))); + +re = /3.{4}8/; +new TestCase ( SECTION, + "re.exec('23 2 34 678 9 09')", + String(["34 678"]), String(re.exec('23 2 34 678 9 09'))); + +new TestCase ( SECTION, + "/3.{4}8/.exec('23 2 34 678 9 09')", + String(["34 678"]), String(/3.{4}8/.exec('23 2 34 678 9 09'))); + +re =/3.{4}8/; +new TestCase ( SECTION, + "(re.exec('23 2 34 678 9 09').length", + 1, (re.exec('23 2 34 678 9 09')).length); + +new TestCase ( SECTION, + "(/3.{4}8/.exec('23 2 34 678 9 09').length", + 1, (/3.{4}8/.exec('23 2 34 678 9 09')).length); + +test(); diff --git a/js/src/tests/js1_2/regexp/source.js b/js/src/tests/js1_2/regexp/source.js new file mode 100644 index 000000000..84b226a43 --- /dev/null +++ b/js/src/tests/js1_2/regexp/source.js @@ -0,0 +1,56 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: source.js + Description: 'Tests RegExp attribute source' + + Author: Nick Lerissa + Date: March 13, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: source'; + +writeHeaderToLog('Executing script: source.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// /xyz/g.source +new TestCase ( SECTION, "/xyz/g.source", + "xyz", /xyz/g.source); + +// /xyz/.source +new TestCase ( SECTION, "/xyz/.source", + "xyz", /xyz/.source); + +// /abc\\def/.source +new TestCase ( SECTION, "/abc\\\\def/.source", + "abc\\\\def", /abc\\def/.source); + +// /abc[\b]def/.source +new TestCase ( SECTION, "/abc[\\b]def/.source", + "abc[\\b]def", /abc[\b]def/.source); + +// (new RegExp('xyz')).source +new TestCase ( SECTION, "(new RegExp('xyz')).source", + "xyz", (new RegExp('xyz')).source); + +// (new RegExp('xyz','g')).source +new TestCase ( SECTION, "(new RegExp('xyz','g')).source", + "xyz", (new RegExp('xyz','g')).source); + +// (new RegExp('abc\\\\def')).source +new TestCase ( SECTION, "(new RegExp('abc\\\\\\\\def')).source", + "abc\\\\def", (new RegExp('abc\\\\def')).source); + +// (new RegExp('abc[\\b]def')).source +new TestCase ( SECTION, "(new RegExp('abc[\\\\b]def')).source", + "abc[\\b]def", (new RegExp('abc[\\b]def')).source); + +test(); diff --git a/js/src/tests/js1_2/regexp/special_characters.js b/js/src/tests/js1_2/regexp/special_characters.js new file mode 100644 index 000000000..1e40eb69d --- /dev/null +++ b/js/src/tests/js1_2/regexp/special_characters.js @@ -0,0 +1,126 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: special_characters.js + Description: 'Tests regular expressions containing special characters' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: special_charaters'; + +writeHeaderToLog('Executing script: special_characters.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// testing backslash '\' +new TestCase ( SECTION, "'^abcdefghi'.match(/\^abc/)", String(["^abc"]), String('^abcdefghi'.match(/\^abc/))); + +// testing beginning of line '^' +new TestCase ( SECTION, "'abcdefghi'.match(/^abc/)", String(["abc"]), String('abcdefghi'.match(/^abc/))); + +// testing end of line '$' +new TestCase ( SECTION, "'abcdefghi'.match(/fghi$/)", String(["ghi"]), String('abcdefghi'.match(/ghi$/))); + +// testing repeat '*' +new TestCase ( SECTION, "'eeeefghi'.match(/e*/)", String(["eeee"]), String('eeeefghi'.match(/e*/))); + +// testing repeat 1 or more times '+' +new TestCase ( SECTION, "'abcdeeeefghi'.match(/e+/)", String(["eeee"]), String('abcdeeeefghi'.match(/e+/))); + +// testing repeat 0 or 1 time '?' +new TestCase ( SECTION, "'abcdefghi'.match(/abc?de/)", String(["abcde"]), String('abcdefghi'.match(/abc?de/))); + +// testing any character '.' +new TestCase ( SECTION, "'abcdefghi'.match(/c.e/)", String(["cde"]), String('abcdefghi'.match(/c.e/))); + +// testing remembering () +new TestCase ( SECTION, "'abcewirjskjdabciewjsdf'.match(/(abc).+\\1'/)", + String(["abcewirjskjdabc","abc"]), String('abcewirjskjdabciewjsdf'.match(/(abc).+\1/))); + +// testing or match '|' +new TestCase ( SECTION, "'abcdefghi'.match(/xyz|def/)", String(["def"]), String('abcdefghi'.match(/xyz|def/))); + +// testing repeat n {n} +new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{3}/)", String(["eee"]), String('abcdeeeefghi'.match(/e{3}/))); + +// testing min repeat n {n,} +new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{3,}/)", String(["eeee"]), String('abcdeeeefghi'.match(/e{3,}/))); + +// testing min/max repeat {min, max} +new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{2,8}/)", String(["eeee"]), String('abcdeeeefghi'.match(/e{2,8}/))); + +// testing any in set [abc...] +new TestCase ( SECTION, "'abcdefghi'.match(/cd[xey]fgh/)", String(["cdefgh"]), String('abcdefghi'.match(/cd[xey]fgh/))); + +// testing any in set [a-z] +new TestCase ( SECTION, "'netscape inc'.match(/t[r-v]ca/)", String(["tsca"]), String('netscape inc'.match(/t[r-v]ca/))); + +// testing any not in set [^abc...] +new TestCase ( SECTION, "'abcdefghi'.match(/cd[^xy]fgh/)", String(["cdefgh"]), String('abcdefghi'.match(/cd[^xy]fgh/))); + +// testing any not in set [^a-z] +new TestCase ( SECTION, "'netscape inc'.match(/t[^a-c]ca/)", String(["tsca"]), String('netscape inc'.match(/t[^a-c]ca/))); + +// testing backspace [\b] +new TestCase ( SECTION, "'this is b\ba test'.match(/is b[\b]a test/)", + String(["is b\ba test"]), String('this is b\ba test'.match(/is b[\b]a test/))); + +// testing word boundary \b +new TestCase ( SECTION, "'today is now - day is not now'.match(/\bday.*now/)", + String(["day is not now"]), String('today is now - day is not now'.match(/\bday.*now/))); + +// control characters??? + +// testing any digit \d +new TestCase ( SECTION, "'a dog - 1 dog'.match(/\d dog/)", String(["1 dog"]), String('a dog - 1 dog'.match(/\d dog/))); + +// testing any non digit \d +new TestCase ( SECTION, "'a dog - 1 dog'.match(/\D dog/)", String(["a dog"]), String('a dog - 1 dog'.match(/\D dog/))); + +// testing form feed '\f' +new TestCase ( SECTION, "'a b a\fb'.match(/a\fb/)", String(["a\fb"]), String('a b a\fb'.match(/a\fb/))); + +// testing line feed '\n' +new TestCase ( SECTION, "'a b a\nb'.match(/a\nb/)", String(["a\nb"]), String('a b a\nb'.match(/a\nb/))); + +// testing carriage return '\r' +new TestCase ( SECTION, "'a b a\rb'.match(/a\rb/)", String(["a\rb"]), String('a b a\rb'.match(/a\rb/))); + +// testing whitespace '\s' +new TestCase ( SECTION, "'xa\f\n\r\t\vbz'.match(/a\s+b/)", String(["a\f\n\r\t\vb"]), String('xa\f\n\r\t\vbz'.match(/a\s+b/))); + +// testing non whitespace '\S' +new TestCase ( SECTION, "'a\tb a b a-b'.match(/a\Sb/)", String(["a-b"]), String('a\tb a b a-b'.match(/a\Sb/))); + +// testing tab '\t' +new TestCase ( SECTION, "'a\t\tb a b'.match(/a\t{2}/)", String(["a\t\t"]), String('a\t\tb a b'.match(/a\t{2}/))); + +// testing vertical tab '\v' +new TestCase ( SECTION, "'a\v\vb a b'.match(/a\v{2}/)", String(["a\v\v"]), String('a\v\vb a b'.match(/a\v{2}/))); + +// testing alphnumeric characters '\w' +new TestCase ( SECTION, "'%AZaz09_$'.match(/\w+/)", String(["AZaz09_"]), String('%AZaz09_$'.match(/\w+/))); + +// testing non alphnumeric characters '\W' +new TestCase ( SECTION, "'azx$%#@*4534'.match(/\W+/)", String(["$%#@*"]), String('azx$%#@*4534'.match(/\W+/))); + +// testing back references '\<number>' +new TestCase ( SECTION, "'test'.match(/(t)es\\1/)", String(["test","t"]), String('test'.match(/(t)es\1/))); + +// testing hex excaping with '\' +new TestCase ( SECTION, "'abcdef'.match(/\x63\x64/)", String(["cd"]), String('abcdef'.match(/\x63\x64/))); + +// testing oct excaping with '\' +new TestCase ( SECTION, "'abcdef'.match(/\\143\\144/)", String(["cd"]), String('abcdef'.match(/\143\144/))); + +test(); + diff --git a/js/src/tests/js1_2/regexp/string_replace.js b/js/src/tests/js1_2/regexp/string_replace.js new file mode 100644 index 000000000..1b3c832fd --- /dev/null +++ b/js/src/tests/js1_2/regexp/string_replace.js @@ -0,0 +1,92 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: string_replace.js + Description: 'Tests the replace method on Strings using regular expressions' + + Author: Nick Lerissa + Date: March 11, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'String: replace'; + +writeHeaderToLog('Executing script: string_replace.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'adddb'.replace(/ddd/,"XX") +new TestCase ( SECTION, "'adddb'.replace(/ddd/,'XX')", + "aXXb", 'adddb'.replace(/ddd/,'XX')); + +// 'adddb'.replace(/eee/,"XX") +new TestCase ( SECTION, "'adddb'.replace(/eee/,'XX')", + 'adddb', 'adddb'.replace(/eee/,'XX')); + +// '34 56 78b 12'.replace(new RegExp('[0-9]+b'),'**') +new TestCase ( SECTION, "'34 56 78b 12'.replace(new RegExp('[0-9]+b'),'**')", + "34 56 ** 12", '34 56 78b 12'.replace(new RegExp('[0-9]+b'),'**')); + +// '34 56 78b 12'.replace(new RegExp('[0-9]+c'),'XX') +new TestCase ( SECTION, "'34 56 78b 12'.replace(new RegExp('[0-9]+c'),'XX')", + "34 56 78b 12", '34 56 78b 12'.replace(new RegExp('[0-9]+c'),'XX')); + +// 'original'.replace(new RegExp(),'XX') +new TestCase ( SECTION, "'original'.replace(new RegExp(),'XX')", + "XXoriginal", 'original'.replace(new RegExp(),'XX')); + +// 'qwe ert x\t\n 345654AB'.replace(new RegExp('x\s*\d+(..)$'),'****') +new TestCase ( SECTION, "'qwe ert x\t\n 345654AB'.replace(new RegExp('x\\s*\\d+(..)$'),'****')", + "qwe ert ****", 'qwe ert x\t\n 345654AB'.replace(new RegExp('x\\s*\\d+(..)$'),'****')); + + +/* + * Test replacement over ropes. The char to rope node ratio must be sufficiently + * high for the special-case code to be tested. + */ +var stringA = "abcdef"; +var stringB = "ghijk"; +var stringC = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"; +stringC += stringC; +stringC += stringC; +stringC[0]; /* flatten stringC */ +var stringD = "lmn"; + +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('aa', '')", + stringA + stringB + stringC, (stringA + stringB + stringC).replace('aa', '')); + +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('abc', 'AA')", + "AAdefghijk" + stringC, (stringA + stringB + stringC).replace('abc', 'AA')); + +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('def', 'AA')", + "abcAAghijk" + stringC, (stringA + stringB + stringC).replace('def', 'AA')); + +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('efg', 'AA')", + "abcdAAhijk" + stringC, (stringA + stringB + stringC).replace('efg', 'AA')); + +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('fgh', 'AA')", + "abcdeAAijk" + stringC, (stringA + stringB + stringC).replace('fgh', 'AA')); + +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('ghi', 'AA')", + "abcdefAAjk" + stringC, (stringA + stringB + stringC).replace('ghi', 'AA')); + +new TestCase ( SECTION, "(stringC + stringD).replace('lmn', 'AA')", + stringC + "AA", (stringC + stringD).replace('lmn', 'AA')); + +new TestCase ( SECTION, "(stringC + stringD).replace('lmno', 'AA')", + stringC + stringD, (stringC + stringD).replace('lmno', 'AA')); + +new TestCase ( SECTION, "(stringC + stringD).replace('mn', 'AA')", + stringC + "lAA", (stringC + stringD).replace('mn', 'AA')); + +new TestCase ( SECTION, "(stringC + stringD).replace('n', 'AA')", + stringC + "lmAA", (stringC + stringD).replace('n', 'AA')); + + +test(); diff --git a/js/src/tests/js1_2/regexp/string_search.js b/js/src/tests/js1_2/regexp/string_search.js new file mode 100644 index 000000000..93c786fbe --- /dev/null +++ b/js/src/tests/js1_2/regexp/string_search.js @@ -0,0 +1,55 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: string_search.js + Description: 'Tests the search method on Strings using regular expressions' + + Author: Nick Lerissa + Date: March 12, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'String: search'; + +writeHeaderToLog('Executing script: string_search.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 'abcdefg'.search(/d/) +new TestCase ( SECTION, "'abcdefg'.search(/d/)", + 3, 'abcdefg'.search(/d/)); + +// 'abcdefg'.search(/x/) +new TestCase ( SECTION, "'abcdefg'.search(/x/)", + -1, 'abcdefg'.search(/x/)); + +// 'abcdefg123456hijklmn'.search(/\d+/) +new TestCase ( SECTION, "'abcdefg123456hijklmn'.search(/\d+/)", + 7, 'abcdefg123456hijklmn'.search(/\d+/)); + +// 'abcdefg123456hijklmn'.search(new RegExp()) +new TestCase ( SECTION, "'abcdefg123456hijklmn'.search(new RegExp())", + 0, 'abcdefg123456hijklmn'.search(new RegExp())); + +// 'abc'.search(new RegExp('$')) +new TestCase ( SECTION, "'abc'.search(new RegExp('$'))", + 3, 'abc'.search(new RegExp('$'))); + +// 'abc'.search(new RegExp('^')) +new TestCase ( SECTION, "'abc'.search(new RegExp('^'))", + 0, 'abc'.search(new RegExp('^'))); + +// 'abc1'.search(/.\d/) +new TestCase ( SECTION, "'abc1'.search(/.\d/)", + 2, 'abc1'.search(/.\d/)); + +// 'abc1'.search(/\d{2}/) +new TestCase ( SECTION, "'abc1'.search(/\d{2}/)", + -1, 'abc1'.search(/\d{2}/)); + +test(); diff --git a/js/src/tests/js1_2/regexp/string_split.js b/js/src/tests/js1_2/regexp/string_split.js new file mode 100644 index 000000000..c810bff95 --- /dev/null +++ b/js/src/tests/js1_2/regexp/string_split.js @@ -0,0 +1,61 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: string_split.js + Description: 'Tests the split method on Strings using regular expressions' + + Author: Nick Lerissa + Date: March 11, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'String: split'; + +writeHeaderToLog('Executing script: string_split.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'a b c de f'.split(/\s/) +new TestCase ( SECTION, "'a b c de f'.split(/\s/)", + String(["a","b","c","de","f"]), String('a b c de f'.split(/\s/))); + +// 'a b c de f'.split(/\s/,3) +new TestCase ( SECTION, "'a b c de f'.split(/\s/,3)", + String(["a","b","c"]), String('a b c de f'.split(/\s/,3))); + +// 'a b c de f'.split(/X/) +new TestCase ( SECTION, "'a b c de f'.split(/X/)", + String(["a b c de f"]), String('a b c de f'.split(/X/))); + +// 'dfe23iu 34 =+65--'.split(/\d+/) +new TestCase ( SECTION, "'dfe23iu 34 =+65--'.split(/\d+/)", + String(["dfe","iu "," =+","--"]), String('dfe23iu 34 =+65--'.split(/\d+/))); + +// 'dfe23iu 34 =+65--'.split(new RegExp('\d+')) +new TestCase ( SECTION, "'dfe23iu 34 =+65--'.split(new RegExp('\\d+'))", + String(["dfe","iu "," =+","--"]), String('dfe23iu 34 =+65--'.split(new RegExp('\\d+')))); + +// 'abc'.split(/[a-z]/) +new TestCase ( SECTION, "'abc'.split(/[a-z]/)", + String(["","",""]), String('abc'.split(/[a-z]/))); + +// 'abc'.split(/[a-z]/) +new TestCase ( SECTION, "'abc'.split(/[a-z]/)", + String(["","",""]), String('abc'.split(/[a-z]/))); + +// 'abc'.split(new RegExp('[a-z]')) +new TestCase ( SECTION, "'abc'.split(new RegExp('[a-z]'))", + String(["","",""]), String('abc'.split(new RegExp('[a-z]')))); + +// 'abc'.split(new RegExp('[a-z]')) +new TestCase ( SECTION, "'abc'.split(new RegExp('[a-z]'))", + String(["","",""]), String('abc'.split(new RegExp('[a-z]')))); + +test(); diff --git a/js/src/tests/js1_2/regexp/test.js b/js/src/tests/js1_2/regexp/test.js new file mode 100644 index 000000000..588520eb4 --- /dev/null +++ b/js/src/tests/js1_2/regexp/test.js @@ -0,0 +1,55 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: test.js + Description: 'Tests regular expressions method compile' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: test'; + +writeHeaderToLog('Executing script: test.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +new TestCase ( SECTION, + "/[0-9]{3}/.test('23 2 34 678 9 09')", + true, /[0-9]{3}/.test('23 2 34 678 9 09')); + +new TestCase ( SECTION, + "/[0-9]{3}/.test('23 2 34 78 9 09')", + false, /[0-9]{3}/.test('23 2 34 78 9 09')); + +new TestCase ( SECTION, + "/\w+ \w+ \w+/.test('do a test')", + true, /\w+ \w+ \w+/.test("do a test")); + +new TestCase ( SECTION, + "/\w+ \w+ \w+/.test('a test')", + false, /\w+ \w+ \w+/.test("a test")); + +new TestCase ( SECTION, + "(new RegExp('[0-9]{3}')).test('23 2 34 678 9 09')", + true, (new RegExp('[0-9]{3}')).test('23 2 34 678 9 09')); + +new TestCase ( SECTION, + "(new RegExp('[0-9]{3}')).test('23 2 34 78 9 09')", + false, (new RegExp('[0-9]{3}')).test('23 2 34 78 9 09')); + +new TestCase ( SECTION, + "(new RegExp('\\\\w+ \\\\w+ \\\\w+')).test('do a test')", + true, (new RegExp('\\w+ \\w+ \\w+')).test("do a test")); + +new TestCase ( SECTION, + "(new RegExp('\\\\w+ \\\\w+ \\\\w+')).test('a test')", + false, (new RegExp('\\w+ \\w+ \\w+')).test("a test")); + +test(); diff --git a/js/src/tests/js1_2/regexp/toString.js b/js/src/tests/js1_2/regexp/toString.js new file mode 100644 index 000000000..e6b6cc883 --- /dev/null +++ b/js/src/tests/js1_2/regexp/toString.js @@ -0,0 +1,47 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: toString.js + Description: 'Tests RegExp method toString' + + Author: Nick Lerissa + Date: March 13, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: toString'; + +writeHeaderToLog('Executing script: toString.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +/* + * var re = new RegExp(); re.toString() For what to expect, + * see http://bugzilla.mozilla.org/show_bug.cgi?id=225343#c7 + */ +var re = new RegExp(); +new TestCase ( SECTION, "var re = new RegExp(); re.toString()", + '/(?:)/', re.toString()); + +// re = /.+/; re.toString(); +re = /.+/; +new TestCase ( SECTION, "re = /.+/; re.toString()", + '/.+/', re.toString()); + +// re = /test/gi; re.toString() +re = /test/gi; +new TestCase ( SECTION, "re = /test/gi; re.toString()", + '/test/gi', re.toString()); + +// re = /test2/ig; re.toString() +re = /test2/ig; +new TestCase ( SECTION, "re = /test2/ig; re.toString()", + '/test2/gi', re.toString()); + +test(); diff --git a/js/src/tests/js1_2/regexp/vertical_bar.js b/js/src/tests/js1_2/regexp/vertical_bar.js new file mode 100644 index 000000000..636f1c9cf --- /dev/null +++ b/js/src/tests/js1_2/regexp/vertical_bar.js @@ -0,0 +1,64 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: vertical_bar.js + Description: 'Tests regular expressions containing |' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: |'; + +writeHeaderToLog('Executing script: vertical_bar.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'abc'.match(new RegExp('xyz|abc')) +new TestCase ( SECTION, "'abc'.match(new RegExp('xyz|abc'))", + String(["abc"]), String('abc'.match(new RegExp('xyz|abc')))); + +// 'this is a test'.match(new RegExp('quiz|exam|test|homework')) +new TestCase ( SECTION, "'this is a test'.match(new RegExp('quiz|exam|test|homework'))", + String(["test"]), String('this is a test'.match(new RegExp('quiz|exam|test|homework')))); + +// 'abc'.match(new RegExp('xyz|...')) +new TestCase ( SECTION, "'abc'.match(new RegExp('xyz|...'))", + String(["abc"]), String('abc'.match(new RegExp('xyz|...')))); + +// 'abc'.match(new RegExp('(.)..|abc')) +new TestCase ( SECTION, "'abc'.match(new RegExp('(.)..|abc'))", + String(["abc","a"]), String('abc'.match(new RegExp('(.)..|abc')))); + +// 'color: grey'.match(new RegExp('.+: gr(a|e)y')) +new TestCase ( SECTION, "'color: grey'.match(new RegExp('.+: gr(a|e)y'))", + String(["color: grey","e"]), String('color: grey'.match(new RegExp('.+: gr(a|e)y')))); + +// 'no match'.match(new RegExp('red|white|blue')) +new TestCase ( SECTION, "'no match'.match(new RegExp('red|white|blue'))", + null, 'no match'.match(new RegExp('red|white|blue'))); + +// 'Hi Bob'.match(new RegExp('(Rob)|(Bob)|(Robert)|(Bobby)')) +new TestCase ( SECTION, "'Hi Bob'.match(new RegExp('(Rob)|(Bob)|(Robert)|(Bobby)'))", + String(["Bob",undefined,"Bob", undefined, undefined]), String('Hi Bob'.match(new RegExp('(Rob)|(Bob)|(Robert)|(Bobby)')))); + +// 'abcdef'.match(new RegExp('abc|bcd|cde|def')) +new TestCase ( SECTION, "'abcdef'.match(new RegExp('abc|bcd|cde|def'))", + String(["abc"]), String('abcdef'.match(new RegExp('abc|bcd|cde|def')))); + +// 'Hi Bob'.match(/(Rob)|(Bob)|(Robert)|(Bobby)/) +new TestCase ( SECTION, "'Hi Bob'.match(/(Rob)|(Bob)|(Robert)|(Bobby)/)", + String(["Bob",undefined,"Bob", undefined, undefined]), String('Hi Bob'.match(/(Rob)|(Bob)|(Robert)|(Bobby)/))); + +// 'abcdef'.match(/abc|bcd|cde|def/) +new TestCase ( SECTION, "'abcdef'.match(/abc|bcd|cde|def/)", + String(["abc"]), String('abcdef'.match(/abc|bcd|cde|def/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/whitespace.js b/js/src/tests/js1_2/regexp/whitespace.js new file mode 100644 index 000000000..ab99b59d5 --- /dev/null +++ b/js/src/tests/js1_2/regexp/whitespace.js @@ -0,0 +1,91 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: whitespace.js + Description: 'Tests regular expressions containing \f\n\r\t\v\s\S\ ' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: \\f\\n\\r\\t\\v\\s\\S '; + +writeHeaderToLog('Executing script: whitespace.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +var non_whitespace = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()-+={[}]|\\:;'<,>./?1234567890" + '"'; +var whitespace = "\f\n\r\t\v "; + +// be sure all whitespace is matched by \s +new TestCase ( SECTION, + "'" + whitespace + "'.match(new RegExp('\\s+'))", + String([whitespace]), String(whitespace.match(new RegExp('\\s+')))); + +// be sure all non-whitespace is matched by \S +new TestCase ( SECTION, + "'" + non_whitespace + "'.match(new RegExp('\\S+'))", + String([non_whitespace]), String(non_whitespace.match(new RegExp('\\S+')))); + +// be sure all non-whitespace is not matched by \s +new TestCase ( SECTION, + "'" + non_whitespace + "'.match(new RegExp('\\s'))", + null, non_whitespace.match(new RegExp('\\s'))); + +// be sure all whitespace is not matched by \S +new TestCase ( SECTION, + "'" + whitespace + "'.match(new RegExp('\\S'))", + null, whitespace.match(new RegExp('\\S'))); + +var s = non_whitespace + whitespace; + +// be sure all digits are matched by \s +new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\s+'))", + String([whitespace]), String(s.match(new RegExp('\\s+')))); + +s = whitespace + non_whitespace; + +// be sure all non-whitespace are matched by \S +new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\S+'))", + String([non_whitespace]), String(s.match(new RegExp('\\S+')))); + +// '1233345find me345'.match(new RegExp('[a-z\\s][a-z\\s]+')) +new TestCase ( SECTION, "'1233345find me345'.match(new RegExp('[a-z\\s][a-z\\s]+'))", + String(["find me"]), String('1233345find me345'.match(new RegExp('[a-z\\s][a-z\\s]+')))); + +var i; + +// be sure all whitespace characters match individually +for (i = 0; i < whitespace.length; ++i) +{ + s = 'ab' + whitespace[i] + 'cd'; + new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\\\s'))", + String([whitespace[i]]), String(s.match(new RegExp('\\s')))); + new TestCase ( SECTION, + "'" + s + "'.match(/\s/)", + String([whitespace[i]]), String(s.match(/\s/))); +} +// be sure all non_whitespace characters match individually +for (i = 0; i < non_whitespace.length; ++i) +{ + s = ' ' + non_whitespace[i] + ' '; + new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\\\S'))", + String([non_whitespace[i]]), String(s.match(new RegExp('\\S')))); + new TestCase ( SECTION, + "'" + s + "'.match(/\S/)", + String([non_whitespace[i]]), String(s.match(/\S/))); +} + + +test(); diff --git a/js/src/tests/js1_2/regexp/word_boundary.js b/js/src/tests/js1_2/regexp/word_boundary.js new file mode 100644 index 000000000..ca96081f8 --- /dev/null +++ b/js/src/tests/js1_2/regexp/word_boundary.js @@ -0,0 +1,87 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: word_boundary.js + Description: 'Tests regular expressions containing \b and \B' + + Author: Nick Lerissa + Date: March 10, 1998 +*/ + +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; +var VERSION = 'no version'; +startTest(); +var TITLE = 'RegExp: \\b and \\B'; + +writeHeaderToLog('Executing script: word_boundary.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'cowboy boyish boy'.match(new RegExp('\bboy\b')) +new TestCase ( SECTION, "'cowboy boyish boy'.match(new RegExp('\\bboy\\b'))", + String(["boy"]), String('cowboy boyish boy'.match(new RegExp('\\bboy\\b')))); + +var boundary_characters = "\f\n\r\t\v~`!@#$%^&*()-+={[}]|\\:;'<,>./? " + '"'; +var non_boundary_characters = '1234567890_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; +var s = ''; +var i; + +// testing whether all boundary characters are matched when they should be +for (i = 0; i < boundary_characters.length; ++i) +{ + s = '123ab' + boundary_characters.charAt(i) + '123c' + boundary_characters.charAt(i); + + new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\b123[a-z]\\b'))", + String(["123c"]), String(s.match(new RegExp('\\b123[a-z]\\b')))); +} + +// testing whether all non-boundary characters are matched when they should be +for (i = 0; i < non_boundary_characters.length; ++i) +{ + s = '123ab' + non_boundary_characters.charAt(i) + '123c' + non_boundary_characters.charAt(i); + + new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\B123[a-z]\\B'))", + String(["123c"]), String(s.match(new RegExp('\\B123[a-z]\\B')))); +} + +s = ''; + +// testing whether all boundary characters are not matched when they should not be +for (i = 0; i < boundary_characters.length; ++i) +{ + s += boundary_characters[i] + "a" + i + "b"; +} +s += "xa1111bx"; + +new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\Ba\\d+b\\B'))", + String(["a1111b"]), String(s.match(new RegExp('\\Ba\\d+b\\B')))); + +new TestCase ( SECTION, + "'" + s + "'.match(/\\Ba\\d+b\\B/)", + String(["a1111b"]), String(s.match(/\Ba\d+b\B/))); + +s = ''; + +// testing whether all non-boundary characters are not matched when they should not be +for (i = 0; i < non_boundary_characters.length; ++i) +{ + s += non_boundary_characters[i] + "a" + i + "b"; +} +s += "(a1111b)"; + +new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\ba\\d+b\\b'))", + String(["a1111b"]), String(s.match(new RegExp('\\ba\\d+b\\b')))); + +new TestCase ( SECTION, + "'" + s + "'.match(/\\ba\\d+b\\b/)", + String(["a1111b"]), String(s.match(/\ba\d+b\b/))); + +test(); |