From 5f5603fff77e35cba2e1e17f75471d0a65305c4b Mon Sep 17 00:00:00 2001 From: xeals Date: Thu, 27 Apr 2023 12:34:48 +1000 Subject: [PATCH] fix parsing of Thunder / Thunder Punch --- calc.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/calc.js b/calc.js index b14f076..f620070 100644 --- a/calc.js +++ b/calc.js @@ -63,7 +63,10 @@ function buildLexer() { const Move = createToken({ name: "Move", pattern: new RegExp( - [...gen.moves].map((m) => escapeRegExp(m.name)).join("|") + [...gen.moves] + .map((m) => escapeRegExp(m.name)) + .sort((a, b) => b.length - a.length) + .join("|") ), }); @@ -350,6 +353,12 @@ function test() { res = parseAndCalculate("Zoroark-Hisui Night Slash vs Golem"); assert(res.attacker.name === "Zoroark-Hisui", "should parse regional forme"); + + res = parseAndCalculate("Ditto Thunder Punch vs. Avalugg"); + assert( + res.move.name === "Thunder Punch", + "should match entire move that is a superset of another move" + ); } export { parseAndCalculate, test };