- 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]`)
|
||||
})
|
||||
+12
-7
@@ -1,4 +1,5 @@
|
||||
import { validateTransformer } from '../src/pr-collector/regexUtils'
|
||||
import { TagResolver } from '../src/configuration'
|
||||
import { validateRegex } from '../src/pr-collector/regexUtils'
|
||||
import {filterTags, prepareAndSortTags, TagInfo, transformTags} from '../src/pr-collector/tags'
|
||||
|
||||
jest.setTimeout(180000)
|
||||
@@ -100,14 +101,16 @@ it('Should filter tags correctly using the regex', async () => {
|
||||
{name: '20.0.2', commit: ''}
|
||||
]
|
||||
|
||||
const tagResolver = {
|
||||
const tagResolver: TagResolver = {
|
||||
method: 'non-existing-method',
|
||||
filter: {
|
||||
pattern: 'api-(.+)',
|
||||
method: 'match',
|
||||
flags: 'gu'
|
||||
}
|
||||
}
|
||||
const filtered = filterTags(tags, tagResolver)
|
||||
const filter = validateRegex(tagResolver.filter)
|
||||
const filtered = filterTags(tags, filter)
|
||||
.map(function (tag) {
|
||||
return tag.name
|
||||
})
|
||||
@@ -131,14 +134,16 @@ it('Should filter tags correctly using the regex (inverse)', async () => {
|
||||
{name: '20.0.2', commit: ''}
|
||||
]
|
||||
|
||||
const tagResolver = {
|
||||
const tagResolver: TagResolver = {
|
||||
method: 'non-existing-method',
|
||||
filter: {
|
||||
pattern: '^(?!\\w+-)(.+)',
|
||||
method: 'match',
|
||||
flags: 'gu'
|
||||
}
|
||||
}
|
||||
const filtered = filterTags(tags, tagResolver)
|
||||
const filter = validateRegex(tagResolver.filter)
|
||||
const filtered = filterTags(tags, filter)
|
||||
.map(function (tag) {
|
||||
return tag.name
|
||||
})
|
||||
@@ -160,7 +165,7 @@ it('Should transform tags correctly using the regex', async () => {
|
||||
{name: '20.0.2', commit: ''}
|
||||
]
|
||||
|
||||
const tagResolver = {
|
||||
const tagResolver: TagResolver = {
|
||||
method: 'non-existing-method',
|
||||
transformer: {
|
||||
pattern: '(api\-)?(.+)',
|
||||
@@ -168,7 +173,7 @@ it('Should transform tags correctly using the regex', async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const transformer = validateTransformer(tagResolver.transformer)
|
||||
const transformer = validateRegex(tagResolver.transformer)
|
||||
if(transformer != null) {
|
||||
const transformed = transformTags(tags, transformer)
|
||||
.map(function (tag) {
|
||||
|
||||
Reference in New Issue
Block a user