Esempio n. 1
0
  private void test_tags_withTagsAnd3Tags(
      final String fileNameWithoutExt, final String userTestName) throws Exception {
    // prepare
    final String filePath = PRETTY_NEW_DIR_LOCATION + fileNameWithoutExt + "." + getExtension();
    final RobotFile modelFile = NewRobotFileTestHelper.getModelFileToModify("2.9");

    // test data prepare
    modelFile.includeTestCaseTableSection();
    TestCaseTable testCaseTable = modelFile.getTestCaseTable();

    RobotToken testName = new RobotToken();
    testName.setText(userTestName);
    TestCase test = new TestCase(testName);
    testCaseTable.addTest(test);
    TestCaseTags testTags = test.newTags();

    RobotToken tagOne = new RobotToken();
    tagOne.setText("tag1");
    RobotToken tagTwo = new RobotToken();
    tagTwo.setText("tag2");
    RobotToken tagThree = new RobotToken();
    tagThree.setText("tag3");
    testTags.addTag(tagOne);
    testTags.addTag(tagTwo);
    testTags.addTag(tagThree);

    // verify
    NewRobotFileTestHelper.assertNewModelTheSameAsInFile(filePath, modelFile);
  }
  @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);
  }
Esempio n. 3
0
  private void test_tagsDec_andComment(final String fileNameWithoutExt, final String userTestName)
      throws Exception {
    // prepare
    final String filePath = PRETTY_NEW_DIR_LOCATION + fileNameWithoutExt + "." + getExtension();
    final RobotFile modelFile = NewRobotFileTestHelper.getModelFileToModify("2.9");

    // test data prepare
    modelFile.includeTestCaseTableSection();
    TestCaseTable testCaseTable = modelFile.getTestCaseTable();

    RobotToken testName = new RobotToken();
    testName.setText(userTestName);
    TestCase test = new TestCase(testName);
    testCaseTable.addTest(test);
    TestCaseTags testTags = test.newTags();

    RobotToken cmTok1 = new RobotToken();
    cmTok1.setText("cm1");
    RobotToken cmTok2 = new RobotToken();
    cmTok2.setText("cm2");
    RobotToken cmTok3 = new RobotToken();
    cmTok3.setText("cm3");

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

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

    // test data prepare
    modelFile.includeSettingTableSection();
    final SettingTable settingTable = modelFile.getSettingTable();
    final TestSetup testSetup = settingTable.newTestSetup();

    RobotToken keyword = new RobotToken();
    keyword.setText("keyword");

    testSetup.setKeywordName(keyword);

    RobotToken cm1 = new RobotToken();
    cm1.setText("cm1");
    RobotToken cm2 = new RobotToken();
    cm2.setText("cm2");
    RobotToken cm3 = new RobotToken();
    cm3.setText("cm3");
    testSetup.addCommentPart(cm1);
    testSetup.addCommentPart(cm2);
    testSetup.addCommentPart(cm3);

    // verify
    NewRobotFileTestHelper.assertNewModelTheSameAsInFile(fileName, modelFile);
  }
Esempio n. 5
0
  @Test
  public void test_eolInLinux_lineChecks_offsetCheck() {
    // prepare
    final String fileContent = "*** Test Cases ***\nTest1\n\tLog\t\tc\n";

    final RobotRuntimeEnvironment runtime = mock(RobotRuntimeEnvironment.class);
    when(runtime.getVersion()).thenReturn("2.9");
    final RobotProjectHolder projectHolder = spy(RobotProjectHolder.class);
    when(projectHolder.getRobotRuntime()).thenReturn(runtime);

    // execute
    final RobotParser parser =
        RobotParser.create(projectHolder, RobotParserConfig.allImportsLazy());
    final RobotFileOutput editorContent =
        parser.parseEditorContent(fileContent, new File("f.robot"));

    // verify
    final RobotFile fileModel = editorContent.getFileModel();
    final List<RobotLine> lineContents = fileModel.getFileContent();
    assertThat(lineContents).hasSize(4);
    assertLine(lineContents.get(0), Arrays.asList("*** Test Cases ***"), "\n");
    assertLine(lineContents.get(1), Arrays.asList("Test1"), "\n");
    assertLine(lineContents.get(2), Arrays.asList("\t", "Log", "\t\t", "c"), "\n");
    assertLine(lineContents.get(3), new ArrayList<String>(0), null);
  }
Esempio n. 6
0
  @Test
  public void
      test_givenTwoTestCasesInTsvFile_oneIsEmpty_andSecondIsJustVariableName_withEmptyExecute()
          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("parser/bugs/tsv_positionCheck.tsv").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();
    assertThatTestCaseTableIsIncluded(robotModel);
    final TestCaseTable testCaseTable = robotModel.getTestCaseTable();
    final List<TestCase> testCases = testCaseTable.getTestCases();
    assertThat(testCases).hasSize(2);
    final TestCase testCaseT3 = testCases.get(0);

    //// verify test case T3
    final RobotToken testCaseT3Name = testCaseT3.getName();
    assertThat(testCaseT3Name.getText()).isEqualTo("T3");
    assertThat(testCaseT3Name.getRaw()).isEqualTo("T3");
    final FilePosition tcT3Pos = testCaseT3Name.getFilePosition();
    assertThat(tcT3Pos.isSamePlace(new FilePosition(2, 0, 20))).as("got %s", tcT3Pos).isTrue();
    assertThat(testCaseT3.getExecutionContext()).isEmpty();

    //// verify test case ${x}
    final TestCase testCaseSpacesX = testCases.get(1);
    assertThat(testCaseSpacesX.getName().getText()).isEqualTo("${x}");
    assertThat(testCaseSpacesX.getName().getRaw()).isEqualTo("${x}");
    final FilePosition tcXPos = testCaseSpacesX.getName().getFilePosition();
    assertThat(tcXPos.isSamePlace(new FilePosition(3, 4, 28))).as("got %s", tcXPos).isTrue();
    final List<RobotExecutableRow<TestCase>> xTestExecutionList =
        testCaseSpacesX.getExecutionContext();
    assertThat(xTestExecutionList).hasSize(1);
    final IExecutableRowDescriptor<TestCase> xTestFirstLineDescription =
        xTestExecutionList.get(0).buildLineDescription();

    final RobotAction action = xTestFirstLineDescription.getAction();
    final RobotToken emptyAction = action.getToken();
    assertThat(emptyAction.getText()).isEmpty();
    assertThat(emptyAction.getRaw()).isEmpty();
    final FilePosition emptyActionPosition = emptyAction.getFilePosition();
    assertThat(emptyActionPosition.isSamePlace(new FilePosition(4, 5, 43)))
        .as("got %s", emptyActionPosition)
        .isTrue();
  }
  @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);
  }
  @Test
  public void test_emptyFile_and_thanCreateTestSetup() throws Exception {
    // prepare
    final String fileName =
        PRETTY_NEW_DIR_LOCATION + "EmptyTestSetupDeclarationOnly." + getExtension();
    final RobotFile modelFile = NewRobotFileTestHelper.getModelFileToModify("2.9");

    // test data prepare
    modelFile.includeSettingTableSection();
    final SettingTable settingTable = modelFile.getSettingTable();
    settingTable.newTestSetup();

    // verify
    NewRobotFileTestHelper.assertNewModelTheSameAsInFile(fileName, modelFile);
  }
  @Override
  public void map(
      final RobotLine currentLine,
      final RobotToken rt,
      final ParsingState currentState,
      final RobotFile fileModel) {
    List<TestCase> testCases = fileModel.getTestCaseTable().getTestCases();
    TestCase testCase = testCases.get(testCases.size() - 1);

    List<TestCaseTags> tags = testCase.getTags();
    TestCaseTags testCaseTags = tags.get(tags.size() - 1);
    testCaseTags.addCommentPart(rt);
  }
  @Override
  public void map(
      final RobotLine currentLine,
      final RobotToken rt,
      final ParsingState currentState,
      final RobotFile fileModel) {
    List<UserKeyword> keywords = fileModel.getKeywordTable().getKeywords();
    UserKeyword keyword = keywords.get(keywords.size() - 1);

    List<KeywordDocumentation> documentation = keyword.getDocumentation();
    KeywordDocumentation testDocumentation = documentation.get(documentation.size() - 1);
    testDocumentation.addCommentPart(rt);
  }
Esempio n. 11
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");
  }
 @Override
 public void map(
     final RobotLine currentLine,
     final RobotToken rt,
     final ParsingState currentState,
     final RobotFile fileModel) {
   List<SuiteDocumentation> documentations = fileModel.getSettingTable().getDocumentation();
   if (!documentations.isEmpty()) {
     SuiteDocumentation suiteDoc = documentations.get(documentations.size() - 1);
     suiteDoc.addCommentPart(rt);
   } else {
     // FIXME: errors
   }
 }
 @Override
 public void map(
     final RobotLine currentLine,
     final RobotToken rt,
     final ParsingState currentState,
     final RobotFile fileModel) {
   List<TestTemplate> testTemplates = fileModel.getSettingTable().getTestTemplates();
   if (!testTemplates.isEmpty()) {
     TestTemplate testTemplate = testTemplates.get(testTemplates.size() - 1);
     testTemplate.addCommentPart(rt);
   } else {
     // FIXME: errors internal
   }
 }
Esempio n. 14
0
 private void assertThatTestCaseTableIsIncluded(final RobotFile fileModel) {
   assertThat(fileModel.getSettingTable().isPresent()).isFalse();
   assertThat(fileModel.getVariableTable().isPresent()).isFalse();
   assertThat(fileModel.getTestCaseTable().isPresent()).isTrue();
   assertThat(fileModel.getKeywordTable().isPresent()).isFalse();
 }