/* * (c) Copyright Ascensio System SIA 2010-2024 * * This program is a free software product. You can redistribute it and/or * modify it under the terms of the GNU Affero General Public License (AGPL) * version 3 as published by the Free Software Foundation. In accordance with * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect * that Ascensio System SIA expressly excludes the warranty of non-infringement * of any third-party rights. * * This program is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html * * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish * street, Riga, Latvia, EU, LV-1050. * * The interactive user interfaces in modified source and object code versions * of the Program must display Appropriate Legal Notices, as required under * Section 5 of the GNU AGPL version 3. * * Pursuant to Section 7(b) of the License you must retain the original Product * logo when distributing the program. Pursuant to Section 7(e) we decline to * grant you any rights under trademark law for use of our trademarks. * * All the Product's GUI elements, including illustrations and icon sets, as * well as technical writing content are licensed under the terms of the * Creative Commons Attribution-ShareAlike 4.0 International. See the License * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode * */ $(function () { let Root, MathContent, logicDocument, p1; function Init() { logicDocument = AscTest.CreateLogicDocument(); logicDocument.Start_SilentMode(); logicDocument.RemoveFromContent(0, logicDocument.GetElementsCount(), false); p1 = new AscWord.Paragraph(); logicDocument.AddToContent(0, p1); MathContent = new ParaMath(); if (p1.Content.length > 0) p1.Content.splice(0, 1); p1.AddToContent(0, MathContent); Root = MathContent.Root; }; Init(); function Clear() { Root.Remove_FromContent(0, Root.Content.length); Root.Correct_Content(); }; function AddFromMathML(strMathMl) { return AscWord.ParaMath.fromMathML(strMathMl); } QUnit.testStart(function (){ AscTest.ClearDocument(); AscCommon.History.Clear(); Clear(); Init(); }) QUnit.module("Presentation MathML", function (assert) { QUnit.module("", function (assert) { // attributes }) QUnit.module("MathML Core Attributes", function (assert) { QUnit.test('mathcolor in ', function (assert) { math = AddFromMathML(`x`); let math_data = math.GetTextOfElement(); let math_text = math_data.GetText(); let style = math_data.arr[0].additionalMathData.style; let color = style.Color; let colorText =`${color.r}, ${color.g}, ${color.b}`; assert.strictEqual( colorText, "255, 0, 0", "Check attribute mathcolor" ); }) QUnit.test('mathbackground in ', function (assert) { math = AddFromMathML(`y`); math_data = math.GetTextOfElement(); math_text = math_data.GetText(); style = math_data.arr[0].additionalMathData.style; let highLight = style.HighLight; let highLightText =`${highLight.r}, ${highLight.g}, ${highLight.b}`; assert.strictEqual( highLightText, "0, 0, 255", "Check attribute mathbackground" ); }) QUnit.test('mathcolor & mathbackground in ', function (assert) { math = AddFromMathML(`z`); math_data = math.GetTextOfElement(); math_text = math_data.GetText(); style = math_data.arr[0].additionalMathData.style; highLight = style.HighLight; color = style.Color; highLightText =`${highLight.r}, ${highLight.g}, ${highLight.b}`; colorText =`${color.r}, ${color.g}, ${color.b}`; assert.strictEqual( colorText + '-' + highLightText, "255, 0, 0-0, 0, 255" , "Check attribute mathbackground and mathcolor" ); }) QUnit.test('mathcolor in ', function (assert) { math = AddFromMathML(`x`); let math_data = math.GetTextOfElement(); let math_text = math_data.GetText(); let style = math_data.arr[0].additionalMathData.style; let color = style.Color; let colorText =`${color.r}, ${color.g}, ${color.b}`; assert.strictEqual( colorText, "255, 0, 0", "Check attribute mathcolor" ); }) QUnit.test('mathbackground in ', function (assert) { math = AddFromMathML(`y`); math_data = math.GetTextOfElement(); math_text = math_data.GetText(); style = math_data.arr[0].additionalMathData.style; let highLight = style.HighLight; let highLightText =`${highLight.r}, ${highLight.g}, ${highLight.b}`; assert.strictEqual( highLightText, "0, 0, 255", "Check attribute mathbackground" ); }) QUnit.test('mathcolor & mathbackground in ', function (assert) { math = AddFromMathML(`z`); math_data = math.GetTextOfElement(); math_text = math_data.GetText(); style = math_data.arr[0].additionalMathData.style; highLight = style.HighLight; color = style.Color; highLightText =`${highLight.r}, ${highLight.g}, ${highLight.b}`; colorText =`${color.r}, ${color.g}, ${color.b}`; assert.strictEqual( colorText + '-' + highLightText, "255, 0, 0-0, 0, 255" , "Check attribute mathbackground and mathcolor" ); }) }) QUnit.module("Token Elements", function () { QUnit.module('Attributes', function () { QUnit.test('mathvariant', function (assert) { math = AddFromMathML(`c`); let math_data = math.GetTextOfElement(); let math_text = math_data.GetText(); let style = math_data.arr[0].additionalMathData.style; assert.strictEqual( colorText, "255, 0, 0", "Check attribute mathcolor" ); }) // QUnit.test('mathsize', function (assert) // { // }) // QUnit.test('dir', function (assert) // { // }) }) QUnit.module('mi', function () { QUnit.module('Attributes', function () { QUnit.test('Check default mathvariant is italic if content length = 1', function (assert) { let math = AddFromMathML(`c`); assert.strictEqual( math.GetTextOfElement().GetText(), "𝑐", "Add with mathvariant is italic" ); }) QUnit.test('Check default mathvariant is normal if content length > 1', function (assert) { let math = AddFromMathML(`cx`); assert.strictEqual( math.GetTextOfElement().GetText(), "cx", "Add with mathvariant is normal" ); }) QUnit.test('Add with normal mathvariant = normal', function (assert) { let math = AddFromMathML(`c`); assert.strictEqual( math.GetTextOfElement().GetText(), "c", "Add with 'c' text" ); }) QUnit.test('Add with custom mathvariant = fraktur', function (assert) { let math = AddFromMathML(`xy`); assert.strictEqual( math.GetTextOfElement().GetText(), "𝔡𝔢", "Add with '𝔡𝔢' text" ); }) }) QUnit.test('Add mi as text', function (assert) { let math = AddFromMathML(`c`); assert.strictEqual( math.GetTextOfElement().GetText(), "𝑐", "Add with '𝑐'" ); }) }) QUnit.module('mn', function () { QUnit.test('Add mn as text', function (assert) { let math = AddFromMathML(`2`); assert.strictEqual( math.GetTextOfElement().GetText(), "2", "Add with '2'" ); }) }) QUnit.module('mo', function () { QUnit.test('Add mo', function (assert) { let math = AddFromMathML(`+`); assert.strictEqual( math.GetTextOfElement().GetText(), "+", "Add with '+'" ); }) QUnit.module('Dictionary-based attributes', function () { // form // lspace // rspace // stretchy // symmetric // maxsize // minsize // largeop // Ooxml control all this attributes. For now unesessary QUnit.test('movablelimits default attribute', function (assert) { let math = AddFromMathML(`βˆ‘in`); assert.strictEqual( math.Root.Content[1].Pr.limLoc, NARY_UndOvr, "Limloc is nary" ); }) QUnit.test('movablelimits attribute', function (assert) { let math = AddFromMathML(`βˆ‘in`); assert.strictEqual( math.Root.Content[1].Pr.limLoc, NARY_SubSup, "Limloc is supSub" ); }) }) QUnit.module('Linebreaking attributes', function () { // for now only one variant QUnit.test('linebreak attribute', function (assert) { let math = AddFromMathML(`βˆ‘in`); assert.strictEqual( math.Root.Content[1].Pr.limLoc, NARY_UndOvr, "Limloc is nary" ); }) // lineleading // linebreakstyle // linebreakmultchar }); QUnit.module('Indentation attributes', function () { // indentalign // indentshift // indenttarget // indentalignfirst // indentshiftfirst // indentalignlast // indentshiftlast }); }) QUnit.module('mtext', function (){ QUnit.test('Add mtext #1', function (assert) { let math = AddFromMathML(` Theorem 1: `); assert.strictEqual( math.GetTextOfElement().GetText(), "Theorem 1:", "Add with 'Theorem 1:'" ); }) QUnit.test('Add mtext #2', function (assert) { let math = AddFromMathML(``); assert.strictEqual( math.GetTextOfElement().GetText(), " ", "Add with ' '" ); }) QUnit.test('Add mtext #3', function (assert) { let math = AddFromMathML(` y = x 2  if  x β‰₯ 1  and  2  otherwise. `); assert.strictEqual( math.GetTextOfElement().GetText(), "𝑦=π‘₯^2 if π‘₯β‰₯1 and 2 otherwise.", "Add with ' '" ); }) }) QUnit.module('space', function (){ // QUnit.test('Add mspace #1', function (assert) // { // let math = AddFromMathML(` Theorem 1: `); // assert.strictEqual( // math.GetTextOfElement().GetText(), // "Theorem 1:", // "Add with 'Theorem 1:'" // ); // }) }) QUnit.module('ms', function (){ QUnit.test('Add ms #1', function (assert) { let math = AddFromMathML(` n `); assert.strictEqual( math.GetTextOfElement().GetText(), "\"n\"", "Add with '\"n\"'" ); }) QUnit.test('Add ms with custom lquote attribute', function (assert) { let math = AddFromMathML(` n `); assert.strictEqual( math.GetTextOfElement().GetText(), "1n\"", "Add with '1n\"'" ); }) QUnit.test('Add ms with custom rquote attribute', function (assert) { let math = AddFromMathML(` n `); assert.strictEqual( math.GetTextOfElement().GetText(), "\"n2", "Add with '\"n2'" ); }) }) QUnit.module('mfrac', function (){ QUnit.test('Add mfrac', function (assert) { let math = AddFromMathML(` a b `); assert.strictEqual( math.GetTextOfElement().GetText(), "π‘Ž/𝑏", "Add with 'π‘Ž/𝑏'" ); }) QUnit.test('Add complex mfrac', function (assert) { let math = AddFromMathML(` ( a b ) a b c d `); assert.strictEqual( math.GetTextOfElement().GetText(), "((π‘Ž/𝑏) π‘Ž/𝑏)/(𝑐/𝑑)", "Add with '((π‘Ž/𝑏)π‘Ž/𝑏)/(𝑐/𝑑)'" ); }) QUnit.module('Attributes', function () { // QUnit.test('linethickness', function (assert) // {}) // QUnit.test('numalign', function (assert) // {}) // QUnit.test('denomalign', function (assert) // {}) QUnit.test('bevelled', function (assert) { let math = AddFromMathML(` a b `); assert.strictEqual( math.GetTextOfElement().GetText(), "π‘Žβ„π‘", "Add with 'π‘Žβ„π‘'" ); }) }) }) QUnit.module('msqrt', function (){ QUnit.test('Add msqrt', function (assert) { let math = AddFromMathML(`x`); assert.strictEqual( math.GetTextOfElement().GetText(), "√(π‘₯)", "Add with '√(π‘₯)'" ); }) }) QUnit.module('mroot', function (){ QUnit.test('Add mroot', function (assert) { let math = AddFromMathML(`x5`); assert.strictEqual( math.GetTextOfElement().GetText(), "√(5&π‘₯)", "Add with '√(5&π‘₯)'" ); }) }) QUnit.module('mstyle', function (){ }) QUnit.module('merror', function (){ QUnit.test('Add merror', function (assert) { let math = AddFromMathML(` Unrecognized element: mfraction; arguments were: 1 + 5 and 2 `); // without rules for Unicode and LaTeX linear form let str = ""; math.Root.Content.forEach((content) => { str += content.GetTextOfElement().GetText(); }); assert.strictEqual( str, "Unrecognized element: mfraction; arguments were:1+√5and2", "Add " ); }) }) QUnit.module('mpadded', function (){ QUnit.test('Add mpadded', function (assert) { let math = AddFromMathML(` 23456 78 `); assert.strictEqual( math.GetTextOfElement().GetText(), '23456/78', "Check text" ); }) }) QUnit.module('mphantom', function (){ QUnit.test('Add mphantom', function (assert) { let math = AddFromMathML(`x`); assert.strictEqual( math.Root.Content[1] instanceof CPhantom , true, "Add with 'x'" ); assert.strictEqual( math.GetTextOfElement().GetText(), '\\mphantomπ‘₯', "Check text" ); }) }) QUnit.module('mfenced', function (){ QUnit.test('Add mfenced #1', function (assert) { let math = AddFromMathML(`x`); assert.strictEqual( math.GetTextOfElement().GetText(), '(π‘₯)', "Check text" ); }) QUnit.test('Add mfenced #2', function (assert) { let math = AddFromMathML(`xy`); console.log(math) assert.strictEqual( math.GetTextOfElement().GetText(), '(π‘₯βˆ£π‘¦)', "Check text" ); assert.strictEqual( math.Root.Content[1].Pr.sepChr, 44, "Check separator" ); }) }) QUnit.module('menclose', function (){ QUnit.test('Add menclose #1', function (assert) { let math = AddFromMathML(` x + y `); assert.strictEqual( math.GetTextOfElement().GetText(), 'β–­(π‘₯+𝑦)', "Menclose always convert to simple box" ); }) }) QUnit.module('msub', function (){ QUnit.test('Add msub', function (assert) { let math = AddFromMathML(` β…‡ x `); assert.strictEqual( math.GetTextOfElement().GetText(), 'β…‡_π‘₯', "Check add msub" ); }) }) QUnit.module('msup', function (){ QUnit.test('Add msup', function (assert) { let math = AddFromMathML(` β…‡ x `); assert.strictEqual( math.GetTextOfElement().GetText(), 'β…‡^π‘₯', "Check add msup" ); }) }) QUnit.module('msubsup', function (){ QUnit.test('Add msubsup', function (assert) { let math = AddFromMathML(` 2 β…‡ x `); assert.strictEqual( math.GetTextOfElement().GetText(), '2_β…‡^π‘₯', "Check add msubsup" ); }) }) QUnit.module('munder', function (){ QUnit.test('Add munder #1', function (assert) { let math = AddFromMathML(` x + y + z ⏟ `); assert.strictEqual( math.GetTextOfElement().GetText(), '⏟(π‘₯+𝑦+𝑧)', "Check add munder" ); }) QUnit.test('Add munder #2', function (assert) { let math = AddFromMathML(` x + y + z ⏟ `); assert.strictEqual( math.GetTextOfElement().GetText(), '⏟(π‘₯+𝑦+𝑧)', "Check add munder" ); }) }) QUnit.module('mover', function (){ QUnit.test('Add mover #1', function (assert) { let math = AddFromMathML(` x ^ `); assert.strictEqual( math.GetTextOfElement().GetText(), 'π‘₯β”΄^', "Check add mover" ); }) QUnit.test('Add mover #2', function (assert) { let math = AddFromMathML(` 3 4 `); assert.strictEqual( math.GetTextOfElement().GetText(), '3β”΄4', "Check add mover" ); }) QUnit.test('Add mover #3', function (assert) { let math = AddFromMathML(` x + y + z ⏞ x + y + z ⏞ `); assert.strictEqual( math.GetTextOfElement().GetText(), '⏞(π‘₯+𝑦+𝑧) ⏞(π‘₯+𝑦+𝑧)', "Check add mover" ); }) }) QUnit.module('munderover', function (){ QUnit.test('Add munderover #1', function (assert) { let math = AddFromMathML(` 5 6 7 `); assert.strictEqual( math.GetTextOfElement().GetText(), '(5β”΄7)┬6', "Check add munderover" ); }) }) // QUnit.module('mmultiscripts', function (){ // QUnit.test('Add mmultiscripts', function (assert) // { // let math = AddFromMathML(` // // 1 // 2 // 3 // // 5 // // 6 // // 8 // 9 // // `); // assert.strictEqual( // math.GetTextOfElement().GetText(), // '(5β”΄7)┬6', // "Check add mmultiscripts" // ); // }) // }) QUnit.module('mtable', function (){ QUnit.test('Normalize nested mtr in mtable', function (assert) { let math = AddFromMathML(` a = 0 b = 1 c = 2 `); let content = math.Root.Content[1]; assert.ok(content instanceof CMathMatrix, "Check matrix created"); let rows = content.getRowsCount ? content.getRowsCount() : 0; assert.strictEqual(rows, 3, "Check 3 rows created from nested mtr"); let Row1 = content.getContentElement(0,0).GetTextOfElement().GetText(); let Row2 = content.getContentElement(1,0).GetTextOfElement().GetText(); let Row3 = content.getContentElement(2,0).GetTextOfElement().GetText(); assert.ok(Row1 === "π‘Ž" && Row2 === "𝑏" && Row3 === "𝑐", "Check all rows present"); }) QUnit.test('Normalize nested mtd in mtable', function (assert) { let math = AddFromMathML(` x = 1 `); let content = math.Root.Content[1]; assert.ok(content instanceof CMathMatrix, "Check matrix created"); let rows = content.getRowsCount ? content.getRowsCount() : 0; assert.strictEqual(rows, 1, "Check 1 row created from nested mtd"); let cols = content.getColsCount ? content.getColsCount() : 0; assert.strictEqual(cols, 3, "Check 3 columns created from nested mtd"); let cell1 = content.getContentElement(0,0).GetTextOfElement().GetText(); let cell2 = content.getContentElement(0,1).GetTextOfElement().GetText(); let cell3 = content.getContentElement(0,2).GetTextOfElement().GetText(); assert.ok(cell1 === "π‘₯" && cell2 === "=" && cell3 === "1", "Check all cells present"); }) QUnit.test('Normalize mixed nested mtr and mtd in mtable', function (assert) { let math = AddFromMathML(` a = 0 b = 1 c = 2 `); let content = math.Root.Content[1]; assert.ok(content instanceof CMathMatrix, "Check matrix created"); let rows = content.getRowsCount ? content.getRowsCount() : 0; assert.strictEqual(rows, 3, "Check 3 rows created from mixed structure"); let row1 = content.getContentElement(0,0).GetTextOfElement().GetText(); let row2 = content.getContentElement(1,0).GetTextOfElement().GetText(); let row3 = content.getContentElement(2,0).GetTextOfElement().GetText(); assert.ok(row1 === "π‘Ž" && row2 === "𝑏" && row3 === "𝑐", "Check all rows present in mixed structure"); }) }) }) }) })