|
38 | 38 | import java.nio.file.spi.FileSystemProvider; |
39 | 39 | import java.util.List; |
40 | 40 | import java.util.Set; |
| 41 | +import java.util.stream.Collectors; |
| 42 | +import java.util.stream.Stream; |
41 | 43 | import org.junit.jupiter.api.Test; |
42 | 44 | import org.junit.jupiter.api.io.TempDir; |
43 | 45 | import org.junit.jupiter.params.ParameterizedTest; |
@@ -157,6 +159,95 @@ void testStandardLibrarySearchPathShouldExcludeToolsUnits( |
157 | 159 | assertThat(symbolTable.getUnitByPath(excludedPath.toString())).isNull(); |
158 | 160 | } |
159 | 161 |
|
| 162 | + @Test |
| 163 | + void testSonarSourcesArePrioritizedOverReferencedFiles( |
| 164 | + @TempDir Path standardLibraryPath, |
| 165 | + @TempDir Path referencedFilesPath, |
| 166 | + @TempDir Path sourceFilesPath) |
| 167 | + throws IOException { |
| 168 | + createStandardLibrary(standardLibraryPath); |
| 169 | + createStandardLibrary(referencedFilesPath); |
| 170 | + createStandardLibrary(sourceFilesPath); |
| 171 | + |
| 172 | + List<Path> referencedFiles; |
| 173 | + try (Stream<Path> referencedFilesStream = Files.list(referencedFilesPath)) { |
| 174 | + referencedFiles = referencedFilesStream.collect(Collectors.toUnmodifiableList()); |
| 175 | + } |
| 176 | + |
| 177 | + List<Path> sourceFiles; |
| 178 | + try (Stream<Path> sourceFilesStream = Files.list(sourceFilesPath)) { |
| 179 | + sourceFiles = sourceFilesStream.collect(Collectors.toUnmodifiableList()); |
| 180 | + } |
| 181 | + |
| 182 | + SymbolTable symbolTable = |
| 183 | + SymbolTable.builder() |
| 184 | + .preprocessorFactory(new DelphiPreprocessorFactory(Platform.WINDOWS)) |
| 185 | + .typeFactory(TypeFactoryUtils.defaultFactory()) |
| 186 | + .standardLibraryPath(standardLibraryPath) |
| 187 | + .referencedFiles(referencedFiles) |
| 188 | + .sourceFiles(sourceFiles) |
| 189 | + .build(); |
| 190 | + |
| 191 | + assertThat(symbolTable.getUnitByPath(standardLibraryPath.resolve("SysInit.pas").toString())) |
| 192 | + .isNull(); |
| 193 | + assertThat(symbolTable.getUnitByPath(referencedFilesPath.resolve("SysInit.pas").toString())) |
| 194 | + .isNull(); |
| 195 | + assertThat(symbolTable.getUnitByPath(sourceFilesPath.resolve("SysInit.pas").toString())) |
| 196 | + .isNotNull(); |
| 197 | + } |
| 198 | + |
| 199 | + @Test |
| 200 | + void testReferencedFilesArePrioritizedOverSearchPath( |
| 201 | + @TempDir Path standardLibraryPath, |
| 202 | + @TempDir Path searchPathRoot, |
| 203 | + @TempDir Path referencedFilesPath) |
| 204 | + throws IOException { |
| 205 | + createStandardLibrary(standardLibraryPath); |
| 206 | + createStandardLibrary(searchPathRoot); |
| 207 | + createStandardLibrary(referencedFilesPath); |
| 208 | + |
| 209 | + List<Path> referencedFiles; |
| 210 | + try (Stream<Path> referencedFilesStream = Files.list(referencedFilesPath)) { |
| 211 | + referencedFiles = referencedFilesStream.collect(Collectors.toUnmodifiableList()); |
| 212 | + } |
| 213 | + |
| 214 | + SymbolTable symbolTable = |
| 215 | + SymbolTable.builder() |
| 216 | + .preprocessorFactory(new DelphiPreprocessorFactory(Platform.WINDOWS)) |
| 217 | + .typeFactory(TypeFactoryUtils.defaultFactory()) |
| 218 | + .standardLibraryPath(standardLibraryPath) |
| 219 | + .searchPath(SearchPath.create(List.of(searchPathRoot))) |
| 220 | + .referencedFiles(referencedFiles) |
| 221 | + .build(); |
| 222 | + |
| 223 | + assertThat(symbolTable.getUnitByPath(standardLibraryPath.resolve("SysInit.pas").toString())) |
| 224 | + .isNull(); |
| 225 | + assertThat(symbolTable.getUnitByPath(searchPathRoot.resolve("SysInit.pas").toString())) |
| 226 | + .isNull(); |
| 227 | + assertThat(symbolTable.getUnitByPath(referencedFilesPath.resolve("SysInit.pas").toString())) |
| 228 | + .isNotNull(); |
| 229 | + } |
| 230 | + |
| 231 | + @Test |
| 232 | + void testSearchPathIsPrioritizedOverStandardLibrary( |
| 233 | + @TempDir Path standardLibraryPath, @TempDir Path searchPathRoot) throws IOException { |
| 234 | + createStandardLibrary(standardLibraryPath); |
| 235 | + createStandardLibrary(searchPathRoot); |
| 236 | + |
| 237 | + SymbolTable symbolTable = |
| 238 | + SymbolTable.builder() |
| 239 | + .preprocessorFactory(new DelphiPreprocessorFactory(Platform.WINDOWS)) |
| 240 | + .typeFactory(TypeFactoryUtils.defaultFactory()) |
| 241 | + .standardLibraryPath(standardLibraryPath) |
| 242 | + .searchPath(SearchPath.create(List.of(searchPathRoot))) |
| 243 | + .build(); |
| 244 | + |
| 245 | + assertThat(symbolTable.getUnitByPath(standardLibraryPath.resolve("SysInit.pas").toString())) |
| 246 | + .isNull(); |
| 247 | + assertThat(symbolTable.getUnitByPath(searchPathRoot.resolve("SysInit.pas").toString())) |
| 248 | + .isNotNull(); |
| 249 | + } |
| 250 | + |
160 | 251 | @ParameterizedTest |
161 | 252 | @ValueSource(strings = {"#$@", "unit ErrorUnit;"}) |
162 | 253 | void testRecognitionErrorInImportShouldNotThrow( |
|
0 commit comments