AsciidocReferenceProposalCalculator { public Set<AsciidocReferenceProposalData> calculate(File editorFile, String fullSource, int indexForCtrlSpace) { String referenceText = calculator.resolveReferenceTextOrNull(fullSource, indexForCtrlSpace); if (referenceText==null) { return Collections.emptySet(); } Path path = Paths.get(referenceText.substring(getPrefix().length())); File parent = baseParentDirResolver.getBaseParentDir(editorFile); if (parent==null) { return Collections.emptySet(); } Path parentPath = path.getParent(); if (parentPath!=null && !parentPath.toString().isEmpty()) { File newParent = parent.toPath().resolve(parentPath).toFile(); if (!newParent.exists()) { return Collections.emptySet(); } parent = newParent; path = parentPath.relativize(path); } Path separatedParentPath = parent.toPath(); String search = null; if (path.toString().length() > 0) { File newParent = separatedParentPath.resolve(path).toFile(); if (newParent.exists()) { parent = newParent; }else { search = path.toString(); } } final String toSearch = search; File[] files = fetchFiles(editorFile, parent, toSearch); if (files==null) { return Collections.emptySet(); } return buildProposals(editorFile, files); } AsciidocReferenceProposalCalculator(String prefix, BaseParentDirResolver baseParentDirResolver, CodeAssistFileFilter fileFilter); Set<AsciidocReferenceProposalData> calculate(File editorFile, String fullSource, int indexForCtrlSpace);  }
@Test public void editorFile1_include_subfolder1_results_in_1_file() throws Exception { String text = "include::subfolder1/"; int index = text.length(); Set<AsciidocReferenceProposalData> result = toTest.calculate(editorFile1, text, index); assertNotNull(result); assertEquals(1, result.size()); Iterator<AsciidocReferenceProposalData> it = result.iterator(); assertEquals("include::subfolder1/otherfile4.adoc[]",it.next().getProposedCode()); }
@Test public void otherfile4_dot_dot_slash_subfolder2_results_in_2_files() throws Exception { File otherFile14 = TestResourcesLoader.assertTestFile("codeassist/include/test1/subfolder1/otherfile4.adoc"); String text = "include::../subfolder2/"; int index = text.length(); Set<AsciidocReferenceProposalData> result = toTest.calculate(otherFile14, text, index); assertNotNull(result); assertEquals(5, result.size()); Iterator<AsciidocReferenceProposalData> it = result.iterator(); assertEquals("include::../subfolder2/asciidoctor-editor with spaces.png[]",it.next().getProposedCode()); assertEquals("include::../subfolder2/asciidoctor-editor.png[]",it.next().getProposedCode()); assertEquals("include::../subfolder2/ditaa-file1.ditaa[]",it.next().getProposedCode()); assertEquals("include::../subfolder2/puml-file1.puml[]",it.next().getProposedCode()); assertEquals("include::../subfolder2/subfolder3/",it.next().getProposedCode()); }
@Test public void editorFile1_include_sub_results_in_2_folders() throws Exception { String text = "include::sub"; int index = text.length()-1; Set<AsciidocReferenceProposalData> result = toTest.calculate(editorFile1, text, index); assertNotNull(result); assertEquals(2, result.size()); Iterator<AsciidocReferenceProposalData> it = result.iterator(); assertEquals("include::subfolder1/",it.next().getProposedCode()); assertEquals("include::subfolder2/",it.next().getProposedCode()); }
@Test public void editorFile1_include_subfolder2_slash_sub_results_in_1_folder() throws Exception { String text = "include::subfolder2/sub"; int index = text.length()-1; Set<AsciidocReferenceProposalData> result = toTest.calculate(editorFile1, text, index); assertNotNull(result); assertEquals(1, result.size()); Iterator<AsciidocReferenceProposalData> it = result.iterator(); assertEquals("include::subfolder2/subfolder3/",it.next().getProposedCode()); }
@Test public void editorFile1_only_include_results_in_2_files_one_folder_as_label() throws Exception { String text = "include::"; int index = text.length(); Set<AsciidocReferenceProposalData> result = toTest.calculate(editorFile1, text, index); assertNotNull(result); assertEquals(5, result.size()); Iterator<AsciidocReferenceProposalData> it = result.iterator(); assertEquals("include::otherfile1.adoc[]",it.next().getProposedCode()); assertEquals("include::otherfile2.txt[]",it.next().getProposedCode()); assertEquals("include::otherfile3.adoc[]",it.next().getProposedCode()); assertEquals("include::subfolder1/",it.next().getProposedCode()); assertEquals("include::subfolder2/",it.next().getProposedCode()); }
@Test public void editorFile1_subfolder1_already_includes_returns_result_for_subfolder() throws Exception { String text = "include::subfolder1"; int index = text.length(); Set<AsciidocReferenceProposalData> result = toTest.calculate(editorFile1, text, index); assertNotNull(result); assertEquals(1, result.size()); Iterator<AsciidocReferenceProposalData> it = result.iterator(); assertEquals("include::subfolder1/otherfile4.adoc[]",it.next().getProposedCode()); }