Search in sources :

Example 46 with ParserResult

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

the class BibtexParserTest method parseRecognizesEntryWithNewlines.

@Test
public void parseRecognizesEntryWithNewlines() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article\n{\ntest,author={Ed von Test}}"));
    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"), 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 47 with ParserResult

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

the class BibtexParserTest method parseRecognizesMonthFieldsWithFollowingComma.

/**
     * Test for SF Bug #1283
     */
@Test
public void parseRecognizesMonthFieldsWithFollowingComma() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article{test,author={Ed von Test},month={8,}},"));
    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(3, e.getFieldNames().size());
    assertEquals(Optional.of("Ed von Test"), e.getField("author"));
    assertEquals(Optional.of("8,"), e.getField("month"));
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 48 with ParserResult

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

the class BibtexParserTest method parseConvertsTabToSpace.

@Test
public void parseConvertsTabToSpace() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article{test,a = {a\tb}}"));
    Collection<BibEntry> c = result.getDatabase().getEntries();
    BibEntry e = c.iterator().next();
    assertEquals(Optional.of("a b"), e.getField("a"));
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 49 with ParserResult

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

the class BibtexParserTest method parseAddsEscapedOpenBracketToFieldValue.

/**
     * Test for SF bug 482
     */
@Test
public void parseAddsEscapedOpenBracketToFieldValue() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article{test,review={escaped \\{ bracket}}"));
    assertFalse(result.hasWarnings());
    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(Optional.of("escaped \\{ bracket"), e.getField("review"));
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 50 with ParserResult

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

the class BibtexParserTest method parseIgnoresText.

@Test
public void parseIgnoresText() throws IOException {
    ParserResult result = parser.parse(new StringReader("comment{some text and \\latex"));
    assertEquals(0, result.getDatabase().getEntries().size());
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) 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