Skip to content

Commit

Permalink
Fix a bug with Drop Notation parsing (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxjrvs authored Jul 8, 2024
1 parent 2fc112f commit 3afd9f0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "randsum",
"version": "4.3.1",
"version": "4.3.2",
"private": false,
"author": "Alex Jarvis",
"icon": "https://raw.githubusercontent.com/RANDSUM/randsum-ts/main/icon.webp",
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const coreNotationPattern = /(?<coreNotationMatch>^\d+[Dd](\d+|{.*}))/
export const modifierRollPatterns =
/(?<dropHighMatch>[Hh]\d*)|(?<dropLowMatch>[Ll]\d*)|(?<dropConstraintsMatch>[Dd]{?([<>|]?\d+,?)*}?)|(?<explodeMatch>!+{?([<>|]?\d+,?)*}?)|(?<uniqueMatch>[Uu]({(\d+,?)+})?)|(?<replaceMatch>[Vv]{?([<>|]?\d+=?\d+,?)*}?)|(?<rerollMatch>[Rr]{?([<>|]?\d,?)*}\d*)|(?<capMatch>[Cc]([<>|]?\d+)*)|(?<plusMatch>\+\d+)|(?<minusMatch>-\d+)/
/(?<dropHighMatch>[Hh]\d*)|(?<dropLowMatch>[Ll]\d*)|(?<dropConstraintsMatch>[Dd]{([<>|]?\d+,?)*})|(?<explodeMatch>!+{?([<>|]?\d+,?)*}?)|(?<uniqueMatch>[Uu]({(\d+,?)+})?)|(?<replaceMatch>[Vv]{?([<>|]?\d+=?\d+,?)*}?)|(?<rerollMatch>[Rr]{?([<>|]?\d,?)*}\d*)|(?<capMatch>[Cc]([<>|]?\d+)*)|(?<plusMatch>\+\d+)|(?<minusMatch>-\d+)/

export const completeRollPattern = new RegExp(
`${coreNotationPattern.source}|${modifierRollPatterns.source}`,
Expand Down
13 changes: 13 additions & 0 deletions tests/validate-notation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ describe('validateNotation', () => {
})
})

describe('when given a nonsensical drop notation that is bugging me', () => {
const notation: DiceNotation<number> = '2d5D'

it('returns an error result', () => {
const result = validateNotation(notation)

expect(result).toEqual({
valid: false,
description: []
})
})
})

describe('when given a standard notation', () => {
it('returns a valid result', () => {
const notation = '2d6'
Expand Down

0 comments on commit 3afd9f0

Please sign in to comment.