diff --git a/calc.go b/calc.go index 146573c..8ceceec 100644 --- a/calc.go +++ b/calc.go @@ -628,16 +628,10 @@ func (f *File) evalInfixExp(sheet, cell string, tokens []efp.Token) (efp.Token, } // current token is logical - if token.TType == efp.OperatorsInfix && token.TSubType == efp.TokenSubTypeLogical { - } if token.TType == efp.TokenTypeOperand && token.TSubType == efp.TokenSubTypeLogical { argsStack.Peek().(*list.List).PushBack(newStringFormulaArg(token.TValue)) } - // current token is text - if token.TType == efp.TokenTypeOperand && token.TSubType == efp.TokenSubTypeText { - argsStack.Peek().(*list.List).PushBack(newStringFormulaArg(token.TValue)) - } if err = f.evalInfixExpFunc(sheet, cell, token, nextToken, opfStack, opdStack, opftStack, opfdStack, argsStack); err != nil { return efp.Token{}, err } @@ -1012,7 +1006,7 @@ func (f *File) parseToken(sheet string, token efp.Token, opdStack, optStack *Sta optStack.Pop() } // opd - if token.TType == efp.TokenTypeOperand && token.TSubType == efp.TokenSubTypeNumber { + if token.TType == efp.TokenTypeOperand && (token.TSubType == efp.TokenSubTypeNumber || token.TSubType == efp.TokenSubTypeText) { opdStack.Push(token) } return nil diff --git a/calc_test.go b/calc_test.go index 22b90e6..20505fc 100644 --- a/calc_test.go +++ b/calc_test.go @@ -34,18 +34,20 @@ func TestCalcCellValue(t *testing.T) { {nil, nil, nil, "Feb", "South 2", 45500}, } mathCalc := map[string]string{ - "=2^3": "8", - "=1=1": "TRUE", - "=1=2": "FALSE", - "=1<2": "TRUE", - "=3<2": "FALSE", - "=2<=3": "TRUE", - "=2<=1": "FALSE", - "=2>1": "TRUE", - "=2>3": "FALSE", - "=2>=1": "TRUE", - "=2>=3": "FALSE", - "=1&2": "12", + "=2^3": "8", + "=1=1": "TRUE", + "=1=2": "FALSE", + "=1<2": "TRUE", + "=3<2": "FALSE", + "=2<=3": "TRUE", + "=2<=1": "FALSE", + "=2>1": "TRUE", + "=2>3": "FALSE", + "=2>=1": "TRUE", + "=2>=3": "FALSE", + "=1&2": "12", + `="A"="A"`: "TRUE", + `="A"<>"A"`: "FALSE", // Engineering Functions // BESSELI "=BESSELI(4.5,1)": "15.389222753735925", @@ -1084,6 +1086,10 @@ func TestCalcCellValue(t *testing.T) { "=IF(1<>1)": "FALSE", "=IF(5<0, \"negative\", \"positive\")": "positive", "=IF(-2<0, \"negative\", \"positive\")": "negative", + `=IF(1=1, "equal", "notequal")`: "equal", + `=IF(1<>1, "equal", "notequal")`: "notequal", + `=IF("A"="A", "equal", "notequal")`: "equal", + `=IF("A"<>"A", "equal", "notequal")`: "notequal", // Excel Lookup and Reference Functions // CHOOSE "=CHOOSE(4,\"red\",\"blue\",\"green\",\"brown\")": "brown",