| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const { itemsToRegexp } = require("../lib/util/compileBooleanMatcher"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | describe("itemsToRegexp", () => { | 
					
						
							|  |  |  | 	const expectCompiled = (name, input, fn) => { | 
					
						
							|  |  |  | 		it(`should compile ${name}`, () => { | 
					
						
							|  |  |  | 			const items = typeof input === "string" ? input.split(",") : input; | 
					
						
							|  |  |  | 			const regexp = itemsToRegexp(items); | 
					
						
							|  |  |  | 			const r = new RegExp(`^${regexp}$`); | 
					
						
							|  |  |  | 			for (const item of items) { | 
					
						
							|  |  |  | 				expect(item).toMatch(r); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			fn(expect(regexp)); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	expect.addSnapshotSerializer({ | 
					
						
							|  |  |  | 		test() { | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		print(received) { | 
					
						
							|  |  |  | 			return received; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	expectCompiled("basic", ["abc", "def", "123", "45", "6"], (e) => | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 		e.toMatchInlineSnapshot("(123|45|6|abc|def)") | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	expectCompiled("single chars", ["a", "b", "c", "1", "2", "3"], (e) => | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 		e.toMatchInlineSnapshot("[123abc]") | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	expectCompiled( | 
					
						
							|  |  |  | 		"prefixes", | 
					
						
							|  |  |  | 		["ab1", "ab2", "ab3", "ab4", "de5", "de6", "de7", "ef8", "ef9", "gh0"], | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		(e) => e.toMatchInlineSnapshot("(ab[1234]|de[567]|ef[89]|gh0)") | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	expectCompiled("short prefixes", "a,ab", (e) => | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 		e.toMatchInlineSnapshot("a(|b)") | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	expectCompiled( | 
					
						
							|  |  |  | 		"nested prefixes", | 
					
						
							|  |  |  | 		["a", "ab", "abc", "abcd", "abcde", "abcdef"], | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		(e) => e.toMatchInlineSnapshot("a(b(c(d(|e|ef)|)|)|)") | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	expectCompiled("suffixes", "a1,b1,c1,d1,e1,a2,b2,c2", (e) => | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 		e.toMatchInlineSnapshot("([abcde]1|[abc]2)") | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	expectCompiled( | 
					
						
							|  |  |  | 		"common prod", | 
					
						
							|  |  |  | 		"674,542,965,12,942,483,445,943,423,995,434,122,995,248,432,165,436,86,435,221", | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		(e) => | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 			e.toMatchInlineSnapshot( | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 				"(1(2|22|65)|4(3[2456]|23|45|83)|9(42|43|65|95)|221|248|542|674|86)" | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 			) | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	expectCompiled( | 
					
						
							|  |  |  | 		"long strings", | 
					
						
							|  |  |  | 		[ | 
					
						
							|  |  |  | 			"./path/to/file.js", | 
					
						
							|  |  |  | 			"./path/to/file.mjs", | 
					
						
							|  |  |  | 			"./path/to/other-file.js", | 
					
						
							|  |  |  | 			"./path/to/directory/with/file.js", | 
					
						
							|  |  |  | 			"./path/to/directory/with/file.json", | 
					
						
							|  |  |  | 			"./path/to/directory/with/file.css", | 
					
						
							|  |  |  | 			"./path/to/directory/with/module.css", | 
					
						
							|  |  |  | 			"webpack/runtime/module" | 
					
						
							|  |  |  | 		], | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		(e) => | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 			e.toMatchInlineSnapshot( | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 				"(\\.\\/path\\/to\\/(directory\\/with\\/(file\\.(js(|on)|css)|module\\.css)|file\\.(|m)js|other\\-file\\.js)|webpack\\/runtime\\/module)" | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 			) | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2020-12-22 19:29:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	expectCompiled( | 
					
						
							|  |  |  | 		"prefix and suffix overlap", | 
					
						
							|  |  |  | 		[ | 
					
						
							|  |  |  | 			"webpack_sharing_consume_default_react_react", | 
					
						
							|  |  |  | 			"webpack_sharing_consume_default_classnames_classnames-webpack_sharing_consume_default_react_react" | 
					
						
							|  |  |  | 		], | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		(e) => | 
					
						
							| 
									
										
										
										
											2020-12-22 19:29:08 +08:00
										 |  |  | 			e.toMatchInlineSnapshot( | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 				"webpack_sharing_consume_default_(|classnames_classnames\\-webpack_sharing_consume_default_)react_react" | 
					
						
							| 
									
										
										
										
											2020-12-22 19:29:08 +08:00
										 |  |  | 			) | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | }); |