Search in sources :

Example 51 with ParserResult

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

the class BibtexParserTest method integrationTestSaveOrderConfig.

@Test
public void integrationTestSaveOrderConfig() throws IOException {
    ParserResult result = BibtexParser.parse(new StringReader("@Comment{jabref-meta: saveOrderConfig:specified;author;false;year;true;abstract;false;}"), importFormatPreferences);
    Optional<SaveOrderConfig> saveOrderConfig = result.getMetaData().getSaveOrderConfig();
    assertEquals(new SaveOrderConfig(false, new SaveOrderConfig.SortCriterion("author", false), new SaveOrderConfig.SortCriterion("year", true), new SaveOrderConfig.SortCriterion("abstract", false)), saveOrderConfig.get());
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) StringReader(java.io.StringReader) SaveOrderConfig(org.jabref.model.metadata.SaveOrderConfig) Test(org.junit.Test)

Example 52 with ParserResult

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

the class BibtexParserTest method parseRecognizesUppercasePreamble.

@Test
public void parseRecognizesUppercasePreamble() throws IOException {
    ParserResult result = parser.parse(new StringReader("@PREAMBLE{some text and \\latex}"));
    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 53 with ParserResult

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

the class BibtexParserTest method parseSavesNewlinesBetweenEntriesInParsedSerialization.

@Test
public void parseSavesNewlinesBetweenEntriesInParsedSerialization() throws IOException {
    String testEntryOne = "@article{test1,author={Ed von Test}}";
    String testEntryTwo = "@article{test2,author={Ed von Test}}";
    ParserResult result = parser.parse(new StringReader(testEntryOne + OS.NEWLINE + OS.NEWLINE + OS.NEWLINE + testEntryTwo));
    Collection<BibEntry> c = result.getDatabase().getEntries();
    assertEquals(2, c.size());
    Iterator<BibEntry> i = c.iterator();
    BibEntry a = i.next();
    BibEntry b = i.next();
    // Sort them because we can't be sure about the order
    if (a.getCiteKeyOptional().equals(Optional.of("test2"))) {
        BibEntry tmp = a;
        a = b;
        b = tmp;
    }
    assertEquals(testEntryOne + OS.NEWLINE, a.getParsedSerialization());
    assertEquals(OS.NEWLINE + OS.NEWLINE + testEntryTwo, b.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 54 with ParserResult

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

the class BibtexParserTest method parseHandlesAccentsCorrectly.

/**
     * Test for #650
     */
@Test
public void parseHandlesAccentsCorrectly() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article{test,author = {H\'{e}lne Fiaux}}"));
    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("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 55 with ParserResult

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

the class BibtexParserTest method parseIgnoresCommentsAfterEntry.

@Test
public void parseIgnoresCommentsAfterEntry() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article{test,author={Ed von Test}}" + "@comment{some text and \\latex}"));
    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)

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