Skip to content

Commit

Permalink
Wrote test cases for version regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedictteo05 committed Dec 4, 2024
1 parent 60f38d5 commit 430a6fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/utils/reg.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BOOK_REG, MODAL_REG } from './regs'
import { BOOK_REG, MODAL_REG, VERSION_REG } from './regs'

describe('test book name reg matching in different languages', () => {
test('should match book name in English', () => {
Expand Down Expand Up @@ -74,4 +74,23 @@ describe('test modal reg matching in different languages', () => {
const reg = new RegExp(MODAL_REG)
expect(reg.test(modal)).toBe(false)
})

test('should match version with only alphabets', () => {
const modal = '-niv2011'
const reg = new RegExp(VERSION_REG)
expect(reg.test(modal)).toBe(true)
})

test('should match version with numbers', () => {
const modal = '-niv2011'
const reg = new RegExp(VERSION_REG)
expect(reg.test(modal)).toBe(true)
})

test('should not match when there is hyphen', () => {
const modal = '-should-fail'
const reg = new RegExp(MODAL_REG)
expect(reg.test(modal)).toBe(false)
})

})
2 changes: 1 addition & 1 deletion src/utils/regs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const MODAL_REG = /([123])*\s*([\p{L}[\\\]^_`a-zA-Z]{2,100}|\p{Script=Han

export const BOOK_REG = /([123])*\s*([\p{L}[\\\]^_`a-zA-Z]{2,100}|\p{Script=Han}{1,})/isu

export const VERSION_REG = /(-[a-zA-Z0-9-]+)$/isu
export const VERSION_REG = /(-[a-zA-Z0-9]+)$/isu

// export const BOOK_REG = /[123]*\s*[A-Z\[\\\]^_`a-z]{2,}/

Expand Down

0 comments on commit 430a6fb

Please sign in to comment.