Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[se] Fix bug 60489 #4726

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cell/model/FormulaObjects/parserFormula.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
cBaseType.prototype.toArray = function (putValue, checkOnError, fPrepareElem) {
let arr = [];
if (this.getMatrix) {
arr = this.getMatrix();
arr = this.type === cElementType.cellsRange3D ? this.getMatrix()[0] : this.getMatrix();
arr = getArrayCopy(arr);

if (putValue || checkOnError) {
Expand Down
48 changes: 41 additions & 7 deletions cell/view/WorkbookView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3129,19 +3129,53 @@
};

WorkbookView.prototype.insertArgumentsInFormula = function (args, argNum, argType, name) {
function checkParser (arg, parserHelp, ws) {
// If any parser returns true, we return it immediately
if (parserHelp.isRef(arg, 0)) {
return true
}
if (parserHelp.is3DRef(arg, 0)[0]) {
return true
}
if (parserHelp.isArea(arg, 0)) {
return true
}
if (ws.workbook.dependencyFormulas.getDefNameByName(arg, ws.getId())) {
return true
}
return false
}


if (this.getCellEditMode()) {
var sArguments = args.join(AscCommon.FormulaSeparators.functionArgumentSeparator);
this.cellEditor.changeCellText(sArguments);
const ws = this.getActiveWS();
// If we expect a string as an argument, then we check whether the current argument is a string
// The check is performed using regular expressions from parserHelper
if (argType !== undefined && argType === AscCommonExcel.cElementType.string) {
let argN = args[argNum];
if (argN !== undefined) {
let parserHelp = AscCommon.parserHelp;
let isString = parserHelp.isString('"' + argN + '"', 0);
let isEmptyString = argN === ""; // if we receive an empty string, then we don't need to add quotes
if (isString && !isEmptyString) {
let anyConditionMet = checkParser(argN, parserHelp, ws);
if (!anyConditionMet) {
argN = '"' + argN + '"';
args[argNum] = argN;
}
}
}
}
let sArguments = args.join(AscCommon.FormulaSeparators.functionArgumentSeparator);
this.cellEditor.changeCellText(sArguments); // changes the text of the arguments in the cell, but not in the wizard

if (name) {
var ws = this.getActiveWS();

var res = new AscCommonExcel.CFunctionInfo(name);
let res = new AscCommonExcel.CFunctionInfo(name);
res.argumentsResult = [];
var argCalc = ws.calculateWizardFormula(args[argNum], argType);
let argCalc = ws.calculateWizardFormula(args[argNum], argType);
res.argumentsResult[argNum] = argCalc.str;
if (argCalc.obj && argCalc.obj.type !== AscCommonExcel.cElementType.error) {
var funcCalc = ws.calculateWizardFormula(name + '(' + sArguments + ')');
let funcCalc = ws.calculateWizardFormula(name + '(' + sArguments + ')');
res.functionResult = funcCalc.str;
if (funcCalc.obj && funcCalc.obj.type !== AscCommonExcel.cElementType.error) {
res.formulaResult = ws.calculateWizardFormula(this.cellEditor.getText().substring(1)).str;
Expand Down
14 changes: 14 additions & 0 deletions tests/cell/spreadsheet-calculation/FormulaTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10540,6 +10540,20 @@ $(function () {
oParser = new parserFormula("TEXTSPLIT(A2,,C1,,,)", "A1", ws);
assert.ok(oParser.parse());
assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "Do. Or do not. There is no try. -Anonymous");

ws.getRange2("A100:A101").setValue("1");
// cellsRange3D test
// col delimiter
let currentWsName = ws.getName();
oParser = new parserFormula("TEXTSPLIT(A2," + currentWsName + "!A100:A101)", "A1", ws);
assert.ok(oParser.parse(), "TEXTSPLIT(A2,Sheet1!A100:A101)");
assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "Do. Or do not. There is no try. -Anonymous", "Result of TEXTSPLIT(A2,Sheet1!A100:A101)");

// row delimiter
oParser = new parserFormula("TEXTSPLIT(A2,," + currentWsName + "!A100:A101)", "A1", ws);
assert.ok(oParser.parse(), "TEXTSPLIT(A2,,Sheet1!A100:A101)");
assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "Do. Or do not. There is no try. -Anonymous", "Result of TEXTSPLIT(A2,,Sheet1!A100:A101)");

});

function putStackData() {
Expand Down
95 changes: 95 additions & 0 deletions tests/cell/spreadsheet-calculation/SheetStructureTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3024,6 +3024,101 @@ $(function () {
clearData(0, 99, 0, 105);
});

QUnit.test('Insert arguments from wizard', function (assert) {
let argNum, res;

ws.getRange2("F1").setValue("1,2,3");
ws.getRange2("F2").setValue("1;2;3");
ws.getRange2("F3").setValue("1.2.3");

ws.getRange2("G1").setValue(";");
ws.getRange2("G2").setValue(",");
ws.getRange2("G3").setValue(".");
ws.getRange2("G4").setValue("test");

wb.dependencyFormulas.addDefName("dd", "Sheet1!$A$100:$A$104");

api.wb.cellEditor = {
data : {},
changeCellText: function () {},
getText: function () {
return "";
}
};

api.wb.wsActive = ws.getIndex();
api.wb.setCellEditMode(true);

// EXACT tests
argNum = 1;
res = api.asc_insertArgumentsInFormula(["G1", ";"], argNum, AscCommonExcel.cElementType.string, "EXACT");
assert.strictEqual(res.functionResult, "TRUE", 'EXACT(";",";")');
assert.strictEqual(res.argumentsResult[argNum], "\";\"", 'Second argument in EXACT(";",";") has quotes');

res = api.asc_insertArgumentsInFormula(["G1", "d"], argNum, AscCommonExcel.cElementType.string, "EXACT");
assert.strictEqual(res.functionResult, "FALSE", 'EXACT(";","d")');
assert.strictEqual(res.argumentsResult[argNum], "\"d\"", 'Second argument in EXACT(";","d") has quotes');

res = api.asc_insertArgumentsInFormula(["G1", "dd"], argNum, AscCommonExcel.cElementType.string, "EXACT");
assert.strictEqual(res.functionResult, "#VALUE!", 'EXACT(";","dd")');
assert.strictEqual(res.argumentsResult[argNum], "", 'Second argument in EXACT(";","dd") doesnt have quotes');

res = api.asc_insertArgumentsInFormula(["G2", ","], argNum, AscCommonExcel.cElementType.string, "EXACT");
assert.strictEqual(res.functionResult, "TRUE", 'EXACT(",",",")');
assert.strictEqual(res.argumentsResult[argNum], "\",\"", 'Second argument in EXACT(",",",") has quotes');

res = api.asc_insertArgumentsInFormula(["G3", "."], argNum, AscCommonExcel.cElementType.string, "EXACT");
assert.strictEqual(res.functionResult, "TRUE", 'EXACT(".",".")');
assert.strictEqual(res.argumentsResult[argNum], "\".\"", 'Second argument in EXACT(".",".") has quotes');

res = api.asc_insertArgumentsInFormula(["G4", "test"], argNum, AscCommonExcel.cElementType.string, "EXACT");
assert.strictEqual(res.functionResult, "TRUE", 'EXACT("test","test")');
assert.strictEqual(res.argumentsResult[argNum], "\"test\"", 'Second argument in EXACT("test","test") has quotes');

// TEXTSPLIT tests
res = api.asc_insertArgumentsInFormula(["F1", ","], argNum, AscCommonExcel.cElementType.string, "TEXTSPLIT");
assert.strictEqual(res.functionResult, "{\"1\",\"2\",\"3\"}", 'TEXTSPLIT("1,2,3",",")');
assert.strictEqual(res.argumentsResult[argNum], "\",\"", 'Second argument in TEXTSPLIT("1,2,3",",") has quotes');

res = api.asc_insertArgumentsInFormula(["F1", ";"], argNum, AscCommonExcel.cElementType.string, "TEXTSPLIT");
assert.strictEqual(res.functionResult, "{\"1,2,3\"}", 'TEXTSPLIT("1,2,3",";")');
assert.strictEqual(res.argumentsResult[argNum], "\";\"", 'Second argument in TEXTSPLIT("1,2,3",";") has quotes');

res = api.asc_insertArgumentsInFormula(["F1", "."], argNum, AscCommonExcel.cElementType.string, "TEXTSPLIT");
assert.strictEqual(res.functionResult, "{\"1,2,3\"}", 'TEXTSPLIT("1,2,3",".")');
assert.strictEqual(res.argumentsResult[argNum], "\".\"", 'Second argument in TEXTSPLIT("1,2,3",".") has quotes');

res = api.asc_insertArgumentsInFormula(["F2", ","], argNum, AscCommonExcel.cElementType.string, "TEXTSPLIT");
assert.strictEqual(res.functionResult, "{\"1;2;3\"}", 'TEXTSPLIT("1;2;3",",")');
assert.strictEqual(res.argumentsResult[argNum], "\",\"", 'Second argument in TEXTSPLIT(1;2;3",",") has quotes');

res = api.asc_insertArgumentsInFormula(["F2", ";"], argNum, AscCommonExcel.cElementType.string, "TEXTSPLIT");
assert.strictEqual(res.functionResult, "{\"1\",\"2\",\"3\"}", 'TEXTSPLIT("1;2;3",";")');
assert.strictEqual(res.argumentsResult[argNum], "\";\"", 'Second argument in TEXTSPLIT("1;2;3",";") has quotes');

res = api.asc_insertArgumentsInFormula(["F2", "."], argNum, AscCommonExcel.cElementType.string, "TEXTSPLIT");
assert.strictEqual(res.functionResult, "{\"1;2;3\"}", 'TEXTSPLIT("1;2;3",".")');
assert.strictEqual(res.argumentsResult[argNum], "\".\"", 'Second argument in TEXTSPLIT("1;2;3",".") has quotes');

res = api.asc_insertArgumentsInFormula(["F3", ","], argNum, AscCommonExcel.cElementType.string, "TEXTSPLIT");
assert.strictEqual(res.functionResult, "{\"1.2.3\"}", 'TEXTSPLIT("1.2.3",",")');
assert.strictEqual(res.argumentsResult[argNum], "\",\"", 'Second argument in TEXTSPLIT(1.2.3",",") has quotes');

res = api.asc_insertArgumentsInFormula(["F3", ";"], argNum, AscCommonExcel.cElementType.string, "TEXTSPLIT");
assert.strictEqual(res.functionResult, "{\"1.2.3\"}", 'TEXTSPLIT("1.2.3",";")');
assert.strictEqual(res.argumentsResult[argNum], "\";\"", 'Second argument in TEXTSPLIT("1.2.3",";") has quotes');

res = api.asc_insertArgumentsInFormula(["F3", "."], argNum, AscCommonExcel.cElementType.string, "TEXTSPLIT");
assert.strictEqual(res.functionResult, "{\"1\",\"2\",\"3\"}", 'TEXTSPLIT("1.2.3",".")');
assert.strictEqual(res.argumentsResult[argNum], "\".\"", 'Second argument in TEXTSPLIT("1.2.3",".") has quotes');

// remove all created earlier defNames
wb.dependencyFormulas._foreachDefName(function(defName) {
wb.dependencyFormulas.removeDefName(undefined, defName.name);
});

});

QUnit.test('autoCompleteFormula', function (assert) {
let resCell, range, fillRange, autoCompleteRes;

Expand Down
Loading