-
-
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
Fix Abbreviation for Escaped Ampersand #9288
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
ed40cc2
Added Naive Ampersand Formatter, see last point in #8948 to-do
AkshatJain9 3dc87ae
Rudimentary attempt at allow \& in the journal abbreviation. However,…
ANUu7312578 e56af9e
Remove unnecessary code in BibWriter.java and unnecessary replacement…
ANUu7312578 ff15343
Merge branch 'main' of https://github.com/JabRef/jabref
ANUu7312578 bc31f93
Merge branch 'main' of https://github.com/AkshatJain9/jabref into iss…
ANUu7312578 4479e19
Merge branch 'JabRef:main' into main
AkshatJain9 03a996b
Merge branch 'JabRef:main' into issue-8948
AkshatJain9 1beef73
Merge branch 'main' of https://github.com/AkshatJain9/jabref into iss…
ANUu7312578 26b6527
Remove linebreak for checkstyle
ANUu7312578 97fdb55
Updated CHANGELOG.md to reflect the changes made
ANUu7312578 d34b5cd
Create tests for escaped ampersand in abbreviation
ANUu7312578 d8d0850
Merge branch 'main' of https://github.com/JabRef/jabref
ANUu7312578 64cc386
Merge branch 'main' of https://github.com/AkshatJain9/jabref into iss…
ANUu7312578 5426806
Remove unnecessary comments
ANUu7312578 0ed991b
Convert to using getResolvedFieldOrAliasLatexFree instead of replace()
ANUu7312578 d8a69c8
Added a javadoc to explain the function created
ANUu7312578 0efdc5a
Merge branch 'main' of https://github.com/JabRef/jabref
ANUu7312578 18d7d8b
Merge branch 'main' of https://github.com/AkshatJain9/jabref into iss…
ANUu7312578 e18c792
Added 3 tests to BibEntryWriterTest which test abbreviating journal e…
ANUu7312578 f4658bc
Merge branch 'main' of https://github.com/JabRef/jabref
ANUu7312578 943fa5b
Merge branch 'main' of https://github.com/AkshatJain9/jabref into iss…
ANUu7312578 7815ba0
Move journal abbreviation tests from BibEntryWriterTest to JournalAbb…
ANUu7312578 fc0907b
CHANGELOG.md changed to remove unnecessary information. restrictUsage…
ANUu7312578 0657b7e
Merge branch 'main' of https://github.com/JabRef/jabref
ANUu7312578 046498b
Merge branch 'main' of https://github.com/AkshatJain9/jabref into iss…
ANUu7312578 098bdac
Merge branch 'main' into issue-8948
Siedlerchr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,12 +1,24 @@ | ||||||||||
package org.jabref.logic.journals; | ||||||||||
|
||||||||||
import javax.swing.undo.CompoundEdit; | ||||||||||
|
||||||||||
import org.jabref.architecture.AllowedToUseSwing; | ||||||||||
import org.jabref.gui.journals.AbbreviationType; | ||||||||||
import org.jabref.gui.journals.UndoableAbbreviator; | ||||||||||
import org.jabref.gui.journals.UndoableUnabbreviator; | ||||||||||
import org.jabref.model.database.BibDatabase; | ||||||||||
import org.jabref.model.entry.BibEntry; | ||||||||||
import org.jabref.model.entry.field.StandardField; | ||||||||||
import org.jabref.model.entry.types.StandardEntryType; | ||||||||||
|
||||||||||
import org.junit.jupiter.api.BeforeEach; | ||||||||||
import org.junit.jupiter.api.Test; | ||||||||||
|
||||||||||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||||||||||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||||||||||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||||||||||
|
||||||||||
@AllowedToUseSwing("UndoableUnabbreviator and UndoableAbbreviator requires Swing Compound Edit in order test the abbreviation and unabreviation of journal titles") | ||||||||||
class JournalAbbreviationRepositoryTest { | ||||||||||
|
||||||||||
private JournalAbbreviationRepository repository; | ||||||||||
|
@@ -134,4 +146,61 @@ void getFromFullName() { | |||||||||
void getFromAbbreviatedName() { | ||||||||||
assertEquals(new Abbreviation("American Journal of Public Health", "Am. J. Public Health"), repository.get("Am. J. Public Health").get()); | ||||||||||
} | ||||||||||
|
||||||||||
@Test | ||||||||||
void testAbbreviationsWithEscapedAmpersand() { | ||||||||||
assertEquals(new Abbreviation("ACS Applied Materials & Interfaces", "ACS Appl. Mater. Interfaces"), repository.get("ACS Applied Materials & Interfaces").get()); | ||||||||||
assertEquals(new Abbreviation("ACS Applied Materials & Interfaces", "ACS Appl. Mater. Interfaces"), repository.get("ACS Applied Materials \\& Interfaces").get()); | ||||||||||
assertEquals(new Abbreviation("Antioxidants & Redox Signaling", "Antioxid. Redox Signaling"), repository.get("Antioxidants & Redox Signaling").get()); | ||||||||||
assertEquals(new Abbreviation("Antioxidants & Redox Signaling", "Antioxid. Redox Signaling"), repository.get("Antioxidants \\& Redox Signaling").get()); | ||||||||||
|
||||||||||
repository.addCustomAbbreviation(new Abbreviation("Long & Name", "L. N.", "LN")); | ||||||||||
assertEquals(new Abbreviation("Long & Name", "L. N.", "LN"), repository.get("Long & Name").get()); | ||||||||||
assertEquals(new Abbreviation("Long & Name", "L. N.", "LN"), repository.get("Long \\& Name").get()); | ||||||||||
Comment on lines
+152
to
+159
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. Normally, we expect one assertation per test case. Thus, this method should be split into several ones. |
||||||||||
} | ||||||||||
|
||||||||||
@Test | ||||||||||
void testJournalAbbreviationWithEscapedAmpersand() { | ||||||||||
BibDatabase bibDatabase = new BibDatabase(); | ||||||||||
JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); | ||||||||||
UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator(journalAbbreviationRepository, AbbreviationType.DEFAULT); | ||||||||||
|
||||||||||
BibEntry entryWithEscapedAmpersandInJournal = new BibEntry(StandardEntryType.Article); | ||||||||||
entryWithEscapedAmpersandInJournal.setField(StandardField.JOURNAL, "ACS Applied Materials \\& Interfaces"); | ||||||||||
Comment on lines
+168
to
+169
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.
Suggested change
|
||||||||||
|
||||||||||
undoableAbbreviator.abbreviate(bibDatabase, entryWithEscapedAmpersandInJournal, StandardField.JOURNAL, new CompoundEdit()); | ||||||||||
BibEntry expectedAbbreviatedJournalEntry = new BibEntry(StandardEntryType.Article) | ||||||||||
.withField(StandardField.JOURNAL, "ACS Appl. Mater. Interfaces"); | ||||||||||
assertEquals(expectedAbbreviatedJournalEntry, entryWithEscapedAmpersandInJournal); | ||||||||||
} | ||||||||||
|
||||||||||
@Test | ||||||||||
void testJournalUnabbreviate() { | ||||||||||
BibDatabase bibDatabase = new BibDatabase(); | ||||||||||
JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); | ||||||||||
UndoableUnabbreviator undoableUnabbreviator = new UndoableUnabbreviator(journalAbbreviationRepository); | ||||||||||
|
||||||||||
BibEntry abbreviatedJournalEntry = new BibEntry(StandardEntryType.Article); | ||||||||||
abbreviatedJournalEntry.setField(StandardField.JOURNAL, "ACS Appl. Mater. Interfaces"); | ||||||||||
|
||||||||||
undoableUnabbreviator.unabbreviate(bibDatabase, abbreviatedJournalEntry, StandardField.JOURNAL, new CompoundEdit()); | ||||||||||
BibEntry expectedAbbreviatedJournalEntry = new BibEntry(StandardEntryType.Article) | ||||||||||
.withField(StandardField.JOURNAL, "ACS Applied Materials & Interfaces"); | ||||||||||
assertEquals(expectedAbbreviatedJournalEntry, abbreviatedJournalEntry); | ||||||||||
} | ||||||||||
|
||||||||||
@Test | ||||||||||
void testJournalAbbreviateWithoutEscapedAmpersand() { | ||||||||||
BibDatabase bibDatabase = new BibDatabase(); | ||||||||||
JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); | ||||||||||
UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator(journalAbbreviationRepository, AbbreviationType.DEFAULT); | ||||||||||
|
||||||||||
BibEntry entryWithoutEscapedAmpersandInJournal = new BibEntry(StandardEntryType.Article); | ||||||||||
entryWithoutEscapedAmpersandInJournal.setField(StandardField.JOURNAL, "ACS Applied Materials & Interfaces"); | ||||||||||
|
||||||||||
undoableAbbreviator.abbreviate(bibDatabase, entryWithoutEscapedAmpersandInJournal, StandardField.JOURNAL, new CompoundEdit()); | ||||||||||
BibEntry expectedAbbreviatedJournalEntry = new BibEntry(StandardEntryType.Article) | ||||||||||
.withField(StandardField.JOURNAL, "ACS Appl. Mater. Interfaces"); | ||||||||||
assertEquals(expectedAbbreviatedJournalEntry, entryWithoutEscapedAmpersandInJournal); | ||||||||||
} | ||||||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think, there is the possibility to pre-compile the Regex. Was it with the
Pattern
class?