|
1 |
| -import { sanitizeText, removeScript, parseGenericTypes } from './common.js'; |
| 1 | +import { sanitizeText, removeScript, parseGenericTypes, countOccurrence } from './common.js'; |
2 | 2 |
|
3 | 3 | describe('when securityLevel is antiscript, all script must be removed', () => {
|
4 | 4 | /**
|
@@ -59,15 +59,29 @@ describe('Sanitize text', () => {
|
59 | 59 | });
|
60 | 60 |
|
61 | 61 | describe('generic parser', () => {
|
62 |
| - it('should parse generic types', () => { |
63 |
| - expect(parseGenericTypes('test~T~')).toEqual('test<T>'); |
64 |
| - expect(parseGenericTypes('test~Array~Array~string~~~')).toEqual('test<Array<Array<string>>>'); |
65 |
| - expect(parseGenericTypes('test~Array~Array~string[]~~~')).toEqual( |
66 |
| - 'test<Array<Array<string[]>>>' |
67 |
| - ); |
68 |
| - expect(parseGenericTypes('test ~Array~Array~string[]~~~')).toEqual( |
69 |
| - 'test <Array<Array<string[]>>>' |
70 |
| - ); |
71 |
| - expect(parseGenericTypes('~test')).toEqual('~test'); |
| 62 | + it.each([ |
| 63 | + ['test~T~', 'test<T>'], |
| 64 | + ['test~Array~Array~string~~~', 'test<Array<Array<string>>>'], |
| 65 | + ['test~Array~Array~string[]~~~', 'test<Array<Array<string[]>>>'], |
| 66 | + ['test ~Array~Array~string[]~~~', 'test <Array<Array<string[]>>>'], |
| 67 | + ['~test', '~test'], |
| 68 | + ['~test~T~', '~test<T>'], |
| 69 | + ])('should parse generic types: %s to %s', (input: string, expected: string) => { |
| 70 | + expect(parseGenericTypes(input)).toEqual(expected); |
72 | 71 | });
|
73 | 72 | });
|
| 73 | + |
| 74 | +it.each([ |
| 75 | + ['', '', 0], |
| 76 | + ['', 'x', 0], |
| 77 | + ['test', 'x', 0], |
| 78 | + ['test', 't', 2], |
| 79 | + ['test', 'te', 1], |
| 80 | + ['test~T~', '~', 2], |
| 81 | + ['test~Array~Array~string~~~', '~', 6], |
| 82 | +])( |
| 83 | + 'should count `%s` to contain occurrences of `%s` to be `%i`', |
| 84 | + (str: string, substring: string, count: number) => { |
| 85 | + expect(countOccurrence(str, substring)).toEqual(count); |
| 86 | + } |
| 87 | +); |
0 commit comments