@Test
  public void test_emptyFile_and_thanCreateScalarVariable_andOneValue_andComment()
      throws Exception {
    // prepare
    final String fileName =
        PRETTY_NEW_DIR_LOCATION
            + "ScalarVariableDeclarationAndOneValueAndCommentOnly."
            + getExtension();
    final RobotFile modelFile = NewRobotFileTestHelper.getModelFileToModify("2.9");

    // test data prepare
    modelFile.includeVariableTableSection();
    final VariableTable variableTable = modelFile.getVariableTable();
    final List<String> values = new ArrayList<>();
    values.add("value1");

    final AVariable aVariable = variableTable.createScalarVariable(0, "scalar", values);
    final RobotToken cmTok1 = new RobotToken();
    cmTok1.setText("cm1");
    final RobotToken cmTok2 = new RobotToken();
    cmTok2.setText("cm2");
    final RobotToken cmTok3 = new RobotToken();
    cmTok3.setText("cm3");

    aVariable.addCommentPart(cmTok1);
    aVariable.addCommentPart(cmTok2);
    aVariable.addCommentPart(cmTok3);

    // verify
    NewRobotFileTestHelper.assertNewModelTheSameAsInFile(fileName, modelFile);
  }
  @Test
  public void test_emptyFile_and_thanCreateScalarVariable() throws Exception {
    // prepare
    final String fileName =
        PRETTY_NEW_DIR_LOCATION + "EmptyScalarVariableDeclarationOnly." + getExtension();
    final RobotFile modelFile = NewRobotFileTestHelper.getModelFileToModify("2.9");

    // test data prepare
    modelFile.includeVariableTableSection();
    final VariableTable variableTable = modelFile.getVariableTable();
    variableTable.createScalarVariable(0, "scalar", new ArrayList<String>());

    // verify
    NewRobotFileTestHelper.assertNewModelTheSameAsInFile(fileName, modelFile);
  }
Example #3
0
  private void assertOneCorrectAndOneWrongVariable_ifAllWasReadAndWillBePresented(
      final String filename) throws Exception {
    // prepare
    final RobotRuntimeEnvironment runtime = mock(RobotRuntimeEnvironment.class);
    when(runtime.getVersion()).thenReturn("2.9");
    final RobotProjectHolder projectHolder = spy(RobotProjectHolder.class);
    when(projectHolder.getRobotRuntime()).thenReturn(runtime);

    final RobotParser parser =
        spy(RobotParser.create(projectHolder, RobotParserConfig.allImportsLazy()));

    //// prepare paths
    final File startFile = new File(this.getClass().getResource(filename).toURI());

    // execute
    final List<RobotFileOutput> output = parser.parse(startFile);

    // verify
    assertThat(output).hasSize(1);
    final RobotFileOutput file = output.get(0);
    final RobotFile robotModel = file.getFileModel();
    assertThatVariableTableIsIncluded(robotModel);
    final VariableTable variableTable = robotModel.getVariableTable();
    final List<AVariable> variables = variableTable.getVariables();
    assertThat(variables).hasSize(2);
    final AVariable varCorrect = variables.get(0);
    assertThat(varCorrect).isInstanceOf(ScalarVariable.class);
    assertThat(varCorrect.getDeclaration().getText()).isEqualTo("${var_ok}");
    assertThat(varCorrect.getDeclaration().getRaw()).isEqualTo("${var_ok}");
    assertThat(varCorrect.getType()).isEqualTo(VariableType.SCALAR);
    assertThat(varCorrect.getName()).isEqualTo("var_ok");

    final AVariable varIncorrect = variables.get(1);
    assertThat(varIncorrect).isInstanceOf(UnknownVariable.class);
    assertThat(varIncorrect.getDeclaration().getText()).isEqualTo("${var} data");
    assertThat(varIncorrect.getDeclaration().getRaw()).isEqualTo("${var} data");
    assertThat(varIncorrect.getType()).isEqualTo(VariableType.INVALID);
    assertThat(varIncorrect.getName()).isEqualTo("${var} data");
  }