use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.
the class BibtexParserTest method parseSavesNewlinesBeforeEntryInParsedSerialization.
@Test
public void parseSavesNewlinesBeforeEntryInParsedSerialization() throws IOException {
String testEntry = "@article{test,author={Ed von Test}}";
ParserResult result = parser.parse(new StringReader(OS.NEWLINE + OS.NEWLINE + OS.NEWLINE + testEntry));
Collection<BibEntry> c = result.getDatabase().getEntries();
assertEquals(1, c.size());
BibEntry e = c.iterator().next();
assertEquals(OS.NEWLINE + OS.NEWLINE + OS.NEWLINE + testEntry, e.getParsedSerialization());
}
use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.
the class BibtexParserTest method parseRecognizesMultipleEntries.
@Test
public void parseRecognizesMultipleEntries() throws IOException {
ParserResult result = BibtexParser.parse(new StringReader("@article{canh05," + " author = {Crowston, K. and Annabi, H.},\n" + " title = {Title A}}\n" + "@inProceedings{foo," + " author={Norton Bar}}"), importFormatPreferences);
List<BibEntry> parsed = result.getDatabase().getEntries();
List<BibEntry> expected = new ArrayList<>();
BibEntry firstEntry = new BibEntry();
firstEntry.setType("article");
firstEntry.setCiteKey("canh05");
firstEntry.setField("author", "Crowston, K. and Annabi, H.");
firstEntry.setField("title", "Title A");
expected.add(firstEntry);
BibEntry secondEntry = new BibEntry();
secondEntry.setType("inproceedings");
secondEntry.setCiteKey("foo");
secondEntry.setField("author", "Norton Bar");
expected.add(secondEntry);
assertEquals(expected, parsed);
}
use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.
the class BibtexParserTest method parseSavesOneNewlineAfterStringInParsedSerialization.
@Test
public void parseSavesOneNewlineAfterStringInParsedSerialization() throws IOException {
String string = "@string{bourdieu = {Bourdieu, Pierre}}" + OS.NEWLINE;
ParserResult result = parser.parse(new StringReader(string + OS.NEWLINE + OS.NEWLINE));
assertEquals(1, result.getDatabase().getStringCount());
BibtexString s = result.getDatabase().getStringValues().iterator().next();
assertEquals(string, s.getParsedSerialization());
}
use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.
the class BibtexParserTest method parsePrecedingComment.
@Test
public void parsePrecedingComment() 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 = parser.parse(new StringReader(bibtexEntry));
Collection<BibEntry> entries = result.getDatabase().getEntries();
assertEquals(1, entries.size());
BibEntry entry = entries.iterator().next();
assertEquals(Optional.of("test"), entry.getCiteKeyOptional());
assertEquals(5, entry.getFieldNames().size());
Set<String> fields = entry.getFieldNames();
assertTrue(fields.contains("author"));
assertEquals(Optional.of("Foo Bar"), entry.getField("author"));
assertEquals(bibtexEntry, entry.getParsedSerialization());
}
use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.
the class BibtexParserTest method parseCombinesMultipleAuthorFields.
@Test
public void parseCombinesMultipleAuthorFields() throws IOException {
ParserResult result = parser.parse(new StringReader("@article{test,author={Ed von Test},author={Second Author},author={Third Author}}"));
Collection<BibEntry> c = result.getDatabase().getEntries();
assertEquals(1, c.size());
BibEntry e = c.iterator().next();
assertEquals("article", e.getType());
assertEquals(Optional.of("test"), e.getCiteKeyOptional());
assertEquals(2, e.getFieldNames().size());
assertEquals(Optional.of("Ed von Test and Second Author and Third Author"), e.getField("author"));
}
Aggregations