mirror of
https://github.com/ONLYOFFICE/sdkjs.git
synced 2026-04-07 14:09:12 +08:00
[de] Fix minor bugs in CParagraphContentPos class
Add unit-tests for CParagraphContentPos module. Also add script for check all tests at once
This commit is contained in:
1
.github/workflows/check.yml
vendored
1
.github/workflows/check.yml
vendored
@ -27,6 +27,7 @@ jobs:
|
||||
node-qunit-puppeteer cell/.unit-tests/FormulaTests.html
|
||||
node-qunit-puppeteer cell/.unit-tests/subdir/PivotTests.html
|
||||
node-qunit-puppeteer cell/.unit-tests/CopyPasteTests.html
|
||||
node-qunit-puppeteer tests/word/unit-tests/paragraphContentPos.html
|
||||
node-qunit-puppeteer tests/word/document-calculation/paragraph.html
|
||||
node-qunit-puppeteer tests/word/forms/forms.html
|
||||
node-qunit-puppeteer tests/word/forms/complexForm.html
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@ -16,3 +16,7 @@ slide/sdk-all.props.js.map
|
||||
slide/sdk-all.vars.js.map
|
||||
word/sdk-all.props.js.map
|
||||
word/sdk-all.vars.js.map
|
||||
node_modules
|
||||
package-lock.json
|
||||
*/node_modules
|
||||
*/package-lock.json
|
||||
|
||||
64
tests/runAll.js
Normal file
64
tests/runAll.js
Normal file
@ -0,0 +1,64 @@
|
||||
const path = require("path");
|
||||
|
||||
const allTests = [
|
||||
'../cell/.unit-tests/FormulaTests.html',
|
||||
'../cell/.unit-tests/subdir/PivotTests.html',
|
||||
'../cell/.unit-tests/CopyPasteTests.html',
|
||||
'word/unit-tests/paragraphContentPos.html',
|
||||
'word/document-calculation/paragraph.html',
|
||||
'word/forms/forms.html',
|
||||
'word/forms/complexForm.html'
|
||||
];
|
||||
|
||||
const {performance} = require('perf_hooks');
|
||||
|
||||
const {
|
||||
runQunitPuppeteer,
|
||||
printResultSummary,
|
||||
printFailedTests
|
||||
} = require("node-qunit-puppeteer");
|
||||
|
||||
async function Run()
|
||||
{
|
||||
let startTime = performance.now();
|
||||
let count = 0;
|
||||
let failed = [];
|
||||
for (let nIndex = 0, nCount = allTests.length; nIndex < nCount; ++nIndex)
|
||||
{
|
||||
await runQunitPuppeteer({targetUrl : path.join(__dirname, allTests[nIndex])})
|
||||
.then(result =>
|
||||
{
|
||||
count++;
|
||||
printResultSummary(result, console);
|
||||
|
||||
if (result.stats.failed > 0)
|
||||
{
|
||||
printFailedTests(result, console);
|
||||
failed.push(allTests[nIndex]);
|
||||
}
|
||||
})
|
||||
.catch(ex =>
|
||||
{
|
||||
console.error(ex);
|
||||
});
|
||||
}
|
||||
|
||||
console.log("\nOverall Elapsed " + (Math.round(( ((performance.now() - startTime) / 1000) + Number.EPSILON) * 1000) / 1000) + "s");
|
||||
console.log("\n"+ (count - failed.length) + "/" + count + " modules successfully passed the tests");
|
||||
|
||||
if (failed.length)
|
||||
{
|
||||
console.log("\nFAILED".red.bold);
|
||||
for (let nIndex = 0, nCount = failed.length; nIndex < nCount; ++nIndex)
|
||||
{
|
||||
console.log(failed[nIndex]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log("\nPASSED".green.bold);
|
||||
}
|
||||
}
|
||||
|
||||
Run();
|
||||
|
||||
30
tests/word/unit-tests/paragraphContentPos.html
Normal file
30
tests/word/unit-tests/paragraphContentPos.html
Normal file
@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>Document calculation tests</title>
|
||||
|
||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
||||
<link type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/qunit/2.16.0/qunit.css" rel="stylesheet" media="screen" />
|
||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/qunit/2.16.0/qunit.js"></script>
|
||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/xregexp/3.2.0/xregexp-all.min.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../../../develop/sdkjs/word/scripts.js"></script>
|
||||
<script type="text/javascript">
|
||||
window.sdk_scripts.forEach(function(item){
|
||||
document.write('<script type="text/javascript" src="' + item + '"><\/script>');
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="paragraphContentPos.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Test forms</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup, will be hidden</div>
|
||||
</body>
|
||||
</html>
|
||||
83
tests/word/unit-tests/paragraphContentPos.js
Normal file
83
tests/word/unit-tests/paragraphContentPos.js
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* 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-12 Ernesta Birznieka-Upisha
|
||||
* 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 () {
|
||||
|
||||
QUnit.module("Unit-tests for AscWord.CParagraphContentPos");
|
||||
|
||||
|
||||
QUnit.test("Test:", function (assert)
|
||||
{
|
||||
let oPos = new AscWord.CParagraphContentPos();
|
||||
assert.strictEqual(oPos.GetDepth(), -1, "Create new pos and check the depth (must be negative)");
|
||||
|
||||
oPos.Add(4);
|
||||
oPos.Add(8);
|
||||
oPos.Add(15);
|
||||
oPos.Add(16);
|
||||
oPos.Add(23);
|
||||
oPos.Add(42);
|
||||
|
||||
assert.strictEqual(oPos.GetDepth(), 5, "Fill the pos and check the depth");
|
||||
|
||||
assert.strictEqual(oPos.Get(0), 4, "[0]");
|
||||
assert.strictEqual(oPos.Get(1), 8, "[1]");
|
||||
assert.strictEqual(oPos.Get(2), 15, "[2]");
|
||||
assert.strictEqual(oPos.Get(3), 16, "[3]");
|
||||
assert.strictEqual(oPos.Get(4), 23, "[4]");
|
||||
assert.strictEqual(oPos.Get(5), 42, "[5]");
|
||||
|
||||
let oPos2 = oPos.Copy();
|
||||
|
||||
assert.strictEqual(oPos2.Compare(oPos), 0, "Make a copy and check for equality");
|
||||
|
||||
oPos2.Update2(20, 3);
|
||||
assert.strictEqual(oPos2.Get(3), 20, "Check [3] after update");
|
||||
assert.strictEqual(oPos2.GetDepth(), 5, "Check depth after Update2");
|
||||
assert.strictEqual(oPos2.Compare(oPos), 1, "Compare pos +1");
|
||||
|
||||
oPos2.Update2(2, 3);
|
||||
assert.strictEqual(oPos2.Compare(oPos), -1, "Compare pos -1");
|
||||
|
||||
oPos2.DecreaseDepth(3);
|
||||
assert.strictEqual(oPos2.GetDepth(), 2, "Check depth after decreasing by 3");
|
||||
assert.strictEqual(oPos2.Compare(oPos), -1, "Compare decreased pos and original pos");
|
||||
assert.strictEqual(oPos2.IsPartOf(oPos), true, "Check decreased pos as part of original");
|
||||
|
||||
oPos2.Update2(2, 2);
|
||||
assert.strictEqual(oPos2.IsPartOf(oPos), false, "Spoil decreased pos and check it as part of original");
|
||||
|
||||
let oPos3 = oPos.Copy();
|
||||
oPos3.DecreaseDepth(1);
|
||||
assert.strictEqual(oPos3.Compare(oPos), -1, "Make a copy and decrease pos and check for equality");
|
||||
});
|
||||
});
|
||||
@ -116,12 +116,17 @@
|
||||
/**
|
||||
* Сравниваем текущую позицию с заданной
|
||||
* @param {CParagraphContentPos} oPos
|
||||
* @returns {number} 0 - позиции совпадают, 1 - текущая позиция дальше заданной, -1 - текущая позиция до заданной.
|
||||
* @returns {number} 0 - позиции совпадают, 1 - текущая позиция дальше заданной, -1 - текущая позиция до заданной
|
||||
*/
|
||||
CParagraphContentPos.prototype.Compare = function(oPos)
|
||||
{
|
||||
if (!this.IsValid() || !oPos || !oPos.IsValid())
|
||||
return -2;
|
||||
|
||||
let nDepth = 0;
|
||||
|
||||
// let nLen1 = this.Depth;
|
||||
// let nLen2 = oPos.Depth;
|
||||
let nLen1 = this.Data.length;
|
||||
let nLen2 = oPos.Data.length;
|
||||
let nLenMin = Math.min(nLen1, nLen2);
|
||||
@ -170,6 +175,41 @@
|
||||
{
|
||||
return (oPos && 0 === this.Compare(oPos));
|
||||
};
|
||||
/**
|
||||
* Проверяем, что текущая позиция является частью заданной
|
||||
* @param oPos {CParagraphContentPos}
|
||||
* @returns {boolean}
|
||||
*/
|
||||
CParagraphContentPos.prototype.IsPartOf = function(oPos)
|
||||
{
|
||||
if (!oPos
|
||||
|| this.IsEmpty()
|
||||
|| oPos.IsEmpty()
|
||||
|| !this.IsValid()
|
||||
|| !oPos.IsValid()
|
||||
|| this.Depth > oPos.Depth)
|
||||
return false;
|
||||
|
||||
let nDepth = 0;
|
||||
let nLen = this.Depth;
|
||||
while (nDepth < nLen)
|
||||
{
|
||||
if (this.Data[nDepth] !== oPos.Data[nDepth])
|
||||
return false;
|
||||
|
||||
++nDepth;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
CParagraphContentPos.prototype.IsValid = function()
|
||||
{
|
||||
return (this.Depth <= this.Data.length);
|
||||
};
|
||||
CParagraphContentPos.prototype.IsEmpty = function()
|
||||
{
|
||||
return (0 === this.Depth);
|
||||
};
|
||||
//--------------------------------------------------------export----------------------------------------------------
|
||||
window['AscWord'].CParagraphContentPos = CParagraphContentPos;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user