InstancesCompletionProposer implements ICompletionProposer { @Override public List<RoboconfCompletionProposal> findProposals( String text ) { List<RoboconfCompletionProposal> proposals = new ArrayList<> (); Ctx ctx = findContext( text ); boolean addImport = true; switch( ctx.kind ) { case IMPORT: for( String instanceImport : CompletionUtils.findInstancesFilesToImport( this.appDirectory, this.editedFile, text )) { if( startsWith( instanceImport, ctx.lastWord )) proposals.add( basicProposal( instanceImport, "", false )); } break; case ATTRIBUTE: addImport = false; Map<String,String> candidates = findExportedVariableNames( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); case NEUTRAL: if( addImport && startsWith( IMPORT_PREFIX, ctx.lastWord )) proposals.add( basicProposal( IMPORT_PREFIX, ctx.lastWord, true )); if( startsWith( INSTANCE_OF_PREFIX, ctx.lastWord )) { proposals.add( basicProposal( INSTANCE_OF_PREFIX, ctx.lastWord, true )); StringBuilder sb = new StringBuilder( INSTANCE_OF_PREFIX ); sb.append( "component" ); sb.append( " {\n\t" ); sb.append( ctx.parentIndentation ); sb.append( PROPERTY_INSTANCE_NAME ); sb.append( ": name;\n" ); sb.append( ctx.parentIndentation ); sb.append( "}" ); String proposalString = sb.toString(); SelectionRange sel1 = new SelectionRange( KEYWORD_INSTANCE_OF.length() + 1, COMPONENT_NAME.length()); SelectionRange sel2 = new SelectionRange( sel1.getOffset() + sel1.getLength() + PROPERTY_INSTANCE_NAME.length() + 6 + ctx.parentIndentation.length(), 4 ); RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, INSTANCE_OF_BLOCK, INSTANCE_OF_BLOCK + "\n\n" + proposalString.trim(), ctx.lastWord.length()); proposal.getSelection().add( sel1 ); proposal.getSelection().add( sel2 ); proposals.add( proposal ); } break; case COMPONENT_NAME: candidates = findComponentNames( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); break; default: break; } return proposals; } InstancesCompletionProposer( File appDirectory, File editedFile ); String getErrorMsg(); @Override List<RoboconfCompletionProposal> findProposals( String text );  }
@Test public void testOffsetAtZero() throws Exception { Couple couple = prepare( "app1", "initial.instances", 0 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); verifyNeutralOffset( proposals ); }
@Test public void testOffsetInComment_1() throws Exception { Couple couple = prepare( "app1", "initial.instances", 9 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetInComment_2() throws Exception { Couple couple = prepare( "app1", "initial.instances", 32 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetInInlineCommentInInstance() throws Exception { Couple couple = prepare( "app1", "initial.instances", 83 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetRightBeforeComment() throws Exception { Couple couple = prepare( "app1", "initial.instances", 1 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); verifyNeutralOffset( proposals ); }
@Test public void testOffsetRightAfterCommentSymbol() throws Exception { Couple couple = prepare( "app1", "initial.instances", 2 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetOutisdeInstances() throws Exception { Couple couple = prepare( "app1", "initial.instances", 43 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); verifyNeutralOffset( proposals ); couple = prepare( "app1", "initial.instances", 107 ); proposals = couple.proposer.findProposals( couple.text ); verifyNeutralOffset( proposals ); }
@Test public void testOffsetRightClosingCurlyBracket() throws Exception { Couple couple = prepare( "app1", "initial.instances", 2 ); couple.text = "instanceof Toto {\n}"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetInsideInstances() throws Exception { Couple couple = prepare( "app1", "initial.instances", 61 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); verifyBasicInstanceProperties( proposals ); couple = prepare( "app1", "initial.instances", 99 ); proposals = couple.proposer.findProposals( couple.text ); verifyBasicInstanceProperties( proposals ); couple = prepare( "app1", "initial.instances", 103 ); proposals = couple.proposer.findProposals( couple.text ); verifyBasicInstanceProperties( proposals ); }
@Test public void testOffsetInsideInstancesWithInstanceOfPrefix() throws Exception { Couple couple = prepare( "app1", "initial.instances", 61 ); couple.text += "inst"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 2, proposals.size()); Assert.assertEquals( KEYWORD_INSTANCE_OF, proposals.get( 0 ).getProposalName()); Assert.assertEquals( INSTANCE_OF_PREFIX, proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 4, proposals.get( 0 ).getReplacementOffset()); Assert.assertEquals( INSTANCE_OF_BLOCK, proposals.get( 1 ).getProposalName()); Assert.assertTrue( proposals.get( 1 ).getProposalString().startsWith( INSTANCE_OF_PREFIX )); Assert.assertTrue( proposals.get( 1 ).getProposalDescription().startsWith( INSTANCE_OF_BLOCK )); Assert.assertEquals( 4, proposals.get( 1 ).getReplacementOffset()); }
@Test public void testOffsetInsideInstancesWithBasicPropertyPrefix_1() throws Exception { Couple couple = prepare( "app1", "initial.instances", 61 ); couple.text += "nam"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( PROPERTY_INSTANCE_NAME + ": ", proposals.get( 0 ).getProposalName()); Assert.assertEquals( PROPERTY_INSTANCE_NAME + ": ", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 3, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetInsideInstancesWithBasicPropertyPrefix_2() throws Exception { Couple couple = prepare( "app1", "initial.instances", 61 ); couple.text += "name"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( PROPERTY_INSTANCE_NAME + ": ", proposals.get( 0 ).getProposalName()); Assert.assertEquals( PROPERTY_INSTANCE_NAME + ": ", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 4, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetInsideInstancesWithBasicPropertyPrefix_3() throws Exception { Couple couple = prepare( "app1", "initial.instances", 61 ); couple.text += "nAMe:"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( PROPERTY_INSTANCE_NAME + ": ", proposals.get( 0 ).getProposalName()); Assert.assertEquals( PROPERTY_INSTANCE_NAME + ": ", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 5, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetInsideInstancesWithBasicPropertyPrefix_4() throws Exception { Couple couple = prepare( "app1", "initial.instances", 61 ); couple.text += "name: "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetInsideInstancesWithBasicPropertyPrefix_5() throws Exception { Couple couple = prepare( "app1", "initial.instances", 61 ); couple.text += "name : "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetInsideInstancesWithInvalidPrefix() throws Exception { Couple couple = prepare( "app1", "initial.instances", 61 ); couple.text += "pop"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetOutisdeInstancesWithImportPrefix() throws Exception { Couple couple = prepare( "app1", "initial.instances", 43 ); couple.text += "im"; 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( 2, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetOutisdeInstancesWithFakeImportPrefix() throws Exception { Couple couple = prepare( "app1", "initial.instances", 43 ); couple.text += "im po"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetOutisdeInstancesWithInstanceOfPrefix() throws Exception { Couple couple = prepare( "app1", "initial.instances", 43 ); couple.text += "in"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 2, proposals.size()); Assert.assertEquals( KEYWORD_INSTANCE_OF, proposals.get( 0 ).getProposalName()); Assert.assertEquals( INSTANCE_OF_PREFIX, proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 2, proposals.get( 0 ).getReplacementOffset()); Assert.assertEquals( INSTANCE_OF_BLOCK, proposals.get( 1 ).getProposalName()); Assert.assertTrue( proposals.get( 1 ).getProposalString().startsWith( INSTANCE_OF_PREFIX )); Assert.assertTrue( proposals.get( 1 ).getProposalDescription().startsWith( INSTANCE_OF_BLOCK )); Assert.assertEquals( 2, proposals.get( 1 ).getReplacementOffset()); }
@Test public void testOffsetOutisdeInstancesWithFakeInstanceOfPrefix() throws Exception { Couple couple = prepare( "app1", "initial.instances", 43 ); couple.text += "instanceof"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetInsideInstancesWithComponentPropertiesAndWithoutInheritance() throws Exception { Couple couple = prepare( "app3", "initial.instances", 61 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 5, proposals.size()); Assert.assertEquals( "c2.ip: ", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "c2.ip: ", proposals.get( 0 ).getProposalString()); Assert.assertEquals( CompletionUtils.SET_BY_ROBOCONF, proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 0 ).getReplacementOffset()); Assert.assertEquals( PROPERTY_INSTANCE_CHANNELS + ": ", proposals.get( 1 ).getProposalName()); Assert.assertEquals( PROPERTY_INSTANCE_CHANNELS + ": ", proposals.get( 1 ).getProposalString()); Assert.assertNull( proposals.get( 1 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 1 ).getReplacementOffset()); Assert.assertEquals( PROPERTY_INSTANCE_NAME + ": ", proposals.get( 2 ).getProposalName()); Assert.assertEquals( PROPERTY_INSTANCE_NAME + ": ", proposals.get( 2 ).getProposalString()); Assert.assertNull( proposals.get( 2 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 2 ).getReplacementOffset()); Assert.assertEquals( KEYWORD_INSTANCE_OF, proposals.get( 3 ).getProposalName()); Assert.assertEquals( INSTANCE_OF_PREFIX, proposals.get( 3 ).getProposalString()); Assert.assertNull( proposals.get( 3 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 3 ).getReplacementOffset()); Assert.assertEquals( INSTANCE_OF_BLOCK, proposals.get( 4 ).getProposalName()); Assert.assertTrue( proposals.get( 4 ).getProposalString().startsWith( INSTANCE_OF_PREFIX )); Assert.assertTrue( proposals.get( 4 ).getProposalDescription().startsWith( INSTANCE_OF_BLOCK )); Assert.assertEquals( 0, proposals.get( 4 ).getReplacementOffset()); }
@Test public void testOffsetInsideInstancesWithComponentPropertiesAfterInstance() throws Exception { Couple couple = prepare( "app3", "initial.instances", 142 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 5, proposals.size()); Assert.assertEquals( "c2.ip: ", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "c2.ip: ", proposals.get( 0 ).getProposalString()); Assert.assertEquals( CompletionUtils.SET_BY_ROBOCONF, proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 0 ).getReplacementOffset()); Assert.assertEquals( PROPERTY_INSTANCE_CHANNELS + ": ", proposals.get( 1 ).getProposalName()); Assert.assertEquals( PROPERTY_INSTANCE_CHANNELS + ": ", proposals.get( 1 ).getProposalString()); Assert.assertNull( proposals.get( 1 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 1 ).getReplacementOffset()); Assert.assertEquals( PROPERTY_INSTANCE_NAME + ": ", proposals.get( 2 ).getProposalName()); Assert.assertEquals( PROPERTY_INSTANCE_NAME + ": ", proposals.get( 2 ).getProposalString()); Assert.assertNull( proposals.get( 2 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 2 ).getReplacementOffset()); Assert.assertEquals( KEYWORD_INSTANCE_OF, proposals.get( 3 ).getProposalName()); Assert.assertEquals( INSTANCE_OF_PREFIX, proposals.get( 3 ).getProposalString()); Assert.assertNull( proposals.get( 3 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 3 ).getReplacementOffset()); Assert.assertEquals( INSTANCE_OF_BLOCK, proposals.get( 4 ).getProposalName()); Assert.assertTrue( proposals.get( 4 ).getProposalString().startsWith( INSTANCE_OF_PREFIX )); Assert.assertTrue( proposals.get( 4 ).getProposalDescription().startsWith( INSTANCE_OF_BLOCK )); Assert.assertEquals( 0, proposals.get( 4 ).getReplacementOffset()); }
@Test public void testOffsetInsideInstancesWithComponentPropertiesAndPrefixAndWithoutInheritance() throws Exception { Couple couple = prepare( "app3", "initial.instances", 61 ); couple.text += "C"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 2, proposals.size()); Assert.assertEquals( "c2.ip: ", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "c2.ip: ", proposals.get( 0 ).getProposalString()); Assert.assertEquals( CompletionUtils.SET_BY_ROBOCONF, proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 1, proposals.get( 0 ).getReplacementOffset()); Assert.assertEquals( PROPERTY_INSTANCE_CHANNELS + ": ", proposals.get( 1 ).getProposalName()); Assert.assertEquals( PROPERTY_INSTANCE_CHANNELS + ": ", proposals.get( 1 ).getProposalString()); Assert.assertNull( proposals.get( 1 ).getProposalDescription()); Assert.assertEquals( 1, proposals.get( 1 ).getReplacementOffset()); }
@Test public void testOffsetInsideInstancesWithInvalidComponent() throws Exception { Couple couple = prepare( "app3", "initial.instances", 500 ); couple.text += "instance of InvalidComponent {\n\t"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); verifyBasicInstanceProperties( proposals ); }
@Test public void testOffsetInsideInstancesWithNoGraph() throws Exception { Couple couple = prepare( "app4", "initial.instances", 61 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); verifyBasicInstanceProperties( proposals ); }
@Test public void testOffsetInsideInstancesWithComponentPropertiesAndWithInheritance() throws Exception { Map<String,String> expected = new LinkedHashMap<> (); expected.put( "c1.ip: ", CompletionUtils.SET_BY_ROBOCONF ); expected.put( "c1.port: ", CompletionUtils.DEFAULT_VALUE + "8100" ); expected.put( "c1.v1: ", CompletionUtils.DEFAULT_VALUE + "version1" ); expected.put( "c1.v2: ", CompletionUtils.DEFAULT_VALUE + "version2" ); expected.put( PROPERTY_INSTANCE_CHANNELS + ": ", null ); expected.put( "f1.v1: ", CompletionUtils.DEFAULT_VALUE + "version1" ); expected.put( "f1.v2: ", CompletionUtils.DEFAULT_VALUE + "version2" ); expected.put( PROPERTY_INSTANCE_NAME + ": ", null ); Couple couple = prepare( "app3", "initial.instances", 135 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( expected.size() + 2, 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 ++; } Assert.assertEquals( KEYWORD_INSTANCE_OF, proposals.get( index ).getProposalName()); Assert.assertEquals( INSTANCE_OF_PREFIX, proposals.get( index ).getProposalString()); Assert.assertNull( proposals.get( index ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( index ).getReplacementOffset()); index ++; Assert.assertEquals( INSTANCE_OF_BLOCK, proposals.get( index ).getProposalName()); Assert.assertTrue( proposals.get( index ).getProposalString().startsWith( INSTANCE_OF_PREFIX )); Assert.assertTrue( proposals.get( index ).getProposalDescription().startsWith( INSTANCE_OF_BLOCK )); Assert.assertEquals( 0, proposals.get( index ).getReplacementOffset()); }
@Test public void testOffsetInsideInstancesWithComponentPropertiesAndPrefixAndWithInheritance() throws Exception { Map<String,String> expected = new LinkedHashMap<> (); expected.put( "f1.v1: ", CompletionUtils.DEFAULT_VALUE + "version1" ); expected.put( "f1.v2: ", CompletionUtils.DEFAULT_VALUE + "version2" ); Couple couple = prepare( "app3", "initial.instances", 135 ); couple.text += " F"; 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( 1, proposals.get( index ).getReplacementOffset()); index ++; } }
@Test public void testOffsetForComponentNameWithNoGraph() throws Exception { Couple couple = prepare( "app4", "initial.instances", 91 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForRootComponentNameWithGraph() throws Exception { Couple couple = prepare( "app3", "initial.instances", 91 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( "c2", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "c2", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetForRootComponentNameWithGraphAndPrefix() throws Exception { Couple couple = prepare( "app3", "initial.instances", 91 ); couple.text += " C"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( "c2", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "c2", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 1, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetForRootComponentNameWithGraphAndInvalidPrefix_1() throws Exception { Couple couple = prepare( "app3", "initial.instances", 91 ); couple.text += " C "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForRootComponentNameWithGraphAndInvalidPrefix_2() throws Exception { Couple couple = prepare( "app3", "initial.instances", 91 ); couple.text += "d"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForChildComponentNameWithGraph() throws Exception { Couple couple = prepare( "app3", "initial.instances", 125 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, 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()); }
@Test public void testOffsetForChildComponentNameWithGraphAndPrefix() throws Exception { Couple couple = prepare( "app3", "initial.instances", 125 ); couple.text += " C"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, 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( 1, proposals.get( 0 ).getReplacementOffset()); }
@Test public void testOffsetForChildComponentNameWithGraphAndInvalidPrefix_1() throws Exception { Couple couple = prepare( "app3", "initial.instances", 125 ); couple.text += " C "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForChildComponentNameWithGraphAndInvalidPrefix_2() throws Exception { Couple couple = prepare( "app3", "initial.instances", 125 ); couple.text += "d"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForComponentNameAndInvalidParent() throws Exception { Couple couple = prepare( "app3", "initial.instances", 700 ); couple.text += "instance of invalid {\n\tinstance of "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 0, proposals.size()); }
@Test public void testOffsetForComponentNameAndValidParent() throws Exception { Couple couple = prepare( "app3", "initial.instances", 700 ); couple.text += "instance of c2 {\n\tinstance of "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, 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()); }
@Test public void verifyIndentation_1() throws Exception { Couple couple = prepare( "app3", "initial.instances", 700 ); couple.text = ""; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 3, proposals.size()); Assert.assertEquals( INSTANCE_OF_BLOCK, proposals.get( 2 ).getProposalName()); Assert.assertEquals( indentation( 0 ), proposals.get( 2 ).getProposalString()); Assert.assertEquals( 0, proposals.get( 2 ).getReplacementOffset()); }
@Test public void verifyIndentation_2() throws Exception { Couple couple = prepare( "app3", "initial.instances", 700 ); couple.text = "instance of n1 {\n"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 4, proposals.size()); Assert.assertEquals( INSTANCE_OF_BLOCK, proposals.get( 3 ).getProposalName()); Assert.assertEquals( indentation( 1 ), proposals.get( 3 ).getProposalString()); Assert.assertEquals( 0, proposals.get( 3 ).getReplacementOffset()); }
@Test public void verifyIndentation_3() throws Exception { Couple couple = prepare( "app3", "initial.instances", 700 ); couple.text = "instance of n1 {\n\tinstance of n2 {\n"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 4, proposals.size()); Assert.assertEquals( INSTANCE_OF_BLOCK, proposals.get( 3 ).getProposalName()); Assert.assertEquals( indentation( 2 ), proposals.get( 3 ).getProposalString()); Assert.assertEquals( 0, proposals.get( 3 ).getReplacementOffset()); }
@Test public void verifyIndentation_4() throws Exception { Couple couple = prepare( "app3", "initial.instances", 700 ); couple.text = "instance of n1 {\n\tinstance of n2 {\n\t\tinstance of n3 {\n"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 4, proposals.size()); Assert.assertEquals( INSTANCE_OF_BLOCK, proposals.get( 3 ).getProposalName()); Assert.assertEquals( indentation( 3 ), proposals.get( 3 ).getProposalString()); Assert.assertEquals( 0, proposals.get( 3 ).getReplacementOffset()); }
@Test public void verifyIndentationWithBadIndentationForParent() throws Exception { Couple couple = prepare( "app3", "initial.instances", 700 ); couple.text = "instance of n1 {\ninstance of n2 {\n"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 4, proposals.size()); Assert.assertEquals( INSTANCE_OF_BLOCK, proposals.get( 3 ).getProposalName()); Assert.assertEquals( indentation( 1 ), proposals.get( 3 ).getProposalString()); Assert.assertEquals( 0, proposals.get( 3 ).getReplacementOffset()); }
@Test public void testOffsetForInstancesImportAllFiles() throws Exception { Couple couple = prepare( "app4", "initial.instances", 700 ); couple.text += "\nimport "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 3, proposals.size()); String[] expected = { "imports/imp1.instances", "imports/subimports/imp2.instances", "imports/subimports/imp3.instances" }; 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 testOffsetForInstancesImportNoSpaceAfterKeyword() throws Exception { Couple couple = prepare( "app4", "initial.instances", 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 testOffsetForInstancesImportWithPrefix() throws Exception { Couple couple = prepare( "app4", "initial.instances", 700 ); couple.text += "\nimport imports/s"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 2, proposals.size()); String[] expected = { "imports/subimports/imp2.instances", "imports/subimports/imp3.instances" }; 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 testOffsetForInstancesImportAvoidDuplicates() throws Exception { Couple couple = prepare( "app4", "initial.instances", 700 ); couple.text += "\nimport imports/subimports/imp2.instances\n\nimport "; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 2, proposals.size()); String[] expected = { "imports/imp1.instances", "imports/subimports/imp3.instances" }; 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 testOffsetForInstancesImportAvoidNastyDuplicates() throws Exception { Couple couple = prepare( "app4", "initial.instances", 700 ); couple.text += "\nimport imports/subimports/imp2.instances ; \n\nimport imp"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 2, proposals.size()); String[] expected = { "imports/imp1.instances", "imports/subimports/imp3.instances" }; 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()); } }