Search in sources :

Example 81 with ParserResult

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

the class BibtexParserTest method integrationTestGroupTree.

@Test
public void integrationTestGroupTree() throws IOException, ParseException {
    ParserResult result = BibtexParser.parse(new StringReader("@comment{jabref-meta: groupsversion:3;}" + OS.NEWLINE + "@comment{jabref-meta: groupstree:" + OS.NEWLINE + "0 AllEntriesGroup:;" + OS.NEWLINE + "1 KeywordGroup:Fréchet\\;0\\;keywords\\;FrechetSpace\\;0\\;1\\;;" + OS.NEWLINE + "1 KeywordGroup:Invariant theory\\;0\\;keywords\\;GIT\\;0\\;0\\;;" + OS.NEWLINE + "1 ExplicitGroup:TestGroup\\;0\\;Key1\\;Key2\\;;" + "}"), importFormatPreferences);
    GroupTreeNode root = result.getMetaData().getGroups().get();
    assertEquals(new AllEntriesGroup("All entries"), root.getGroup());
    assertEquals(3, root.getNumberOfChildren());
    assertEquals(new RegexKeywordGroup("Fréchet", GroupHierarchyType.INDEPENDENT, "keywords", "FrechetSpace", false), root.getChildren().get(0).getGroup());
    assertEquals(new WordKeywordGroup("Invariant theory", GroupHierarchyType.INDEPENDENT, "keywords", "GIT", false, ',', false), root.getChildren().get(1).getGroup());
    assertEquals(Arrays.asList("Key1", "Key2"), ((ExplicitGroup) root.getChildren().get(2).getGroup()).getLegacyEntryKeys());
}
Also used : AllEntriesGroup(org.jabref.model.groups.AllEntriesGroup) ParserResult(org.jabref.logic.importer.ParserResult) StringReader(java.io.StringReader) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup) Test(org.junit.Test)

Example 82 with ParserResult

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

the class BibtexParserTest method parseCommentAndEntryInOneLine.

@Test
public void parseCommentAndEntryInOneLine() throws IOException {
    // @formatter:off
    String bibtexEntry = "Some random comment that should stay here @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
    // read in bibtex string
    ParserResult result = parser.parse(new StringReader(bibtexEntry));
    Collection<BibEntry> entries = result.getDatabase().getEntries();
    assertEquals(1, entries.size());
    BibEntry entry = entries.iterator().next();
    assertEquals(Optional.of("test"), entry.getCiteKeyOptional());
    assertEquals(5, entry.getFieldNames().size());
    Set<String> fields = entry.getFieldNames();
    assertTrue(fields.contains("author"));
    assertEquals(Optional.of("Foo Bar"), entry.getField("author"));
    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 83 with ParserResult

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

the class BibtexParserTest method parseRecognizesStringAndEntry.

@Test
public void parseRecognizesStringAndEntry() throws IOException {
    ParserResult result = BibtexParser.parse(new StringReader("" + "@string{bourdieu = {Bourdieu, Pierre}}" + "@book{bourdieu-2002-questions-sociologie, " + "	Address = {Paris}," + "	Author = bourdieu," + "	Isbn = 2707318256," + "	Publisher = {Minuit}," + "	Title = {Questions de sociologie}," + "	Year = 2002" + "}"), importFormatPreferences);
    assertEquals(1, result.getDatabase().getStringCount());
    BibtexString s = result.getDatabase().getStringValues().iterator().next();
    assertEquals("bourdieu", s.getName());
    assertEquals("Bourdieu, Pierre", s.getContent());
    Collection<BibEntry> c = result.getDatabase().getEntries();
    assertEquals(1, c.size());
    BibEntry e = c.iterator().next();
    assertEquals("book", e.getType());
    assertEquals(Optional.of("bourdieu-2002-questions-sociologie"), e.getCiteKeyOptional());
    assertEquals(Optional.of("Paris"), e.getField("address"));
    assertEquals(Optional.of("#bourdieu#"), e.getField("author"));
    assertEquals(Optional.of("2707318256"), e.getField("isbn"));
    assertEquals(Optional.of("Minuit"), e.getField("publisher"));
    assertEquals(Optional.of("Questions de sociologie"), e.getField("title"));
    assertEquals(Optional.of("2002"), e.getField("year"));
}
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 84 with ParserResult

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

the class BibtexParserTest method parseRecognizesPreamble.

@Test
public void parseRecognizesPreamble() 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 85 with ParserResult

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

the class BibtexParserTest method parseIgnoresComments.

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