-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for month issue and strings (and some minor code impr… #5531
Changes from 1 commit
9bdfd9a
40c2a86
2a46d18
48d76c6
1632196
6893dc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,16 +10,17 @@ | |
* JabRef internal fields | ||
*/ | ||
public enum InternalField implements Field { | ||
INTERNAL_ALL_FIELD("all"), | ||
INTERNAL_ALL_TEXT_FIELDS_FIELD("all-text-fields"), | ||
MARKED_INTERNAL("__markedentry"), | ||
MARKED_INTERNAL("__markedentry"), // used in old versions of JabRef. Currently used for conversion only | ||
OWNER("owner"), | ||
TIMESTAMP("timestamp", FieldProperty.DATE), | ||
GROUPS("groups"), | ||
KEY_FIELD("bibtexkey"), | ||
TYPE_HEADER("entrytype"), | ||
OBSOLETE_TYPE_HEADER("bibtextype"), | ||
BIBTEX_STRING("__string"), | ||
// all field names starting with "Jabref-internal-" are not appearing in .bib files | ||
BIBTEX_STRING("JabRef-internal-bibtex-string"), // marker that the content is just a BibTeX string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing these values might lead to problems as they are (maybe) stored in bib files as keys for save actions or in the preferences. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked the usage of this string. It is called at the formatter only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really thought on these things and they MUST NOT stored in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm not mistaken, they are used in the serialization of save actions, e.g.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ups. OK, I put the old values back. |
||
INTERNAL_ALL_FIELD("JabRef-internal-all"), // virtual field to denote "all fields" | ||
INTERNAL_ALL_TEXT_FIELDS_FIELD("JabRef-internal-all-text-fields"), // virtual field to denote "all text fields" | ||
INTERNAL_ID_FIELD("JabRef-internal-id"); | ||
|
||
private final String name; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -289,7 +289,56 @@ void writeEntryWithCustomizedTypeAlsoWritesTypeDeclaration() throws Exception { | |
} | ||
|
||
@Test | ||
void roundtrip() throws Exception { | ||
void writeEntryWithConstantMonthApril() throws Exception { | ||
BibEntry entry = new BibEntry.Builder(StandardEntryType.Misc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests should go to the |
||
.field(StandardField.MONTH, "#apr#") | ||
.build(); | ||
database.insertEntry(entry); | ||
|
||
databaseWriter.savePartOfDatabase(bibtexContext, Collections.singletonList(entry)); | ||
|
||
assertEquals(OS.NEWLINE + | ||
"@Misc{," + OS.NEWLINE + | ||
" month = apr," + OS.NEWLINE + | ||
"}" + OS.NEWLINE + OS.NEWLINE + | ||
"@Comment{jabref-meta: databaseType:bibtex;}" + OS.NEWLINE, stringWriter.toString()); | ||
} | ||
|
||
@Test | ||
void writeEntryWithMonthApril() throws Exception { | ||
BibEntry entry = new BibEntry.Builder(StandardEntryType.Misc) | ||
.field(StandardField.MONTH, "apr") | ||
.build(); | ||
database.insertEntry(entry); | ||
|
||
databaseWriter.savePartOfDatabase(bibtexContext, Collections.singletonList(entry)); | ||
|
||
assertEquals(OS.NEWLINE + | ||
"@Misc{," + OS.NEWLINE + | ||
" month = {apr}," + OS.NEWLINE + | ||
"}" + OS.NEWLINE + OS.NEWLINE + | ||
"@Comment{jabref-meta: databaseType:bibtex;}" + OS.NEWLINE, stringWriter.toString()); | ||
} | ||
|
||
@Test | ||
void roundtripWithArticleMonths() throws Exception { | ||
Path testBibtexFile = Paths.get("src/test/resources/testbib/articleWithMonths.bib"); | ||
Charset encoding = StandardCharsets.UTF_8; | ||
ParserResult result = new BibtexParser(importFormatPreferences, fileMonitor).parse(Importer.getReader(testBibtexFile, encoding)); | ||
|
||
when(preferences.getEncoding()).thenReturn(encoding); | ||
when(preferences.isSaveInOriginalOrder()).thenReturn(true); | ||
BibDatabaseContext context = new BibDatabaseContext(result.getDatabase(), result.getMetaData(), | ||
new Defaults(BibDatabaseMode.BIBTEX)); | ||
|
||
databaseWriter.savePartOfDatabase(context, result.getDatabase().getEntries()); | ||
try (Scanner scanner = new Scanner(testBibtexFile, encoding.name())) { | ||
assertEquals(scanner.useDelimiter("\\A").next(), stringWriter.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried I came up with
Feels more complicated and I can't really get it to work as the assertion fails, but "Contents are equal" |
||
} | ||
} | ||
|
||
@Test | ||
void roundtripWithComplexBib() throws Exception { | ||
Path testBibtexFile = Paths.get("src/test/resources/testbib/complex.bib"); | ||
Charset encoding = StandardCharsets.UTF_8; | ||
ParserResult result = new BibtexParser(importFormatPreferences, fileMonitor).parse(Importer.getReader(testBibtexFile, encoding)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
% Encoding: UTF-8 | ||
@Article{constant, | ||
month = apr | ||
koppor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Article{text, | ||
month = {apr} | ||
} | ||
|
||
@Comment{jabref-meta: databaseType:bibtex;} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a good use case for ifPresent lambda, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sharedEntry.get().getField(field).ifPresent((v) -> localEntry.setField)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for hint. I fixed a modification of an unmodifiable collection. Seems that this feature is used very seldom. Hope, it gets better.