Search in sources :

Example 76 with ParserResult

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

the class BibtexParserTest method parseWarnsAboutUnmatchedContentInEntryWithoutComma.

@Test
public void parseWarnsAboutUnmatchedContentInEntryWithoutComma() throws IOException {
    ParserResult result = BibtexParser.parse(new StringReader("@article{test,author={author bracket } too much}"), importFormatPreferences);
    List<BibEntry> entries = result.getDatabase().getEntries();
    assertEquals(Optional.of("author bracket #too##much#"), entries.get(0).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 77 with ParserResult

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

the class BibtexParserTest method parseRecognizesDatabaseID.

@Test
public void parseRecognizesDatabaseID() throws Exception {
    BibtexParser parser = this.parser;
    String expectedDatabaseID = "q1w2e3r4t5z6";
    StringBuilder sharedDatabaseFileContent = new StringBuilder().append("% DBID: ").append(expectedDatabaseID).append(OS.NEWLINE).append("@Article{a}");
    ParserResult parserResult = parser.parse(new StringReader(sharedDatabaseFileContent.toString()));
    String actualDatabaseID = parserResult.getDatabase().getSharedDatabaseID().get();
    assertEquals(expectedDatabaseID, actualDatabaseID);
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) StringReader(java.io.StringReader) BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Example 78 with ParserResult

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

the class BibtexParserTest method parseRecognizesEntryWithBigNumbers.

/**
     * Test for [ 1594123 ] Failure to import big numbers Issue Reported by Ulf Martin. SF Bugs #503, #495 are also
     * related
     */
@Test
public void parseRecognizesEntryWithBigNumbers() throws IOException {
    ParserResult result = BibtexParser.parse(new StringReader("@article{canh05," + "isbn = 1234567890123456789,\n" + "isbn2 = {1234567890123456789},\n" + "small = 1234,\n" + "}"), importFormatPreferences);
    Collection<BibEntry> c = result.getDatabase().getEntries();
    BibEntry e = c.iterator().next();
    assertEquals("article", e.getType());
    assertEquals(Optional.of("canh05"), e.getCiteKeyOptional());
    assertEquals(Optional.of("1234567890123456789"), e.getField("isbn"));
    assertEquals(Optional.of("1234567890123456789"), e.getField("isbn2"));
    assertEquals(Optional.of("1234"), e.getField("small"));
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 79 with ParserResult

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

the class BibtexParserTest method parseRecognizesStringInParenthesis.

@Test
public void parseRecognizesStringInParenthesis() throws IOException {
    ParserResult result = parser.parse(new StringReader("@string(bourdieu = {Bourdieu, Pierre})"));
    assertEquals(1, result.getDatabase().getStringCount());
    BibtexString s = result.getDatabase().getStringValues().iterator().next();
    assertEquals("bourdieu", s.getName());
    assertEquals("Bourdieu, Pierre", s.getContent());
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) StringReader(java.io.StringReader) BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Example 80 with ParserResult

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

the class BibtexParserTest method parseAcceptsEntryWithAtSymbolInBrackets.

@Test
public void parseAcceptsEntryWithAtSymbolInBrackets() throws IOException {
    ParserResult result = parser.parse(new StringReader("@article{test,author={author @ good}}"));
    List<BibEntry> entries = result.getDatabase().getEntries();
    assertEquals(1, entries.size());
    assertEquals(Optional.of("author @ good"), entries.get(0).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