fix parsing of Thunder / Thunder Punch

This commit is contained in:
xeals 2023-04-27 12:34:48 +10:00
parent ce70a9fb4d
commit 5f5603fff7
Signed by: xeals
GPG Key ID: A498C7AF27EC6B5C

11
calc.js
View File

@ -63,7 +63,10 @@ function buildLexer() {
const Move = createToken({ const Move = createToken({
name: "Move", name: "Move",
pattern: new RegExp( 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"); res = parseAndCalculate("Zoroark-Hisui Night Slash vs Golem");
assert(res.attacker.name === "Zoroark-Hisui", "should parse regional forme"); 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 }; export { parseAndCalculate, test };