use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.
the class BibEntryWriterTest method roundTripWithPrecedingCommentTest.
@Test
public void roundTripWithPrecedingCommentTest() throws IOException {
// @formatter:off
String bibtexEntry = "% Some random comment that should stay here" + OS.NEWLINE + "@Article{test," + OS.NEWLINE + " Author = {Foo Bar}," + OS.NEWLINE + " Journal = {International Journal of Something}," + OS.NEWLINE + " Note = {some note}," + OS.NEWLINE + " Number = {1}" + OS.NEWLINE + "}";
// @formatter:on
// read in bibtex string
ParserResult result = new BibtexParser(importFormatPreferences).parse(new StringReader(bibtexEntry));
Collection<BibEntry> entries = result.getDatabase().getEntries();
BibEntry entry = entries.iterator().next();
//write out bibtex string
StringWriter stringWriter = new StringWriter();
writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX);
String actual = stringWriter.toString();
assertEquals(bibtexEntry, actual);
}
use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.
the class BibEntryWriterTest method roundTripWithAppendedNewlines.
@Test
public void roundTripWithAppendedNewlines() throws IOException {
// @formatter:off
String bibtexEntry = "@Article{test," + OS.NEWLINE + " Author = {Foo Bar}," + OS.NEWLINE + " Journal = {International Journal of Something}," + OS.NEWLINE + " Note = {some note}," + OS.NEWLINE + " Number = {1}" + OS.NEWLINE + "}\n\n";
// @formatter:on
// read in bibtex string
ParserResult result = new BibtexParser(importFormatPreferences).parse(new StringReader(bibtexEntry));
Collection<BibEntry> entries = result.getDatabase().getEntries();
BibEntry entry = entries.iterator().next();
//write out bibtex string
StringWriter stringWriter = new StringWriter();
writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX);
String actual = stringWriter.toString();
// Only one appending newline is written by the writer, the rest by FileActions. So, these should be removed here.
assertEquals(bibtexEntry.substring(0, bibtexEntry.length() - 1), actual);
}
use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.
the class BibEntryWriterTest method monthFieldSpecialSyntax.
@Test
public void monthFieldSpecialSyntax() throws IOException {
// @formatter:off
String bibtexEntry = "@Article{test," + OS.NEWLINE + " Author = {Foo Bar}," + OS.NEWLINE + " Month = mar," + OS.NEWLINE + " Number = {1}" + OS.NEWLINE + "}";
// @formatter:on
// read in bibtex string
ParserResult result = new BibtexParser(importFormatPreferences).parse(new StringReader(bibtexEntry));
Collection<BibEntry> entries = result.getDatabase().getEntries();
BibEntry entry = entries.iterator().next();
// modify month field
Set<String> fields = entry.getFieldNames();
assertTrue(fields.contains("month"));
assertEquals("#mar#", entry.getField("month").get());
//write out bibtex string
StringWriter stringWriter = new StringWriter();
writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX);
String actual = stringWriter.toString();
assertEquals(bibtexEntry, actual);
}
use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.
the class AuxParserTest method testNormal.
@Test
public void testNormal() throws URISyntaxException, IOException {
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
File auxFile = Paths.get(AuxParserTest.class.getResource("paper.aux").toURI()).toFile();
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(importFormatPreferences).parse(originalReader);
AuxParser auxParser = new AuxParser(auxFile.getAbsolutePath(), result.getDatabase());
AuxParserResult auxResult = auxParser.parse();
assertTrue(auxResult.getGeneratedBibDatabase().hasEntries());
assertEquals(0, auxResult.getUnresolvedKeysCount());
BibDatabase newDB = auxResult.getGeneratedBibDatabase();
assertEquals(2, newDB.getEntries().size());
assertEquals(2, auxResult.getResolvedKeysCount());
assertEquals(2, auxResult.getFoundKeysInAux());
assertEquals(auxResult.getFoundKeysInAux() + auxResult.getCrossRefEntriesCount(), auxResult.getResolvedKeysCount() + auxResult.getUnresolvedKeysCount());
assertEquals(0, auxResult.getCrossRefEntriesCount());
}
}
use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.
the class AuxParserTest method duplicateBibDatabaseConfiguration.
@Test
public void duplicateBibDatabaseConfiguration() throws URISyntaxException, IOException {
InputStream originalStream = AuxParserTest.class.getResourceAsStream("config.bib");
File auxFile = Paths.get(AuxParserTest.class.getResource("paper.aux").toURI()).toFile();
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(importFormatPreferences).parse(originalReader);
AuxParser auxParser = new AuxParser(auxFile.getAbsolutePath(), result.getDatabase());
AuxParserResult auxResult = auxParser.parse();
BibDatabase db = auxResult.getGeneratedBibDatabase();
assertEquals(Optional.of("\"Maintained by \" # maintainer"), db.getPreamble());
assertEquals(1, db.getStringCount());
}
}
Aggregations