GraphsCompletionProposer implements ICompletionProposer { @Override public List<RoboconfCompletionProposal> findProposals( String text ) { List<RoboconfCompletionProposal> proposals = new ArrayList<> (); Ctx ctx = findContext( text ); switch( ctx.kind ) { case NEUTRAL: if( startsWith( IMPORT_PREFIX, ctx.property )) { if( ! ctx.property.matches( "(?i)" + KEYWORD_IMPORT + "\\s+" )) proposals.add( basicProposal( IMPORT_PREFIX, ctx.property, true )); else for( String graphImport : CompletionUtils.findGraphFilesToImport( this.appDirectory, this.editedFile, text )) { if( startsWith( graphImport, ctx.lastWord )) proposals.add( basicProposal( graphImport, "", false )); } } if( ! Utils.isEmptyOrWhitespaces( ctx.lastWord )) break; ctx.property = ctx.property.trim(); if( startsWith( FACET_PREFIX, ctx.property )) { proposals.add( basicProposal( FACET_PREFIX, ctx.property, true )); String proposalString = FACET_PREFIX + "name {\n\t\n}"; RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, FACET_BLOCK, FACET_BLOCK + "\n\n" + proposalString.trim(), ctx.property.length()); proposal.getSelection().add( new SelectionRange( 6, 4 )); proposals.add( proposal ); } if( Utils.isEmptyOrWhitespaces( ctx.property )) { String proposalString = "name {\n\t\n}"; RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, COMPONENT_BLOCK, COMPONENT_BLOCK + "\n\n" + proposalString.trim(), ctx.property.length()); proposal.getSelection().add( new SelectionRange( 0, 4 )); proposals.add( proposal ); } break; case ATTRIBUTE: String[] arr = ctx.facet ? FACET_PROPERTY_NAMES : COMPONENT_PROPERTY_NAMES; for( String s : arr ) { s += ": "; if( startsWith( s, ctx.lastWord )) proposals.add( basicProposal( s, ctx.lastWord )); } break; case PROPERTY: ctx.property = ctx.property.trim(); Map<String,String> candidates = findPropertyCandidates( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); break; default: break; } return proposals; } GraphsCompletionProposer( File appDirectory, File editedFile ); @Override List<RoboconfCompletionProposal> findProposals( String text );  }
@Test public void testOffsetAtZero() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 0 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); verifyNeutralOffset( proposals ); }
@Test public void testOffsetInComment() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 9 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetRightBeforeComment_1() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 1 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); verifyNeutralOffset( proposals ); }
@Test public void testOffsetRightBeforeComment_2() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 21 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); verifyNeutralOffset( proposals ); }
@Test public void testOffsetRightAfterCommentSymbol() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 2 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetBetweenTwoTypes() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 44 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); verifyNeutralOffset( proposals ); couple = prepare( "app1", "edited1.graph", 60 ); proposals = couple.proposer.findProposals( couple.text ); verifyNeutralOffset( proposals ); couple = prepare( "app1", "edited1.graph", 70 ); proposals = couple.proposer.findProposals( couple.text ); verifyNeutralOffset( proposals ); couple.text = "comp {\n}\n"; proposals = couple.proposer.findProposals( couple.text ); verifyNeutralOffset( proposals ); couple.text = "comp {\n}"; proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetInsideFacetBeginning() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\nfac"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 2, proposals.size()); Assert.assertEquals( KEYWORD_FACET, proposals.get( 0 ).getProposalName()); Assert.assertEquals( FACET_PREFIX, proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 3, proposals.get( 0 ).getReplacementOffset()); Assert.assertEquals( FACET_BLOCK, proposals.get( 1 ).getProposalName()); Assert.assertTrue( proposals.get( 1 ).getProposalString().startsWith( FACET_PREFIX )); Assert.assertTrue( proposals.get( 1 ).getProposalDescription().startsWith( FACET_BLOCK )); Assert.assertEquals( 3, proposals.get( 1 ).getReplacementOffset()); }
@Test public void testOffsetInsideFakeFacetBeginning() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\nfac anotherWord"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetRightAfterClosingBracket() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 59 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetInsideImportBeginning() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\nimpo"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( KEYWORD_IMPORT, proposals.get( 0 ).getProposalName()); Assert.assertEquals( IMPORT_PREFIX, proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 4, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetInsideImportBeginningAndUpperCase() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\niMPo"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( KEYWORD_IMPORT, proposals.get( 0 ).getProposalName()); Assert.assertEquals( IMPORT_PREFIX, proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 4, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetInsideFacet() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\nfacet f {\n\t"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( FACET_PROPERTY_NAMES.length, proposals.size()); for( int i=0; i<FACET_PROPERTY_NAMES.length; i++ ) { Assert.assertEquals( FACET_PROPERTY_NAMES[ i ], FACET_PROPERTY_NAMES[ i ] + ": ", proposals.get( i ).getProposalName()); Assert.assertEquals( FACET_PROPERTY_NAMES[ i ], FACET_PROPERTY_NAMES[ i ] + ": ", proposals.get( i ).getProposalString()); Assert.assertNull( FACET_PROPERTY_NAMES[ i ], proposals.get( i ).getProposalDescription()); Assert.assertEquals( FACET_PROPERTY_NAMES[ i ], 0, proposals.get( i ).getReplacementOffset()); } }
@Test public void testOffsetInsideFacetWithValidPrefix() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\nfacet f {\n\texp"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( PROPERTY_GRAPH_EXPORTS + ": ", proposals.get( 0 ).getProposalName()); Assert.assertEquals( PROPERTY_GRAPH_EXPORTS + ": ", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 3, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetInsideFacetWithInvalidPrefix() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\nfacet f {\n\tnaw"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetInsideComponent() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\ncomp {\n\t"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( COMPONENT_PROPERTY_NAMES.length, proposals.size()); for( int i=0; i<COMPONENT_PROPERTY_NAMES.length; i++ ) { Assert.assertEquals( COMPONENT_PROPERTY_NAMES[ i ], COMPONENT_PROPERTY_NAMES[ i ] + ": ", proposals.get( i ).getProposalName()); Assert.assertEquals( COMPONENT_PROPERTY_NAMES[ i ], COMPONENT_PROPERTY_NAMES[ i ] + ": ", proposals.get( i ).getProposalString()); Assert.assertNull( COMPONENT_PROPERTY_NAMES[ i ], proposals.get( i ).getProposalDescription()); Assert.assertEquals( COMPONENT_PROPERTY_NAMES[ i ], 0, proposals.get( i ).getReplacementOffset()); } }
@Test public void testOffsetInsideComponentWithValidPrefix() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\ncomp {\n\texpo"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( PROPERTY_GRAPH_EXPORTS + ": ", proposals.get( 0 ).getProposalName()); Assert.assertEquals( PROPERTY_GRAPH_EXPORTS + ": ", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 4, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetInsideComponentWithInvalidPrefix() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\ncomp {\n\tnaw"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetInsideComponentRightBeforeColon() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\ncomp {\n\texport"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( PROPERTY_GRAPH_EXPORTS + ": ", proposals.get( 0 ).getProposalName()); Assert.assertEquals( PROPERTY_GRAPH_EXPORTS + ": ", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 6, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetInsideComponentRightAfterColon() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\ncomp {\n\texports:"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( PROPERTY_GRAPH_EXPORTS + ": ", proposals.get( 0 ).getProposalName()); Assert.assertEquals( PROPERTY_GRAPH_EXPORTS + ": ", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 8, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetInsideComponentAfterColon() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\ncomp {\n\texports: "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForInstallerNamesWithoutPrefix() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\ncomp {\n\tinstaller: "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); List<String> installerNames = new ArrayList<>( Arrays.asList( KNOWN_INSTALLERS )); Collections.sort( installerNames ); Assert.assertEquals( installerNames.size(), proposals.size()); for( int i=0; i<installerNames.size(); i++ ) { Assert.assertEquals( installerNames.get( i ), installerNames.get( i ), proposals.get( i ).getProposalName()); Assert.assertEquals( installerNames.get( i ), installerNames.get( i ), proposals.get( i ).getProposalString()); Assert.assertNull( installerNames.get( i ), proposals.get( i ).getProposalDescription()); Assert.assertEquals( installerNames.get( i ), 0, proposals.get( i ).getReplacementOffset()); } }
@Test public void testOffsetForInstallerNamesWithValidPrefix() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\ncomp {\n\tinstaller: log"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( "logger", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "logger", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 3, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetForInstallerNamesWithInvalidPrefix_1() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\ncomp {\n\tinstaller: what"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForInstallerNamesWithInvalidPrefix_2() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\ncomp {\n\tinstaller: log "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForInstallerNamesWithValidPrefixAndUpperCase() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\ncomp {\n\tinstaller: LOg"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( "logger", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "logger", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 3, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetForFacetChildrenWithoutPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\nfacet myfacet {\n\tchildren: "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 3, proposals.size()); Assert.assertEquals( "c1", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "c1", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 0 ).getReplacementOffset()); Assert.assertEquals( "c2", proposals.get( 1 ).getProposalName()); Assert.assertEquals( "c2", proposals.get( 1 ).getProposalString()); Assert.assertNull( proposals.get( 1 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 1 ).getReplacementOffset()); Assert.assertEquals( "f1", proposals.get( 2 ).getProposalName()); Assert.assertEquals( "f1", proposals.get( 2 ).getProposalString()); Assert.assertNull( proposals.get( 2 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 2 ).getReplacementOffset()); }
@Test public void testOffsetForFacetChildrenWithPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\nfacet myfacet {\n\tchildren: C"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 2, proposals.size()); Assert.assertEquals( "c1", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "c1", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 1, proposals.get( 0 ).getReplacementOffset()); Assert.assertEquals( "c2", proposals.get( 1 ).getProposalName()); Assert.assertEquals( "c2", proposals.get( 1 ).getProposalString()); Assert.assertNull( proposals.get( 1 ).getProposalDescription()); Assert.assertEquals( 1, proposals.get( 1 ).getReplacementOffset()); }
@Test public void testOffsetForComponentChildrenWithoutPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\ncomp {\n\tchildren: "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 3, proposals.size()); Assert.assertEquals( "c1", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "c1", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 0 ).getReplacementOffset()); Assert.assertEquals( "c2", proposals.get( 1 ).getProposalName()); Assert.assertEquals( "c2", proposals.get( 1 ).getProposalString()); Assert.assertNull( proposals.get( 1 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 1 ).getReplacementOffset()); Assert.assertEquals( "f1", proposals.get( 2 ).getProposalName()); Assert.assertEquals( "f1", proposals.get( 2 ).getProposalString()); Assert.assertNull( proposals.get( 2 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 2 ).getReplacementOffset()); }
@Test public void testOffsetForComponentChildrenWithPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\ncomp {\n\tchildren: C"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 2, proposals.size()); Assert.assertEquals( "c1", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "c1", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 1, proposals.get( 0 ).getReplacementOffset()); Assert.assertEquals( "c2", proposals.get( 1 ).getProposalName()); Assert.assertEquals( "c2", proposals.get( 1 ).getProposalString()); Assert.assertNull( proposals.get( 1 ).getProposalDescription()); Assert.assertEquals( 1, proposals.get( 1 ).getReplacementOffset()); }
@Test public void testOffsetForFacetExtendsWithoutPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\nfacet myfacet {\n\textends: "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( "f1", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "f1", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetForFacetExtendsWithValidPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\nfacet myfacet {\n\textends: f"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( "f1", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "f1", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 1, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetForFacetExtendsWithInvalidPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\nfacet myfacet {\n\textends: no"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForComponentExtendsWithoutPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\ncomp {\n\textends: "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 2, proposals.size()); Assert.assertEquals( "c1", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "c1", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 0 ).getReplacementOffset()); Assert.assertEquals( "c2", proposals.get( 1 ).getProposalName()); Assert.assertEquals( "c2", proposals.get( 1 ).getProposalString()); Assert.assertNull( proposals.get( 1 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 1 ).getReplacementOffset()); }
@Test public void testOffsetForComponentExtendsWithValidPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\ncomp {\n\textends: C"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 2, proposals.size()); Assert.assertEquals( "c1", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "c1", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 1, proposals.get( 0 ).getReplacementOffset()); Assert.assertEquals( "c2", proposals.get( 1 ).getProposalName()); Assert.assertEquals( "c2", proposals.get( 1 ).getProposalString()); Assert.assertNull( proposals.get( 1 ).getProposalDescription()); Assert.assertEquals( 1, proposals.get( 1 ).getReplacementOffset()); }
@Test public void testOffsetForComponentExtendsWithInvalidPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\ncomp {\n\textends: no"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForComponentFacetsWithoutPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\ncomp {\n\tfacets: "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( "f1", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "f1", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetForComponentFacetsWithValidPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\ncomp {\n\tfacets: F"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( "f1", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "f1", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 1, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetForComponentFacetsWithInvalidPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\ncomp {\n\tfacets: no"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForFacetFacetsWithoutPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\nfacet myfacet {\n\tfacets: "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForFacetInstallerWithoutPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\nfacet myfacet {\n\tinstaller: "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForFacetVariablesImportsWithoutPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\nfacet myfacet {\n\timports: "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForComponentCommentsWithoutPrefix() throws Exception { Couple couple = prepare( "app3", "edited3.graph", 200 ); couple.text += "\ncomp {\n\tchildren: "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 4, proposals.size()); Assert.assertEquals( "c1", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "c1", proposals.get( 0 ).getProposalString()); Assert.assertEquals( "A comment about c1", proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 0 ).getReplacementOffset()); Assert.assertEquals( "c2", proposals.get( 1 ).getProposalName()); Assert.assertEquals( "c2", proposals.get( 1 ).getProposalString()); Assert.assertNull( proposals.get( 1 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 1 ).getReplacementOffset()); Assert.assertEquals( "f1", proposals.get( 2 ).getProposalName()); Assert.assertEquals( "f1", proposals.get( 2 ).getProposalString()); Assert.assertEquals( "This is facet f1.\nAnd the desc spans over two lines.", proposals.get( 2 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 2 ).getReplacementOffset()); Assert.assertEquals( "f2", proposals.get( 3 ).getProposalName()); Assert.assertEquals( "f2", proposals.get( 3 ).getProposalString()); Assert.assertEquals( "Simple comment.", proposals.get( 3 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 3 ).getReplacementOffset()); }
@Test public void testOffsetForGraphImportAllFiles() throws Exception { Couple couple = prepare( "app3", "edited3.graph", 700 ); couple.text += "\nimport "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 3, proposals.size()); String[] expected = { "imports/imp1.graph", "imports/subimports/imp2.graph", "imports/subimports/imp3.graph" }; for( int i=0; i<expected.length; i++ ) { Assert.assertEquals( expected[ i ], proposals.get( i ).getProposalName()); Assert.assertEquals( expected[ i ], proposals.get( i ).getProposalString()); Assert.assertNull( proposals.get( i ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( i ).getReplacementOffset()); } }
@Test public void testOffsetForGraphImportNoSpaceAfterKeyword() throws Exception { Couple couple = prepare( "app3", "edited3.graph", 700 ); couple.text += "\nimport"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( KEYWORD_IMPORT, proposals.get( 0 ).getProposalName()); Assert.assertEquals( IMPORT_PREFIX, proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( KEYWORD_IMPORT.length(), proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetForGraphImportWithPrefix() throws Exception { Couple couple = prepare( "app3", "edited3.graph", 700 ); couple.text += "\nimport imports/s"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 2, proposals.size()); String[] expected = { "imports/subimports/imp2.graph", "imports/subimports/imp3.graph" }; for( int i=0; i<expected.length; i++ ) { Assert.assertEquals( expected[ i ], proposals.get( i ).getProposalName()); Assert.assertEquals( expected[ i ], proposals.get( i ).getProposalString()); Assert.assertNull( proposals.get( i ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( i ).getReplacementOffset()); } }
@Test public void testOffsetForGraphImportAvoidDuplicates() throws Exception { Couple couple = prepare( "app3", "edited3.graph", 700 ); couple.text += "\nimport imports/subimports/imp2.graph\n\nimport "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 2, proposals.size()); String[] expected = { "imports/imp1.graph", "imports/subimports/imp3.graph" }; for( int i=0; i<expected.length; i++ ) { Assert.assertEquals( expected[ i ], proposals.get( i ).getProposalName()); Assert.assertEquals( expected[ i ], proposals.get( i ).getProposalString()); Assert.assertNull( proposals.get( i ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( i ).getReplacementOffset()); } }
@Test public void testOffsetForGraphImportAvoidNastyDuplicates() throws Exception { Couple couple = prepare( "app3", "edited3.graph", 700 ); couple.text += "\nimport imports/subimports/imp2.graph ; \n\nimport imp"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 2, proposals.size()); String[] expected = { "imports/imp1.graph", "imports/subimports/imp3.graph" }; for( int i=0; i<expected.length; i++ ) { Assert.assertEquals( expected[ i ], proposals.get( i ).getProposalName()); Assert.assertEquals( expected[ i ], proposals.get( i ).getProposalString()); Assert.assertNull( proposals.get( i ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( i ).getReplacementOffset()); } }
@Test public void testOffsetForVariablesImportsWithoutPrefix() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\ncomp {\n\timports: "; Map<String,String> expected = new TreeMap<> (); expected.put( "c1.*", CompletionUtils.IMPORT_ALL_THE_VARIABLES ); expected.put( "c1.v1", CompletionUtils.DEFAULT_VALUE + "version1" ); expected.put( "c1.v2", CompletionUtils.DEFAULT_VALUE + "version2" ); expected.put( "c1.ip", CompletionUtils.SET_BY_ROBOCONF ); expected.put( "c1.port", CompletionUtils.DEFAULT_VALUE + "8100" ); expected.put( "c2.*", CompletionUtils.IMPORT_ALL_THE_VARIABLES ); expected.put( "c2.ip", CompletionUtils.SET_BY_ROBOCONF ); expected.put( "f1.*", CompletionUtils.IMPORT_ALL_THE_VARIABLES ); expected.put( "f1.v1", CompletionUtils.DEFAULT_VALUE + "version1" ); expected.put( "f1.v2", CompletionUtils.DEFAULT_VALUE + "version2" ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( expected.size(), proposals.size()); int index = 0; for( Map.Entry<String,String> entry : expected.entrySet()) { Assert.assertEquals( entry.getKey(), proposals.get( index ).getProposalName()); Assert.assertEquals( entry.getKey(), proposals.get( index ).getProposalString()); Assert.assertEquals( entry.getValue(), proposals.get( index ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( index ).getReplacementOffset()); index ++; } }
@Test public void testOffsetForVariablesImportsSkipNonExporting_BrokenGraph_1() throws Exception { Couple couple = prepare( "app5", "edited5.graph", 394 ); Map<String,String> expected = new TreeMap<> (); expected.put( "c1.*", CompletionUtils.IMPORT_ALL_THE_VARIABLES ); expected.put( "c1.v1", CompletionUtils.DEFAULT_VALUE + "version1" ); expected.put( "c1.v2", CompletionUtils.DEFAULT_VALUE + "version2" ); expected.put( "c1.ip", CompletionUtils.SET_BY_ROBOCONF ); expected.put( "c1.port", CompletionUtils.DEFAULT_VALUE + "8100" ); expected.put( "c2.*", CompletionUtils.IMPORT_ALL_THE_VARIABLES ); expected.put( "c2.ip", CompletionUtils.SET_BY_ROBOCONF ); expected.put( "f1.*", CompletionUtils.IMPORT_ALL_THE_VARIABLES ); expected.put( "f1.v1", CompletionUtils.DEFAULT_VALUE + "version1" ); expected.put( "f1.v2", CompletionUtils.DEFAULT_VALUE + "version2" ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( expected.size(), proposals.size()); int index = 0; for( Map.Entry<String,String> entry : expected.entrySet()) { Assert.assertEquals( entry.getKey(), proposals.get( index ).getProposalName()); Assert.assertEquals( entry.getKey(), proposals.get( index ).getProposalString()); Assert.assertEquals( entry.getValue(), proposals.get( index ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( index ).getReplacementOffset()); index ++; } }
@Test public void testOffsetForVariablesImportsSkipNonExporting_BrokenGraph_2() throws Exception { Couple couple = prepare( "app6", "edited6.graph", 410 ); Map<String,String> expected = new TreeMap<> (); expected.put( "c1.*", CompletionUtils.IMPORT_ALL_THE_VARIABLES ); expected.put( "c1.v1", CompletionUtils.DEFAULT_VALUE + "version1" ); expected.put( "c1.v2", CompletionUtils.DEFAULT_VALUE + "version2" ); expected.put( "c1.ip", CompletionUtils.SET_BY_ROBOCONF ); expected.put( "c1.port", CompletionUtils.DEFAULT_VALUE + "8100" ); expected.put( "c2.*", CompletionUtils.IMPORT_ALL_THE_VARIABLES ); expected.put( "c2.ip", CompletionUtils.SET_BY_ROBOCONF ); expected.put( "comp2.*", CompletionUtils.IMPORT_ALL_THE_VARIABLES ); expected.put( "comp2.toto", null ); expected.put( "f1.*", CompletionUtils.IMPORT_ALL_THE_VARIABLES ); expected.put( "f1.v1", CompletionUtils.DEFAULT_VALUE + "version1" ); expected.put( "f1.v2", CompletionUtils.DEFAULT_VALUE + "version2" ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( expected.size(), proposals.size()); int index = 0; for( Map.Entry<String,String> entry : expected.entrySet()) { Assert.assertEquals( entry.getKey(), proposals.get( index ).getProposalName()); Assert.assertEquals( entry.getKey(), proposals.get( index ).getProposalString()); Assert.assertEquals( entry.getValue(), proposals.get( index ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( index ).getReplacementOffset()); index ++; } }
@Test public void testOffsetForVariablesImportsWithPrefix_1() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\ncomp {\n\timports: c1"; Map<String,String> expected = new TreeMap<> (); expected.put( "c1.*", CompletionUtils.IMPORT_ALL_THE_VARIABLES ); expected.put( "c1.v1", CompletionUtils.DEFAULT_VALUE + "version1" ); expected.put( "c1.v2", CompletionUtils.DEFAULT_VALUE + "version2" ); expected.put( "c1.ip", CompletionUtils.SET_BY_ROBOCONF ); expected.put( "c1.port", CompletionUtils.DEFAULT_VALUE + "8100" ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( expected.size(), proposals.size()); int index = 0; for( Map.Entry<String,String> entry : expected.entrySet()) { Assert.assertEquals( entry.getKey(), proposals.get( index ).getProposalName()); Assert.assertEquals( entry.getKey(), proposals.get( index ).getProposalString()); Assert.assertEquals( entry.getValue(), proposals.get( index ).getProposalDescription()); Assert.assertEquals( 2, proposals.get( index ).getReplacementOffset()); index ++; } }
@Test public void testOffsetForVariablesImportsWithPrefix_2() throws Exception { Couple couple = prepare( "app2", "edited2.graph", 140 ); couple.text += "\ncomp {\n\timports: c2."; Map<String,String> expected = new TreeMap<> (); expected.put( "c2.*", CompletionUtils.IMPORT_ALL_THE_VARIABLES ); expected.put( "c2.ip", CompletionUtils.SET_BY_ROBOCONF ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( expected.size(), proposals.size()); int index = 0; for( Map.Entry<String,String> entry : expected.entrySet()) { Assert.assertEquals( entry.getKey(), proposals.get( index ).getProposalName()); Assert.assertEquals( entry.getKey(), proposals.get( index ).getProposalString()); Assert.assertEquals( entry.getValue(), proposals.get( index ).getProposalDescription()); Assert.assertEquals( 3, proposals.get( index ).getReplacementOffset()); index ++; } }