@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); }
@Test public void variablesDefinedInVariablesFilesAreLocated_onlyUntilDetectorWantsToContinue() throws Exception { final IFile sourceFile = projectProvider.createFile( "importingFile.robot", createVariablesImportSettingsSection("vars.py")); final RobotModel model = new RobotModel(); final RobotSuiteFile suiteFile = model.createSuiteFile(sourceFile); final RobotSettingsSection settings = suiteFile.findSection(RobotSettingsSection.class).get(); final RobotSetting varSetting = (RobotSetting) settings.findChild("Variables"); final VariablesImport varsImport = (VariablesImport) varSetting.getLinkedElement(); final VariablesFileImportReference varsImportRef = new VariablesFileImportReference(varsImport); varsImportRef.map(ImmutableMap.of("var_a", 42, "var_b", 1729)); final RobotFileOutput output = suiteFile.getLinkedElement().getParent(); output.setVariablesImportReferences(newArrayList(varsImportRef)); final Set<String> visitedVars = new HashSet<>(); final VariableDefinitionLocator locator = new VariableDefinitionLocator(sourceFile, model); locator.locateVariableDefinition(limitedVarFileVariableDetector(visitedVars)); assertThat(visitedVars).containsOnly("${var_a}"); }
@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(); }
@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; }
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 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; }
@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; }
@Test(timeout = 10000) public void test_loopedResources_shouldPassFastAndWithoutAny_reReadFiles_BUG_RED_352_GITHUB_23() 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.allImportsEager())); //// prepare paths final String mainPath = "parser/bugs/RED_352_ReadManyTimesPrevReadReferenceFile_LoopPrevent/"; final File startFile = new File(this.getClass().getResource(mainPath + "StartFile.robot").toURI()); final File normalFile = new File(this.getClass().getResource(mainPath + "NormalFile.robot").toURI()); final File anotherLoop = new File(this.getClass().getResource(mainPath + "anotherLoop.robot").toURI()); final File loopEndWithRefToFirst = new File( this.getClass() .getResource(mainPath + "resources/loopEndWithRefToFirst.robot") .toURI()); final File middle = new File(this.getClass().getResource(mainPath + "resources/Middle.robot").toURI()); final File theFirst = new File(this.getClass().getResource(mainPath + "resources/theFirst.robot").toURI()); // execute final List<RobotFileOutput> output = parser.parse(startFile); // verify content //// StartFile.robot assertThat(output).hasSize(1); final RobotFileOutput startFileOutput = output.get(0); assertThat(startFileOutput.getProcessedFile()).isEqualTo(startFile); final List<ResourceImportReference> resourceImportReferences = startFileOutput.getResourceImportReferences(); assertThat(resourceImportReferences).hasSize(3); final ResourceImportReference theFirstImportMain = resourceImportReferences.get(0); assertThat(theFirstImportMain.getImportDeclaration().getPathOrName().getText()) .isEqualTo("NormalFile.robot"); assertThat(theFirstImportMain.getReference().getProcessedFile()).isEqualTo(normalFile); final ResourceImportReference anotherFileResource = resourceImportReferences.get(1); assertThat(anotherFileResource.getImportDeclaration().getPathOrName().getText()) .isEqualTo("anotherLoop.robot"); assertThat(anotherFileResource.getReference().getProcessedFile()).isEqualTo(anotherLoop); final ResourceImportReference res_theFirst = resourceImportReferences.get(2); assertThat(res_theFirst.getImportDeclaration().getPathOrName().getText()) .isEqualTo("resources/theFirst.robot"); assertThat(res_theFirst.getReference().getProcessedFile()).isEqualTo(theFirst); //// NormalFile.robot final RobotFileOutput normalFileOutput = theFirstImportMain.getReference(); assertThat(normalFileOutput.getResourceImportReferences()).hasSize(0); //// anotherLoop.robot final RobotFileOutput anotherFileOutput = anotherFileResource.getReference(); final List<ResourceImportReference> anotherLoopRefs = anotherFileOutput.getResourceImportReferences(); assertThat(anotherLoopRefs).hasSize(1); final ResourceImportReference loopEndRef = anotherLoopRefs.get(0); assertThat(loopEndRef.getImportDeclaration().getPathOrName().getText()) .isEqualTo("resources/loopEndWithRefToFirst.robot"); assertThat(loopEndRef.getReference().getProcessedFile()).isEqualTo(loopEndWithRefToFirst); //// loopEndWithRefToFirst.robot final RobotFileOutput loopEndOutput = loopEndRef.getReference(); final List<ResourceImportReference> loopEndRefs = loopEndOutput.getResourceImportReferences(); assertThat(loopEndRefs).hasSize(1); final ResourceImportReference middleRef = loopEndRefs.get(0); assertThat(middleRef.getImportDeclaration().getPathOrName().getText()) .isEqualTo("../resources/Middle.robot"); assertThat(middleRef.getReference().getProcessedFile()).isEqualTo(middle); //// middle.robot final RobotFileOutput middleOutput = middleRef.getReference(); final List<ResourceImportReference> middleRefs = middleOutput.getResourceImportReferences(); assertThat(middleRefs).hasSize(1); final ResourceImportReference res_theFirstAgain = middleRefs.get(0); assertThat(res_theFirstAgain.getImportDeclaration().getPathOrName().getText()) .isEqualTo("../resources/theFirst.robot"); assertThat(res_theFirstAgain.getReference()).isSameAs(res_theFirst.getReference()); // verify order final InOrder order = inOrder(projectHolder, parser); order.verify(projectHolder, times(1)).shouldBeLoaded(startFile); order.verify(projectHolder, times(1)).addModelFile(output.get(0)); order.verify(projectHolder, times(1)).shouldBeLoaded(normalFile); order.verify(projectHolder, times(1)).addModelFile(theFirstImportMain.getReference()); order.verify(projectHolder, times(1)).shouldBeLoaded(anotherLoop); order.verify(projectHolder, times(1)).addModelFile(anotherFileResource.getReference()); order.verify(projectHolder, times(1)).shouldBeLoaded(loopEndWithRefToFirst); order.verify(projectHolder, times(1)).addModelFile(loopEndRef.getReference()); order.verify(projectHolder, times(1)).shouldBeLoaded(middle); order.verify(projectHolder, times(1)).addModelFile(middleRef.getReference()); order.verify(projectHolder, times(1)).shouldBeLoaded(theFirst); order.verify(projectHolder, times(1)).addModelFile(res_theFirst.getReference()); order.verify(projectHolder, times(1)).shouldBeLoaded(theFirst); order.verify(projectHolder, times(1)).findFileByName(theFirst); }