Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Mar 3, 2016
1 parent da3c1c3 commit 69fe30e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/main/java/net/sf/jabref/wizard/auximport/AuxFileParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public String getInformation(boolean includeMissingEntries) {
*/
private void parseAuxFile(String filename) {
// nested aux files
List<String> fileList = Arrays.asList(filename);
List<String> fileList = new ArrayList<>(1);
fileList.add(filename);

int fileIndex = 0;

Expand All @@ -144,8 +145,13 @@ private void parseAuxFile(String filename) {
Matcher inputMatch = INPUT_PATTERN.matcher(line);

while (inputMatch.find()) {
String inputString = citeMatch.group(2);
String inputFile = new File(filename).toPath().resolve(inputString).toString();
String inputString = inputMatch.group(1);

String inputFile = inputString;
Path rootPath = new File(filename).toPath().getParent();
if(rootPath != null) {
inputFile = rootPath.resolve(inputString).toString();
}

if (!fileList.contains(inputFile)) {
fileList.add(inputFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,42 @@ public void testNotAllFound() {
}
}

// TODO strings and preamble test
// TODO return type of generate during error should be false
// TODO resolve nested aux files
@Test
public void duplicateBibDatabaseConfiguration() {
InputStream originalStream = AuxFileParserTest.class.getResourceAsStream("config.bib");
File auxFile = new File(AuxFileParserTest.class.getResource("paper.aux").getFile());
try (InputStreamReader originalReader = new InputStreamReader(originalStream)) {
ParserResult result = BibtexParser.parse(originalReader);

AuxFileParser auxFileParser = new AuxFileParser(auxFile.getAbsolutePath(), result.getDatabase());
BibDatabase db = auxFileParser.getGeneratedBibDatabase();

assertEquals("\"Maintained by \" # maintainer", db.getPreamble());
assertEquals(1, db.getStringCount());
} catch (IOException ex) {
fail("Cannot open file");
}
}

@Test
public void testNestedAux() {
InputStream originalStream = AuxFileParserTest.class.getResourceAsStream("origin.bib");
File auxFile = new File(AuxFileParserTest.class.getResource("nested.aux").getFile());
try (InputStreamReader originalReader = new InputStreamReader(originalStream)) {
ParserResult result = BibtexParser.parse(originalReader);

AuxFileParser auxFileParser = new AuxFileParser(auxFile.getAbsolutePath(), result.getDatabase());
assertFalse(auxFileParser.getGeneratedBibDatabase().isEmpty());
assertEquals(0, auxFileParser.getUnresolvedKeysCount());
BibDatabase newDB = auxFileParser.getGeneratedBibDatabase();
assertEquals(2, newDB.getEntries().size());
assertEquals(2, auxFileParser.getResolvedKeysCount());
assertEquals(2, auxFileParser.getFoundKeysInAux());
assertEquals(auxFileParser.getFoundKeysInAux(),
auxFileParser.getResolvedKeysCount() + auxFileParser.getUnresolvedKeysCount());
assertEquals(0, auxFileParser.getCrossRefEntriesCount());
} catch (IOException ex) {
fail("Cannot open file");
}
}
}
25 changes: 25 additions & 0 deletions src/test/resources/net/sf/jabref/wizard/auximport/config.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@String {maintainer = "Stefan Kolb"}
@preamble {"Maintained by " # maintainer}

@Book{Newton1999,
title = {The Principia: mathematical principles of natural philosophy},
publisher = {Univ of California Press},
year = {1999},
author = {Newton, Isaac}
}

@Book{Darwin1888,
title = {The descent of man, and selection in relation to sex},
publisher = {J. Murray},
year = {1888},
author = {Darwin, Charles}
}

@Book{Einstein1920,
title = {Relativity: The special and general theory},
publisher = {Penguin},
year = {1920},
author = {Einstein, Albert}
}

@Comment{jabref-meta: DATABASE_TYPE:BibTeX;}
5 changes: 5 additions & 0 deletions src/test/resources/net/sf/jabref/wizard/auximport/nested.aux
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
\relax
\bibstyle{plain}
\bibdata{origin}
\@input{paper.aux}
\@writefile{toc}{\contentsline {section}{\numberline {1}}{1}}

0 comments on commit 69fe30e

Please sign in to comment.