- refactor regex handling for the different usecases to allow providing the preferred method
- introduce new `exec` and `execAll` variants which support named groups - introduce `replaceAll` in addition to `replace` - update test cases - cleanup code
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { transformStringToValue, validateRegex } from '../src/pr-collector/regexUtils'
|
||||
import { Regex } from '../src/pr-collector/types'
|
||||
|
||||
jest.setTimeout(180000)
|
||||
|
||||
it('Replace into target', async () => {
|
||||
const regex: Regex = {
|
||||
pattern: '.*(\\[Feature\\]|\\[Issue\\]).*',
|
||||
target: '$1',
|
||||
}
|
||||
const validatedRegex = validateRegex(regex)
|
||||
expect(validateRegex).not.toBeNull()
|
||||
expect(transformStringToValue("[Feature] TEST", validatedRegex!!)).toStrictEqual(`[Feature]`)
|
||||
})
|
||||
|
||||
it('Replace all into target', async () => {
|
||||
const regex: Regex = {
|
||||
pattern: '.*(\\[Feature\\]|\\[Issue\\]).*',
|
||||
method: 'replaceAll',
|
||||
target: '$1',
|
||||
}
|
||||
const validatedRegex = validateRegex(regex)
|
||||
expect(validateRegex).not.toBeNull()
|
||||
expect(transformStringToValue("[Feature] TEST", validatedRegex!!)).toStrictEqual(`[Feature]`)
|
||||
})
|
||||
|
||||
it('Match without target', async () => {
|
||||
const regex: Regex = {
|
||||
pattern: '\\[Feature\\]|\\[Issue\\]',
|
||||
method: 'match'
|
||||
}
|
||||
const validatedRegex = validateRegex(regex)
|
||||
expect(validateRegex).not.toBeNull()
|
||||
expect(transformStringToValue("[Feature] TEST", validatedRegex!!)).toStrictEqual(`[Feature]`)
|
||||
})
|
||||
|
||||
it('Match into target', async () => {
|
||||
const regex: Regex = {
|
||||
pattern: '(?<label>\\[Feature\\]|\\[Issue\\])',
|
||||
method: 'match',
|
||||
target: '$1',
|
||||
}
|
||||
const validatedRegex = validateRegex(regex)
|
||||
expect(validateRegex).not.toBeNull()
|
||||
expect(transformStringToValue("[Feature] TEST", validatedRegex!!)).toStrictEqual(`[Feature]`)
|
||||
})
|
||||
|
||||
it('Match into named group', async () => {
|
||||
const regex: Regex = {
|
||||
pattern: '(?<label>\\[Feature\\]|\\[Issue\\])',
|
||||
method: 'match',
|
||||
target: 'label',
|
||||
}
|
||||
const validatedRegex = validateRegex(regex)
|
||||
expect(validateRegex).not.toBeNull()
|
||||
expect(transformStringToValue("[Feature] TEST", validatedRegex!!)).toStrictEqual(`[Feature]`)
|
||||
})
|
||||
Reference in New Issue
Block a user