From 9b1020c20be804c88fe56eac8bd5f65aad87de2b Mon Sep 17 00:00:00 2001 From: Flavio Di Natale Date: Tue, 8 Oct 2024 00:32:59 +0200 Subject: [PATCH] expand regex to parse / grades --- src/__tests__/scales/polish.ts | 8 +++++++- src/scales/polish.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/__tests__/scales/polish.ts b/src/__tests__/scales/polish.ts index af423cc..71068ee 100644 --- a/src/__tests__/scales/polish.ts +++ b/src/__tests__/scales/polish.ts @@ -2,13 +2,19 @@ import { Polish } from '../../scales' describe('Polish', () => { - describe('isPolish', () => { + describe('isType', () => { test('VI is a valid grade', () => { expect(Polish.isType('VI')).toBe(true) }) test('asd is not a valid grade', () => { expect(Polish.isType('asd')).toBe(false) }) + test('VI+/VI.1 is a valid slash grade', () => { + expect(Polish.isType('VI+/VI.1')).toBe(true) + }) + test('VI+/VI.1+ is not a valid slash grade', () => { + expect(Polish.isType('VI+/VI.1')).toBe(false) + }) }) // describe('Get Score', () => { // test('9a > 5c', () => { diff --git a/src/scales/polish.ts b/src/scales/polish.ts index a8d8e87..539b169 100644 --- a/src/scales/polish.ts +++ b/src/scales/polish.ts @@ -3,7 +3,7 @@ import routes from '../data/routes.json' import { Route } from '.' import { GradeBandTypes, routeScoreToBand } from '../GradeBands' -const polishGradeRegex = /^((I{1,3})|(IV\+?)|(V[+,-]?)|(VI(.[1-9])?\+?))?$/i +const polishGradeRegex = /^((?:I{1,3})|(?:IV[+]?)|(?:V[+,-]?)|(?:VI(?:\.[1-9])?[+]?)){1}(?:(\/)((?:I{1,3})|(?:IV[+]?)|(?:V[+,-]?)|(?:VI(?:\.[1-9])?[+]?)))?$/i const isPolish = (grade: string): RegExpMatchArray | null => grade.match(polishGradeRegex) const PolishScale: GradeScale = {