Search in sources :

Example 86 with ParserResult

use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.

the class BibtexParserTest method parseRecognizesBibtexKeyWithSpecialCharacters.

@Test
public void parseRecognizesBibtexKeyWithSpecialCharacters() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article{te_st:with-special(characters),author={Ed von Test}}"));
    Collection<BibEntry> c = result.getDatabase().getEntries();
    BibEntry e = c.iterator().next();
    assertEquals("article", e.getType());
    assertEquals(Optional.of("te_st:with-special(characters)"), e.getCiteKeyOptional());
    assertEquals(2, e.getFieldNames().size());
    assertEquals(Optional.of("Ed von Test"), e.getField("author"));
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 87 with ParserResult

use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.

the class BibtexParserTest method parseSetsParsedSerialization.

@Test
public void parseSetsParsedSerialization() throws IOException {
    String firstEntry = "@article{canh05," + "  author = {Crowston, K. and Annabi, H.}," + OS.NEWLINE + "  title = {Title A}}" + OS.NEWLINE;
    String secondEntry = "@inProceedings{foo," + "  author={Norton Bar}}";
    ParserResult result = parser.parse(new StringReader(firstEntry + secondEntry));
    for (BibEntry entry : result.getDatabase().getEntries()) {
        if (entry.getCiteKeyOptional().get().equals("canh05")) {
            assertEquals(firstEntry, entry.getParsedSerialization());
        } else {
            assertEquals(secondEntry, entry.getParsedSerialization());
        }
    }
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) StringReader(java.io.StringReader) BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Example 88 with ParserResult

use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.

the class BibtexParserTest method parseCommentWithoutBrackets.

@Test
public void parseCommentWithoutBrackets() throws IOException {
    String commentText = "@Comment someComment";
    ParserResult result = parser.parse(new StringReader(commentText));
    assertEquals(commentText, result.getDatabase().getEpilog());
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) StringReader(java.io.StringReader) BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Example 89 with ParserResult

use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.

the class BibtexParserTest method parseRecognizesDateFieldWithConcatenation.

/**
     * Test for SF Bug #48
     */
@Test
public void parseRecognizesDateFieldWithConcatenation() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article{test,date = {1-4~} # nov}"));
    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("1-4~#nov#"), e.getField("date"));
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 90 with ParserResult

use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.

the class BibtexParserTest method parseIgnoresAndWarnsAboutEntryWithUnmatchedOpenBracketInQuotationMarks.

@Test
public void parseIgnoresAndWarnsAboutEntryWithUnmatchedOpenBracketInQuotationMarks() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article{test,author=\"author {missing bracket\"}"));
    assertTrue(result.hasWarnings());
    Collection<BibEntry> c = result.getDatabase().getEntries();
    assertEquals(0, c.size());
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

ParserResult (org.jabref.logic.importer.ParserResult)196 Test (org.junit.Test)145 BibEntry (org.jabref.model.entry.BibEntry)131 StringReader (java.io.StringReader)130 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)38 BibtexString (org.jabref.model.entry.BibtexString)30 ArrayList (java.util.ArrayList)23 BibDatabase (org.jabref.model.database.BibDatabase)20 Path (java.nio.file.Path)14 IOException (java.io.IOException)12 StringWriter (java.io.StringWriter)12 File (java.io.File)10 InputStreamReader (java.io.InputStreamReader)10 HashMap (java.util.HashMap)10 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)9 InputStream (java.io.InputStream)8 Defaults (org.jabref.model.Defaults)8 Charset (java.nio.charset.Charset)6 Scanner (java.util.Scanner)5 BufferedReader (java.io.BufferedReader)4