Search in sources :

Example 71 with ParserResult

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

the class BibtexParserTest method parseSavesOneNewlineAfterEntryInParsedSerialization.

@Test
public void parseSavesOneNewlineAfterEntryInParsedSerialization() throws IOException {
    String testEntry = "@article{test,author={Ed von Test}}";
    ParserResult result = parser.parse(new StringReader(testEntry + OS.NEWLINE + OS.NEWLINE));
    Collection<BibEntry> c = result.getDatabase().getEntries();
    assertEquals(1, c.size());
    BibEntry e = c.iterator().next();
    assertEquals(testEntry + OS.NEWLINE, e.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 72 with ParserResult

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

the class BibtexParserTest method parseRecognizesEntryWithUnknownType.

@Test
public void parseRecognizesEntryWithUnknownType() throws IOException {
    ParserResult result = parser.parse(new StringReader("@unknown{test,author={Ed von Test}}"));
    Collection<BibEntry> c = result.getDatabase().getEntries();
    assertEquals(1, c.size());
    BibEntry e = c.iterator().next();
    assertEquals("unknown", 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 73 with ParserResult

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

the class BibtexParserTest method parseRecognizesEntryWithAtInField.

@Test
public void parseRecognizesEntryWithAtInField() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article{test,author={Ed von T@st}}"));
    List<BibEntry> parsed = result.getDatabase().getEntries();
    BibEntry expected = new BibEntry("article").withField(BibEntry.KEY_FIELD, "test").withField("author", "Ed von T@st");
    assertEquals(Collections.singletonList(expected), parsed);
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 74 with ParserResult

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

the class BibtexParserTest method parseFileHeaderAndPreambleWithoutNewLine.

/**
     * Test for #669
     */
@Test
public void parseFileHeaderAndPreambleWithoutNewLine() throws IOException {
    ParserResult result = parser.parse(new StringReader("% Encoding: US-ASCII@preamble{some text and \\latex}"));
    assertFalse(result.hasWarnings());
    assertEquals(Optional.of("some text and \\latex"), result.getDatabase().getPreamble());
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 75 with ParserResult

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

the class BibtexParserTest method parseIgnoresUpercaseComments.

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