예제 #1
0
  public void testNotExistingLookSensorValues() {

    List<InternToken> internTokenList = new LinkedList<InternToken>();
    internTokenList.add(new InternToken(InternTokenType.SENSOR, ""));
    InternFormulaParser internParser = new InternFormulaParser(internTokenList);
    FormulaElement parseTree = internParser.parseFormula();

    assertNull("Invalid sensor parsed:   NOT_EXISTING_SENSOR)", parseTree);
    int errorTokenIndex = internParser.getErrorTokenIndex();
    assertEquals("Error Token Index is not as expected", 0, errorTokenIndex);
  }
예제 #2
0
  public void testNotExistingUservariable() {
    List<InternToken> internTokenList = new LinkedList<InternToken>();
    internTokenList.add(
        new InternToken(InternTokenType.USER_VARIABLE, "NOT_EXISTING_USER_VARIABLE"));
    InternFormulaParser internParser = new InternFormulaParser(internTokenList);
    FormulaElement parseTree = internParser.parseFormula();

    assertNull("Invalid user variable parsed:   NOT_EXISTING_USER_VARIABLE)", parseTree);
    int errorTokenIndex = internParser.getErrorTokenIndex();
    assertEquals("Error Token Index is not as expected", 0, errorTokenIndex);
  }
예제 #3
0
  public static boolean saveFormulaForUserBrickParameterChange() {
    InternFormulaParser formulaToParse = formulaEditorEditText.getFormulaParser();
    FormulaElement formulaParseTree = formulaToParse.parseFormula();

    switch (formulaToParse.getErrorTokenIndex()) {
      case PARSER_OK:
        currentFormula.setRoot(formulaParseTree);
        if (onFormulaChangedListener != null) {
          onFormulaChangedListener.onFormulaChanged(
              formulaBrick, currentBrickField, currentFormula);
        }
        if (formulaEditorBrick != null) {
          currentFormula.refreshTextField(brickView);
        }
        formulaEditorEditText.formulaSaved();
        return true;
    }
    return false;
  }
예제 #4
0
  public boolean saveFormulaIfPossible() {
    InternFormulaParser formulaToParse = formulaEditorEditText.getFormulaParser();
    FormulaElement formulaParseTree = formulaToParse.parseFormula();

    switch (formulaToParse.getErrorTokenIndex()) {
      case PARSER_OK:
        currentFormula.setRoot(formulaParseTree);
        if (onFormulaChangedListener != null) {
          onFormulaChangedListener.onFormulaChanged(
              formulaBrick, currentBrickField, currentFormula);
        }
        if (formulaEditorBrick != null) {
          currentFormula.refreshTextField(brickView);
        }
        formulaEditorEditText.formulaSaved();
        showToast(R.string.formula_editor_changes_saved, false);
        return true;
      case PARSER_STACK_OVERFLOW:
        return checkReturnWithoutSaving(PARSER_STACK_OVERFLOW);
      default:
        formulaEditorEditText.setParseErrorCursorAndSelection();
        return checkReturnWithoutSaving(PARSER_INPUT_SYNTAX_ERROR);
    }
  }