From 7e137711317ade910c4f2686e0c0e223736a0533 Mon Sep 17 00:00:00 2001 From: Carla Costea Date: Tue, 8 Mar 2022 14:46:11 +0200 Subject: [PATCH 1/2] fix counting trailing zeros when we also have leading zeros --- src/fixtures/latex-equal/literal/literal.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/fixtures/latex-equal/literal/literal.ts b/src/fixtures/latex-equal/literal/literal.ts index 5dae603..a3610df 100644 --- a/src/fixtures/latex-equal/literal/literal.ts +++ b/src/fixtures/latex-equal/literal/literal.ts @@ -1,4 +1,5 @@ export default { + mode: "literal", tests: [ { @@ -13,6 +14,12 @@ export default { ne: ["12.001"], opts: { literal: { allowTrailingZeros: true } }, }, + { + only:true, + target: "0.500", + eq: [".500000"], + ne: [".5001"], + }, { target: "12.00", eq: ["12.00"], From fdef445935a3ca7f36bb94073c3b9509e7c0e768 Mon Sep 17 00:00:00 2001 From: Carla Costea Date: Tue, 8 Mar 2022 15:06:40 +0200 Subject: [PATCH 2/2] fix counting trailing zeros when we also have leading zeros, add tests --- src/conversion/latex-to-ast.ts | 2 +- src/fixtures/latex-equal/literal/literal.ts | 13 ++++++++++++- src/latex-equal.ts | 4 +--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/conversion/latex-to-ast.ts b/src/conversion/latex-to-ast.ts index f10e46b..b9987d9 100644 --- a/src/conversion/latex-to-ast.ts +++ b/src/conversion/latex-to-ast.ts @@ -1146,7 +1146,7 @@ export class LatexToAst { if (parsedNumber !== number.toString()) { const p = number.toString(); // @ts-ignore - const sub = result + const sub = parsedNumber // @ts-ignore .substring(p.length) .split("") diff --git a/src/fixtures/latex-equal/literal/literal.ts b/src/fixtures/latex-equal/literal/literal.ts index a3610df..8ab393f 100644 --- a/src/fixtures/latex-equal/literal/literal.ts +++ b/src/fixtures/latex-equal/literal/literal.ts @@ -15,9 +15,20 @@ export default { opts: { literal: { allowTrailingZeros: true } }, }, { - only:true, target: "0.500", eq: [".500000"], + opts: { literal: { allowTrailingZeros: true } }, + ne: [".5001"], + }, + { + target: "0.500", + ne: [".500000"], + opts: { literal: { allowTrailingZeros: false } }, + }, + { + target: "0.500", + eq: [".500"], + opts: { literal: { allowTrailingZeros: true } }, ne: [".5001"], }, { diff --git a/src/latex-equal.ts b/src/latex-equal.ts index 437cf2e..991f734 100644 --- a/src/latex-equal.ts +++ b/src/latex-equal.ts @@ -26,11 +26,9 @@ export const latexEqual = (a: Latex, b: Latex, opts: Opts) => { } const al = lta.convert(a); - console.log(al, "al") - const bl = lta.convert(b); - console.log(bl, "bl") + if (differenceIsTooGreat(al, bl)) { return false; }