Search in sources :

Example 11 with BibtexString

use of org.jabref.model.entry.BibtexString in project jabref by JabRef.

the class BibtexDatabaseWriterTest method writeStringAndEncoding.

@Test
public void writeStringAndEncoding() throws Exception {
    SavePreferences preferences = new SavePreferences().withEncoding(Charsets.US_ASCII);
    database.addString(new BibtexString("name", "content"));
    StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), preferences);
    assertEquals("% Encoding: US-ASCII" + OS.NEWLINE + OS.NEWLINE + "@String{name = {content}}" + OS.NEWLINE, session.getStringValue());
}
Also used : BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Example 12 with BibtexString

use of org.jabref.model.entry.BibtexString in project jabref by JabRef.

the class BibtexParserTest method parseSavesOneNewlineAfterStringInParsedSerialization.

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

Example 13 with BibtexString

use of org.jabref.model.entry.BibtexString 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 14 with BibtexString

use of org.jabref.model.entry.BibtexString 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 15 with BibtexString

use of org.jabref.model.entry.BibtexString in project jabref by JabRef.

the class BibDatabaseTest method resolveForStringsSurroundingContent.

@Test
public void resolveForStringsSurroundingContent() {
    BibtexString string = new BibtexString("AAA", "aaa");
    database.addString(string);
    assertEquals(database.resolveForStrings("aa#AAA#AAA"), "aaaaaAAA");
}
Also used : BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Aggregations

BibtexString (org.jabref.model.entry.BibtexString)40 Test (org.junit.Test)24 ParserResult (org.jabref.logic.importer.ParserResult)8 BibEntry (org.jabref.model.entry.BibEntry)7 StringReader (java.io.StringReader)6 KeyCollisionException (org.jabref.model.database.KeyCollisionException)5 UndoableInsertString (org.jabref.gui.undo.UndoableInsertString)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 NamedCompound (org.jabref.gui.undo.NamedCompound)2 UndoableStringChange (org.jabref.gui.undo.UndoableStringChange)2 BibDatabase (org.jabref.model.database.BibDatabase)2 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Scanner (java.util.Scanner)1 Matcher (java.util.regex.Matcher)1