Skip to content

Commit

Permalink
Merge pull request #7 from benjagooder/GOML_Doug_refactorAuxParser
Browse files Browse the repository at this point in the history
Goml doug refactor aux parser
  • Loading branch information
benjagooder authored Feb 11, 2019
2 parents 8c4da44 + a888d55 commit 479ffcd
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion src/test/java/org/jabref/logic/auxparser/AuxParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void tearDown() {
}

@Test
void testNormal() throws URISyntaxException, IOException {
void testNormalBibDatabase() throws URISyntaxException, IOException {
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
Path auxFile = Paths.get(AuxParserTest.class.getResource("paper.aux").toURI());
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
Expand All @@ -51,13 +51,91 @@ void testNormal() throws URISyntaxException, IOException {
AuxParserResult auxResult = auxParser.parse(auxFile);

assertTrue(auxResult.getGeneratedBibDatabase().hasEntries());
}
}

@Test
void testNormalUnresolvedKeysCount() throws URISyntaxException, IOException {
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
Path auxFile = Paths.get(AuxParserTest.class.getResource("paper.aux").toURI());
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader);

AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
AuxParserResult auxResult = auxParser.parse(auxFile);

assertEquals(0, auxResult.getUnresolvedKeysCount());
}
}

@Test
void testNormalEntries() throws URISyntaxException, IOException {
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
Path auxFile = Paths.get(AuxParserTest.class.getResource("paper.aux").toURI());
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader);

AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
AuxParserResult auxResult = auxParser.parse(auxFile);
BibDatabase newDB = auxResult.getGeneratedBibDatabase();

assertEquals(2, newDB.getEntries().size());
}
}

@Test
void testNormalResolvedKeysCount() throws URISyntaxException, IOException {
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
Path auxFile = Paths.get(AuxParserTest.class.getResource("paper.aux").toURI());
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader);

AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
AuxParserResult auxResult = auxParser.parse(auxFile);

assertEquals(2, auxResult.getResolvedKeysCount());
}
}

@Test
void testNormalFoundKeysInAux() throws URISyntaxException, IOException {
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
Path auxFile = Paths.get(AuxParserTest.class.getResource("paper.aux").toURI());
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader);

AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
AuxParserResult auxResult = auxParser.parse(auxFile);

assertEquals(2, auxResult.getFoundKeysInAux());
}
}

@Test
void testNormalMultipleKeyCounts() throws URISyntaxException, IOException {
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
Path auxFile = Paths.get(AuxParserTest.class.getResource("paper.aux").toURI());
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader);

AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
AuxParserResult auxResult = auxParser.parse(auxFile);

assertEquals(auxResult.getFoundKeysInAux() + auxResult.getCrossRefEntriesCount(),
auxResult.getResolvedKeysCount() + auxResult.getUnresolvedKeysCount());
}
}

@Test
void testNormalCrossRefEntriesCount() throws URISyntaxException, IOException {
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
Path auxFile = Paths.get(AuxParserTest.class.getResource("paper.aux").toURI());
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader);

AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
AuxParserResult auxResult = auxParser.parse(auxFile);

assertEquals(0, auxResult.getCrossRefEntriesCount());
}
}
Expand Down

0 comments on commit 479ffcd

Please sign in to comment.