Search in sources :

Example 66 with ParserResult

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

the class BibtexParserTest method parsePreambleAndEntryWithoutNewLine.

/**
     * Test for #669
     */
@Test
public void parsePreambleAndEntryWithoutNewLine() throws IOException {
    ParserResult result = parser.parse(new StringReader("@preamble{some text and \\latex}@article{test,author = {H\'{e}lne Fiaux}}"));
    assertFalse(result.hasWarnings());
    assertEquals(Optional.of("some text and \\latex"), result.getDatabase().getPreamble());
    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("H\'{e}lne Fiaux"), 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 67 with ParserResult

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

the class BibtexParserTest method parseRecognizesFormatedEntry.

@Test
public void parseRecognizesFormatedEntry() throws IOException {
    ParserResult result = BibtexParser.parse(new StringReader("" + "@INPROCEEDINGS{CroAnnHow05," + "\n" + "  author = {Crowston, K. and Annabi, H. and Howison, J. and Masango, C.}," + "\n" + "  title = {Effective work practices for floss development: A model and propositions}," + "\n" + "  booktitle = {Hawaii International Conference On System Sciences (HICSS)}," + "\n" + "  year = {2005}," + "\n" + "  owner = {oezbek}," + "\n" + "  timestamp = {2006.05.29}," + "\n" + "  url = {http://james.howison.name/publications.html}" + "\n" + "}))"), importFormatPreferences);
    Collection<BibEntry> c = result.getDatabase().getEntries();
    assertEquals(1, c.size());
    BibEntry e = c.iterator().next();
    assertEquals("inproceedings", e.getType());
    assertEquals(8, e.getFieldNames().size());
    assertEquals(Optional.of("CroAnnHow05"), e.getCiteKeyOptional());
    assertEquals(Optional.of("Crowston, K. and Annabi, H. and Howison, J. and Masango, C."), e.getField("author"));
    assertEquals(Optional.of("Effective work practices for floss development: A model and propositions"), e.getField("title"));
    assertEquals(Optional.of("Hawaii International Conference On System Sciences (HICSS)"), e.getField("booktitle"));
    assertEquals(Optional.of("2005"), e.getField("year"));
    assertEquals(Optional.of("oezbek"), e.getField("owner"));
    assertEquals(Optional.of("2006.05.29"), e.getField("timestamp"));
    assertEquals(Optional.of("http://james.howison.name/publications.html"), e.getField("url"));
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 68 with ParserResult

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

the class BibtexParserTest method parseRecognizesEntryWithWhitespace.

@Test
public void parseRecognizesEntryWithWhitespace() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article { test,author={Ed von Test}}"));
    List<BibEntry> parsed = result.getDatabase().getEntries();
    assertEquals(1, parsed.size());
    BibEntry e = parsed.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 69 with ParserResult

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

the class BibtexParserTest method parseNotWarnsAboutEntryWithoutBibtexKey.

@Test
public void parseNotWarnsAboutEntryWithoutBibtexKey() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article{,author={Ed von Test}}"));
    assertFalse(result.hasWarnings());
    Collection<BibEntry> c = result.getDatabase().getEntries();
    BibEntry e = new BibEntry();
    e.setField("author", "Ed von Test");
    e.setType("article");
    assertEquals(Collections.singletonList(e), c);
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 70 with ParserResult

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

the class BibtexParserTest method parseIgnoresAndWarnsAboutEntryWithUnmatchedOpenBracket.

@Test
public void parseIgnoresAndWarnsAboutEntryWithUnmatchedOpenBracket() 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