diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorEditor.java b/src/main/java/org/solovyev/android/calculator/CalculatorEditor.java index bfe91912..4f0194bf 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorEditor.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorEditor.java @@ -84,7 +84,9 @@ public class CalculatorEditor extends EditText { } Log.d(this.getClass().getName(), getText().toString()); - setSelection(selectionStart, selectionEnd); + + int length = getText().length(); + setSelection(Math.max(Math.min(length - 1, selectionStart), 0), Math.max(Math.min(length - 1, selectionEnd), 0)); } public boolean isHighlightText() { diff --git a/src/main/java/org/solovyev/android/calculator/model/ToJsclTextProcessor.java b/src/main/java/org/solovyev/android/calculator/model/ToJsclTextProcessor.java index af535519..6791c092 100644 --- a/src/main/java/org/solovyev/android/calculator/model/ToJsclTextProcessor.java +++ b/src/main/java/org/solovyev/android/calculator/model/ToJsclTextProcessor.java @@ -45,10 +45,6 @@ class ToJsclTextProcessor implements TextProcessor { if (mathTypeBefore == MathType.function && CollectionsUtils.find(MathType.openGroupSymbols, startsWithFinder) != null) { throw new ParseException("Empty function: " + mathTypeResult.getMatch()); - } else if (mathTypeBefore == MathType.postfix_function && mathTypeResult.getMathType() == MathType.binary_operation) { - if ( mathTypeResult.getMatch().equals("^") ) { - throw new ParseException("Power operation after postfix function is currently unsupported!"); - } } i = mathTypeResult.processToJscl(result, i); diff --git a/src/test/java/org/solovyev/android/calculator/TextHighlighterTest.java b/src/test/java/org/solovyev/android/calculator/TextHighlighterTest.java index 17872ffd..19cd40d0 100644 --- a/src/test/java/org/solovyev/android/calculator/TextHighlighterTest.java +++ b/src/test/java/org/solovyev/android/calculator/TextHighlighterTest.java @@ -42,5 +42,16 @@ public class TextHighlighterTest { Assert.assertEquals(")", textHighlighter.process(")").toString()); Assert.assertEquals(")()(", textHighlighter.process(")()(").toString()); Assert.assertEquals("1 000 000", textHighlighter.process("1000000").toString()); + + textHighlighter.process("cannot calculate 3^10^10 !!!\n" + + " unable to enter 0. FIXED\n" + + " empty display in Xperia Rayo\n" + + " check привиденная FIXED\n" + + " set display result only if text in editor was not changed FIXED\n" + + " shift M text to the left\n" + + " do not show SYNTAX ERROR always (may be show send clock?q) FIXED\n" + + " ln(8)*log(8) => ln(8)*og(8) FIXED\n" + + " copy/paste ln(8)*log(8)\n" + + " 6!^2 ERROR"); } } diff --git a/src/test/java/org/solovyev/android/calculator/model/CalculatorEngineTest.java b/src/test/java/org/solovyev/android/calculator/model/CalculatorEngineTest.java index c3474bb9..c623c4da 100644 --- a/src/test/java/org/solovyev/android/calculator/model/CalculatorEngineTest.java +++ b/src/test/java/org/solovyev/android/calculator/model/CalculatorEngineTest.java @@ -5,6 +5,7 @@ package org.solovyev.android.calculator.model; +import jscl.math.Expression; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -108,6 +109,7 @@ public class CalculatorEngineTest { junit.framework.Assert.assertEquals("120", cm.evaluate(JsclOperation.numeric, "(2+2+1)!").getResult()); junit.framework.Assert.assertEquals("24", cm.evaluate(JsclOperation.numeric, "(2.0+2.0)!").getResult()); junit.framework.Assert.assertEquals("24", cm.evaluate(JsclOperation.numeric, "4.0!").getResult()); + junit.framework.Assert.assertEquals("36.0", Expression.valueOf("3!^2").numeric().toString()); try { junit.framework.Assert.assertEquals("i", cm.evaluate(JsclOperation.numeric, "i!").getResult()); fail();