1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2013 the V8 project authors. All rights reserved. 2b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// 4b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Redistribution and use in source and binary forms, with or without 5b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// modification, are permitted provided that the following conditions 6b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// are met: 7b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// 1. Redistributions of source code must retain the above copyright 8b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// notice, this list of conditions and the following disclaimer. 9b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// 2. Redistributions in binary form must reproduce the above copyright 10b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// notice, this list of conditions and the following disclaimer in the 11b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// documentation and/or other materials provided with the distribution. 12b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// 13b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 14b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 24b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochdescription( 25b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch'Test RegExp.compile method.' 26b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch); 27b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 28b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochre = new RegExp("a", "i"); 29b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.toString()", "'/a/i'"); 30b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 31b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochre.compile("a"); 32b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.multiline", "false"); 33b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.ignoreCase", "false"); 34b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.global", "false"); 35b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.test('A')", "false"); 36b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.toString()", "'/a/'"); 37b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 38b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochre.compile("b", "g"); 39b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.toString()", "'/b/g'"); 40b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 41b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochre.compile(new RegExp("c")); 42b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.toString()", "'/c/'"); 43b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochre.compile(new RegExp("c", "i")); 45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.ignoreCase", "true"); 46b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.test('C')", "true"); 47b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.toString()", "'/c/i'"); 48b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 49b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldThrow("re.compile(new RegExp('c'), 'i');"); 50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// It's OK to supply a second argument, as long as the argument is "undefined". 52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochre.compile(re, undefined); 53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.toString()", "'/c/i'"); 54b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 55b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldThrow("re.compile(new RegExp('+'));"); 56b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 57b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochre.compile(undefined); 58014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochshouldBe("re.toString()", "'/(?:)/'"); 59b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 60b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochre.compile(null); 61b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.toString()", "'/null/'"); 62b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 63b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochre.compile(); 64b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.toString()", "'/(?:)/'"); 65b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 66b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochre.compile("z", undefined); 67b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.toString()", "'/z/'"); 68b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 69b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Compiling should reset lastIndex. 70b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochre.lastIndex = 100; 71b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochre.compile(/a/g); 72b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.lastIndex", "0"); 73b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochre.exec("aaa"); 74b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochshouldBe("re.lastIndex", "1"); 75