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());
}
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());
}
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"));
}
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());
}
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());
}
Aggregations