Search in sources :

Example 61 with ParserResult

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

the class BibtexParserTest method parseCombinesMultipleKeywordsFields.

/**
     * Test for SF Bug #1269
     */
@Test
public void parseCombinesMultipleKeywordsFields() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article{test,Keywords={Test},Keywords={Second Keyword},Keywords={Third Keyword}}"));
    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("Test, Second Keyword, Third Keyword"), e.getField("keywords"));
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 62 with ParserResult

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

the class BibtexParserTest method parseRecognizesFieldsWithBracketsEnclosedInQuotationMarks.

@Test
public void parseRecognizesFieldsWithBracketsEnclosedInQuotationMarks() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article{test,author=\"Test {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("Test {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 63 with ParserResult

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

the class BibtexParserTest method parseRecognizesSaveActionsAfterEntry.

@Test
public void parseRecognizesSaveActionsAfterEntry() throws IOException {
    BibtexParser parser = this.parser;
    ParserResult parserResult = parser.parse(new StringReader("@InProceedings{6055279,\n" + "  Title                    = {Educational session 1},\n" + "  Booktitle                = {Custom Integrated Circuits Conference (CICC), 2011 IEEE},\n" + "  Year                     = {2011},\n" + "  Month                    = {Sept},\n" + "  Pages                    = {1-7},\n" + "  Abstract                 = {Start of the above-titled section of the conference proceedings record.},\n" + "  DOI                      = {10.1109/CICC.2011.6055279},\n" + "  ISSN                     = {0886-5930}\n" + "}\n" + "\n" + "@comment{jabref-meta: saveActions:enabled;title[lower_case]}"));
    FieldFormatterCleanups saveActions = parserResult.getMetaData().getSaveActions().get();
    assertTrue(saveActions.isEnabled());
    assertEquals(Collections.singletonList(new FieldFormatterCleanup("title", new LowerCaseFormatter())), saveActions.getConfiguredActions());
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) StringReader(java.io.StringReader) FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) LowerCaseFormatter(org.jabref.logic.formatter.casechanger.LowerCaseFormatter) Test(org.junit.Test)

Example 64 with ParserResult

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

the class BibtexParserTest method parseCommentContainingEntries.

@Test
public void parseCommentContainingEntries() throws IOException {
    // @formatter:off
    String bibtexEntry = "@Comment{@article{myarticle,}" + OS.NEWLINE + "@inproceedings{blabla, title={the proceedings of blabla}; }" + OS.NEWLINE + "} " + OS.NEWLINE + "@Article{test," + OS.NEWLINE + "  Author                   = {Foo Bar}," + OS.NEWLINE + "  Journal                  = {International Journal of Something}," + OS.NEWLINE + "  Note                     = {some note}," + OS.NEWLINE + "  Number                   = {1}" + OS.NEWLINE + "}";
    // @formatter:on
    ParserResult result = parser.parse(new StringReader(bibtexEntry));
    Collection<BibEntry> entries = result.getDatabase().getEntries();
    BibEntry entry = entries.iterator().next();
    assertEquals(bibtexEntry, 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 65 with ParserResult

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

the class BibtexParserTest method parseRecognizesFieldsWithEscapedQuotationMarks.

@Test
public void parseRecognizesFieldsWithEscapedQuotationMarks() throws IOException {
    // Quotes in fields of the form key = "value" have to be escaped by putting them into braces
    ParserResult result = parser.parse(new StringReader("@article{test,author=\"Test {\" 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("Test {\" 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