Пример #1
0
  @Override
  public RobotToken map(
      final RobotLine currentLine,
      final Stack<ParsingState> processingState,
      final RobotFileOutput robotFileOutput,
      final RobotToken rt,
      final FilePosition fp,
      final String text) {
    final List<IRobotTokenType> types = rt.getTypes();
    types.remove(RobotTokenType.UNKNOWN);
    types.add(0, RobotTokenType.KEYWORD_SETTING_RETURN_VALUE);
    rt.setText(text);
    rt.setRaw(text);

    final KeywordTable keywordTable = robotFileOutput.getFileModel().getKeywordTable();
    final List<UserKeyword> keywords = keywordTable.getKeywords();
    final UserKeyword keyword = keywords.get(keywords.size() - 1);
    final List<KeywordReturn> returns = keyword.getReturns();
    final KeywordReturn keywordReturn = returns.get(returns.size() - 1);
    keywordReturn.addReturnValue(rt);

    processingState.push(ParsingState.KEYWORD_SETTING_RETURN_VALUE);

    return rt;
  }
Пример #2
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);
  }
Пример #3
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();
  }
Пример #4
0
  @Override
  public boolean checkIfCanBeMapped(
      final RobotFileOutput robotFileOutput,
      final RobotLine currentLine,
      final RobotToken rt,
      final String text,
      final Stack<ParsingState> processingState) {
    boolean result = false;
    final ParsingState state = stateHelper.getCurrentStatus(processingState);
    if (state == ParsingState.SETTING_TEST_SETUP) {
      final List<TestSetup> testSetups =
          robotFileOutput.getFileModel().getSettingTable().getTestSetups();
      result = utility.checkIfHasAlreadyKeywordName(testSetups);
    } else if (state == ParsingState.SETTING_TEST_SETUP_KEYWORD
        || state == ParsingState.SETTING_TEST_SETUP_KEYWORD_ARGUMENT) {
      result = true;
    }

    return result;
  }
Пример #5
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");
  }
Пример #6
0
  @Override
  public RobotToken map(
      final RobotLine currentLine,
      final Stack<ParsingState> processingState,
      final RobotFileOutput robotFileOutput,
      final RobotToken rt,
      final FilePosition fp,
      final String text) {
    rt.getTypes().add(0, RobotTokenType.SETTING_TEST_SETUP_KEYWORD_ARGUMENT);
    rt.setText(text);
    rt.setRaw(text);

    final SettingTable settings = robotFileOutput.getFileModel().getSettingTable();
    final List<TestSetup> setups = settings.getTestSetups();
    if (!setups.isEmpty()) {
      setups.get(setups.size() - 1).addArgument(rt);
    } else {
      // FIXME: some error
    }
    processingState.push(ParsingState.SETTING_TEST_SETUP_KEYWORD_ARGUMENT);

    return rt;
  }