From 13b6c4472372bbb47496509976c23caae0cc49b3 Mon Sep 17 00:00:00 2001 From: Jared Hughes Date: Tue, 5 Mar 2024 14:56:20 -0800 Subject: [PATCH] Add test for infixOperatorNames --- test/unit/infixOperatorNames.test.js | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/unit/infixOperatorNames.test.js diff --git a/test/unit/infixOperatorNames.test.js b/test/unit/infixOperatorNames.test.js new file mode 100644 index 000000000..8b73dcff6 --- /dev/null +++ b/test/unit/infixOperatorNames.test.js @@ -0,0 +1,41 @@ +suite('infixOperatorNames', function () { + const $ = window.test_only_jquery; + var mq; + setup(function () { + const autoOperatorNames = 'arcsinh sin with for'; + const infixOperatorNames = 'with for'; + const opts = { autoOperatorNames, infixOperatorNames }; + mq = MQ.MathField($('').appendTo('#mock')[0], opts); + }); + + function prayWellFormedPoint(pt) { + prayWellFormed(pt.parent, pt[L], pt[R]); + } + function assertLatex(latex) { + prayWellFormedPoint(mq.__controller.cursor); + assert.equal(mq.latex(), latex); + } + + test('for stops scanning', function () { + mq.typedText('tfor1/'); + assertLatex('t\\operatorname{for}\\frac{1}{ }'); + }); + + test('sin does not stop scanning', function () { + mq.typedText('tsin1/'); + assertLatex('\\frac{t\\sin1}{ }'); + }); + + test('arcsinh does not stop scanning', function () { + mq.typedText('tarcsinh1/'); + assertLatex('\\frac{t\\operatorname{arcsinh}1}{ }'); + }); + + test('backspace invalidates word', function () { + mq.typedText('tfor1'); + mq.keystroke('Home').keystroke('Right').keystroke('Del'); + assertLatex('tor1'); + mq.keystroke('End').typedText('/'); + assertLatex('\\frac{tor1}{ }'); + }); +});