use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.
the class BibtexDatabaseWriterTest method roundtripWithUnknownMetaData.
@Test
public void roundtripWithUnknownMetaData() throws Exception {
Path testBibtexFile = Paths.get("src/test/resources/testbib/unknownMetaData.bib");
Charset encoding = StandardCharsets.UTF_8;
ParserResult result = new BibtexParser(importFormatPreferences).parse(Importer.getReader(testBibtexFile, encoding));
SavePreferences preferences = new SavePreferences().withEncoding(encoding).withSaveInOriginalOrder(true);
BibDatabaseContext context = new BibDatabaseContext(result.getDatabase(), result.getMetaData(), new Defaults(BibDatabaseMode.BIBTEX));
StringSaveSession session = databaseWriter.savePartOfDatabase(context, result.getDatabase().getEntries(), preferences);
try (Scanner scanner = new Scanner(testBibtexFile, encoding.name())) {
assertEquals(scanner.useDelimiter("\\A").next(), session.getStringValue());
}
}
use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.
the class BibDatabaseTestsWithFiles method resolveStrings.
@Test
public void resolveStrings() throws IOException {
try (FileInputStream stream = new FileInputStream("src/test/resources/org/jabref/util/twente.bib");
InputStreamReader fr = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(importFormatPreferences).parse(fr);
BibDatabase db = result.getDatabase();
assertEquals("Arvind", db.resolveForStrings("#Arvind#"));
assertEquals("Patterson, David", db.resolveForStrings("#Patterson#"));
assertEquals("Arvind and Patterson, David", db.resolveForStrings("#Arvind# and #Patterson#"));
// Strings that are not found return just the given string.
assertEquals("#unknown#", db.resolveForStrings("#unknown#"));
}
}
use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.
the class DatabaseFileLookupTest method setUp.
@Before
public void setUp() throws Exception {
try (FileInputStream stream = new FileInputStream(ImportDataTest.UNLINKED_FILES_TEST_BIB);
InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS)).parse(reader);
database = result.getDatabase();
entries = database.getEntries();
entry1 = database.getEntryByKey("entry1").get();
entry2 = database.getEntryByKey("entry2").get();
}
}
use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.
the class LayoutTest method bibtexString2BibtexEntry.
public static BibEntry bibtexString2BibtexEntry(String s) throws IOException {
ParserResult result = new BibtexParser(importFormatPreferences).parse(new StringReader(s));
Collection<BibEntry> c = result.getDatabase().getEntries();
Assert.assertEquals(1, c.size());
return c.iterator().next();
}
use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.
the class OOBibStyleTest method testGetCitationMarker.
@Test
public void testGetCitationMarker() throws IOException {
Path testBibtexFile = Paths.get("src/test/resources/testbib/complex.bib");
ParserResult result = new BibtexParser(importFormatPreferences).parse(Importer.getReader(testBibtexFile, StandardCharsets.UTF_8));
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, layoutFormatterPreferences);
Map<BibEntry, BibDatabase> entryDBMap = new HashMap<>();
BibDatabase db = result.getDatabase();
for (BibEntry entry : db.getEntries()) {
entryDBMap.put(entry, db);
}
BibEntry entry = db.getEntryByKey("1137631").get();
assertEquals("[Boström et al., 2006]", style.getCitationMarker(Arrays.asList(entry), entryDBMap, true, null, null));
assertEquals("Boström et al. [2006]", style.getCitationMarker(Arrays.asList(entry), entryDBMap, false, null, new int[] { 3 }));
assertEquals("[Boström, Wäyrynen, Bodén, Beznosov & Kruchten, 2006]", style.getCitationMarker(Arrays.asList(entry), entryDBMap, true, null, new int[] { 5 }));
}
Aggregations