Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Goml doug refactor aux parser #7

Merged
merged 2 commits into from
Feb 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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