Search in sources :

Example 66 with BibDatabase

use of org.jabref.model.database.BibDatabase in project jabref by JabRef.

the class AuxParserTest method testNotAllFound.

@Test
public void testNotAllFound() throws URISyntaxException, IOException {
    InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
    File auxFile = Paths.get(AuxParserTest.class.getResource("badpaper.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(1, auxResult.getUnresolvedKeysCount());
        BibDatabase newDB = auxResult.getGeneratedBibDatabase();
        assertEquals(2, newDB.getEntries().size());
        assertEquals(2, auxResult.getResolvedKeysCount());
        assertEquals(3, auxResult.getFoundKeysInAux());
        assertEquals(auxResult.getFoundKeysInAux() + auxResult.getCrossRefEntriesCount(), auxResult.getResolvedKeysCount() + auxResult.getUnresolvedKeysCount());
        assertEquals(0, auxResult.getCrossRefEntriesCount());
    }
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) File(java.io.File) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Example 67 with BibDatabase

use of org.jabref.model.database.BibDatabase in project jabref by JabRef.

the class MakeLabelWithDatabaseTest method setUp.

@Before
public void setUp() {
    database = new BibDatabase();
    entry = new BibEntry();
    entry.setField("author", "John Doe");
    entry.setField("year", "2016");
    entry.setField("title", "An awesome paper on JabRef");
    database.insertEntry(entry);
    pattern = GlobalBibtexKeyPattern.fromPattern("[auth][year]");
    bibtexKeyPattern = new DatabaseBibtexKeyPattern(pattern);
    preferences = new BibtexKeyPatternPreferences("", "", false, true, true, pattern, ',');
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) DatabaseBibtexKeyPattern(org.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern) BibDatabase(org.jabref.model.database.BibDatabase) Before(org.junit.Before)

Example 68 with BibDatabase

use of org.jabref.model.database.BibDatabase in project jabref by JabRef.

the class BibtexKeyPatternUtilTest method keywordNKeywordsSeparatedBySpace.

@Test
public void keywordNKeywordsSeparatedBySpace() {
    BibEntry entry = new BibEntry();
    entry.setField("keywords", "w1, w2a w2b, w3");
    String result = BibtexKeyPatternUtil.makeLabel(entry, "keyword1", ',', new BibDatabase());
    assertEquals("w1", result);
    // check keywords with space
    result = BibtexKeyPatternUtil.makeLabel(entry, "keyword2", ',', new BibDatabase());
    assertEquals("w2a w2b", result);
    // check out of range
    result = BibtexKeyPatternUtil.makeLabel(entry, "keyword4", ',', new BibDatabase());
    assertEquals("", result);
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Example 69 with BibDatabase

use of org.jabref.model.database.BibDatabase in project jabref by JabRef.

the class BibtexKeyPatternUtilTest method testAndInAuthorName.

@Test
public void testAndInAuthorName() throws ParseException {
    Optional<BibEntry> entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Simon Holland}}", importFormatPreferences);
    assertEquals("Holland", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth", ',', new BibDatabase()), true));
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Example 70 with BibDatabase

use of org.jabref.model.database.BibDatabase in project jabref by JabRef.

the class BibtexKeyPatternUtilTest method testMakeLabelAndCheckLegalKeys.

/**
     * Test for https://sourceforge.net/forum/message.php?msg_id=4498555 Test the Labelmaker and all kind of accents Á á
     * Ć ć É é Í í Ĺ ĺ Ń ń Ó ó Ŕ ŕ Ś ś Ú ú Ý ý Ź ź
     */
@Test
public void testMakeLabelAndCheckLegalKeys() throws ParseException {
    Optional<BibEntry> entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Köning}, year={2000}}", importFormatPreferences);
    assertEquals("Koen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", ',', new BibDatabase()), true));
    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Áöning}, year={2000}}", importFormatPreferences);
    assertEquals("Aoen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", ',', new BibDatabase()), true));
    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Éöning}, year={2000}}", importFormatPreferences);
    assertEquals("Eoen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", ',', new BibDatabase()), true));
    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Íöning}, year={2000}}", importFormatPreferences);
    assertEquals("Ioen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", ',', new BibDatabase()), true));
    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ĺöning}, year={2000}}", importFormatPreferences);
    assertEquals("Loen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", ',', new BibDatabase()), true));
    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ńöning}, year={2000}}", importFormatPreferences);
    assertEquals("Noen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", ',', new BibDatabase()), true));
    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Óöning}, year={2000}}", importFormatPreferences);
    assertEquals("Ooen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", ',', new BibDatabase()), true));
    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ŕöning}, year={2000}}", importFormatPreferences);
    assertEquals("Roen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", ',', new BibDatabase()), true));
    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Śöning}, year={2000}}", importFormatPreferences);
    assertEquals("Soen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", ',', new BibDatabase()), true));
    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Úöning}, year={2000}}", importFormatPreferences);
    assertEquals("Uoen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", ',', new BibDatabase()), true));
    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ýöning}, year={2000}}", importFormatPreferences);
    assertEquals("Yoen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", ',', new BibDatabase()), true));
    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Źöning}, year={2000}}", importFormatPreferences);
    assertEquals("Zoen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", ',', new BibDatabase()), true));
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Aggregations

BibDatabase (org.jabref.model.database.BibDatabase)88 BibEntry (org.jabref.model.entry.BibEntry)60 Test (org.junit.Test)44 ParserResult (org.jabref.logic.importer.ParserResult)20 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)15 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)15 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)13 MetaData (org.jabref.model.metadata.MetaData)12 IOException (java.io.IOException)10 Defaults (org.jabref.model.Defaults)9 Before (org.junit.Before)9 File (java.io.File)8 InputStreamReader (java.io.InputStreamReader)8 InputStream (java.io.InputStream)7 PropertyVetoException (com.sun.star.beans.PropertyVetoException)6 UnknownPropertyException (com.sun.star.beans.UnknownPropertyException)6 WrappedTargetException (com.sun.star.lang.WrappedTargetException)6 LinkedHashMap (java.util.LinkedHashMap)5 BasePanel (org.jabref.gui.BasePanel)5