* feat(new tool): Regex Tester Fix https://github.com/CorentinTh/it-tools/issues/1007, https://github.com/CorentinTh/it-tools/issues/991, https://github.com/CorentinTh/it-tools/issues/936, https://github.com/CorentinTh/it-tools/issues/761, https://github.com/CorentinTh/it-tools/issues/649 https://github.com/CorentinTh/it-tools/issues/644, https://github.com/CorentinTh/it-tools/issues/554 https://github.com/CorentinTh/it-tools/issues/308 * fix: refactor to service + add regex diagram + ui enhancements * fix: update queryParams * fix: deps * fix: svg style bug in @regexper/render @regexper/render use a stylesheet in svg that cause bugs in whole site. So add regexper in a shadow root * feat(new tool): added Regex Cheatsheet * Update src/tools/regex-memo/index.ts * Update src/tools/regex-tester/index.ts --------- Co-authored-by: Corentin THOMASSET <corentin.thomasset74@gmail.com>
		
			
				
	
	
		
			107 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			107 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { describe, expect, it } from 'vitest';
 | |
| import { matchRegex } from './regex-tester.service';
 | |
| 
 | |
| const regexesData = [
 | |
|   {
 | |
|     regex: '',
 | |
|     text: '',
 | |
|     flags: '',
 | |
|     result: [],
 | |
|   },
 | |
|   {
 | |
|     regex: '.*',
 | |
|     text: '',
 | |
|     flags: '',
 | |
|     result: [],
 | |
|   },
 | |
|   {
 | |
|     regex: '',
 | |
|     text: 'aaa',
 | |
|     flags: '',
 | |
|     result: [],
 | |
|   },
 | |
|   {
 | |
|     regex: 'a',
 | |
|     text: 'baaa',
 | |
|     flags: '',
 | |
|     result: [
 | |
|       {
 | |
|         captures: [],
 | |
|         groups: [],
 | |
|         index: 1,
 | |
|         value: 'a',
 | |
|       },
 | |
|     ],
 | |
|   },
 | |
|   {
 | |
|     regex: '(.)(?<g>r)',
 | |
|     text: 'azertyr',
 | |
|     flags: 'g',
 | |
|     result: [
 | |
|       {
 | |
|         captures: [
 | |
|           {
 | |
|             end: 3,
 | |
|             name: '1',
 | |
|             start: 2,
 | |
|             value: 'e',
 | |
|           },
 | |
|           {
 | |
|             end: 4,
 | |
|             name: '2',
 | |
|             start: 3,
 | |
|             value: 'r',
 | |
|           },
 | |
|         ],
 | |
|         groups: [
 | |
|           {
 | |
|             end: 4,
 | |
|             name: 'g',
 | |
|             start: 3,
 | |
|             value: 'r',
 | |
|           },
 | |
|         ],
 | |
|         index: 2,
 | |
|         value: 'er',
 | |
|       },
 | |
|       {
 | |
|         captures: [
 | |
|           {
 | |
|             end: 6,
 | |
|             name: '1',
 | |
|             start: 5,
 | |
|             value: 'y',
 | |
|           },
 | |
|           {
 | |
|             end: 7,
 | |
|             name: '2',
 | |
|             start: 6,
 | |
|             value: 'r',
 | |
|           },
 | |
|         ],
 | |
|         groups: [
 | |
|           {
 | |
|             end: 7,
 | |
|             name: 'g',
 | |
|             start: 6,
 | |
|             value: 'r',
 | |
|           },
 | |
|         ],
 | |
|         index: 5,
 | |
|         value: 'yr',
 | |
|       },
 | |
|     ],
 | |
|   },
 | |
| ];
 | |
| 
 | |
| describe('regex-tester', () => {
 | |
|   for (const reg of regexesData) {
 | |
|     const { regex, text, flags, result: expected_result } = reg;
 | |
|     it(`Should matchRegex("${regex}","${text}","${flags}") return correct result`, async () => {
 | |
|       const result = matchRegex(regex, text, `${flags}d`);
 | |
| 
 | |
|       expect(result).to.deep.equal(expected_result);
 | |
|     });
 | |
|   }
 | |
| });
 |