| 
									
										
										
										
											2021-05-11 22:47:14 +01:00
										 |  |  | describe("errors", () => { | 
					
						
							|  |  |  |     test("invalid pattern", () => { | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             RegExp("["); | 
					
						
							|  |  |  |         }).toThrowWithMessage( | 
					
						
							|  |  |  |             SyntaxError, | 
					
						
							|  |  |  |             "RegExp compile error: Error during parsing of regular expression:" | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test("invalid flag", () => { | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             RegExp("", "x"); | 
					
						
							|  |  |  |         }).toThrowWithMessage(SyntaxError, "Invalid RegExp flag 'x'"); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test("repeated flag", () => { | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             RegExp("", "gg"); | 
					
						
							|  |  |  |         }).toThrowWithMessage(SyntaxError, "Repeated RegExp flag 'g'"); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-27 22:42:41 +00:00
										 |  |  | test("basic functionality", () => { | 
					
						
							| 
									
										
										
										
											2020-11-27 23:42:58 +00:00
										 |  |  |     expect(RegExp().toString()).toBe("/(?:)/"); | 
					
						
							|  |  |  |     expect(RegExp(undefined).toString()).toBe("/(?:)/"); | 
					
						
							| 
									
										
										
										
											2020-11-27 22:42:41 +00:00
										 |  |  |     expect(RegExp("foo").toString()).toBe("/foo/"); | 
					
						
							|  |  |  |     expect(RegExp("foo", undefined).toString()).toBe("/foo/"); | 
					
						
							|  |  |  |     expect(RegExp("foo", "g").toString()).toBe("/foo/g"); | 
					
						
							| 
									
										
										
										
											2020-11-27 23:42:58 +00:00
										 |  |  |     expect(RegExp(undefined, "g").toString()).toBe("/(?:)/g"); | 
					
						
							| 
									
										
										
										
											2020-11-27 22:42:41 +00:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-07-08 13:36:09 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | test("regexp object as pattern parameter", () => { | 
					
						
							|  |  |  |     expect(RegExp(/foo/).toString()).toBe("/foo/"); | 
					
						
							|  |  |  |     expect(RegExp(/foo/g).toString()).toBe("/foo/g"); | 
					
						
							|  |  |  |     expect(RegExp(/foo/g, "").toString()).toBe("/foo/"); | 
					
						
							|  |  |  |     expect(RegExp(/foo/g, "y").toString()).toBe("/foo/y"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var regex_like_object_without_flags = { | 
					
						
							|  |  |  |         source: "foo", | 
					
						
							|  |  |  |         [Symbol.match]: function () {}, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     expect(RegExp(regex_like_object_without_flags).toString()).toBe("/foo/"); | 
					
						
							|  |  |  |     expect(RegExp(regex_like_object_without_flags, "y").toString()).toBe("/foo/y"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var regex_like_object_with_flags = { | 
					
						
							|  |  |  |         source: "foo", | 
					
						
							|  |  |  |         flags: "g", | 
					
						
							|  |  |  |         [Symbol.match]: function () {}, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     expect(RegExp(regex_like_object_with_flags).toString()).toBe("/foo/g"); | 
					
						
							|  |  |  |     expect(RegExp(regex_like_object_with_flags, "").toString()).toBe("/foo/"); | 
					
						
							|  |  |  |     expect(RegExp(regex_like_object_with_flags, "y").toString()).toBe("/foo/y"); | 
					
						
							|  |  |  | }); |