-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NormalizeEnDashesFormatter (#4045)
* Add NormalizeEnDashesFormatter * Adapt to new Formatter hiearchy * Add missing localization keys
- Loading branch information
1 parent
cab2692
commit b029c72
Showing
5 changed files
with
91 additions
and
0 deletions.
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
32 changes: 32 additions & 0 deletions
32
src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatter.java
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.jabref.logic.formatter.bibtexfields; | ||
|
||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.cleanup.Formatter; | ||
|
||
public class NormalizeEnDashesFormatter extends Formatter { | ||
|
||
@Override | ||
public String getName() { | ||
return Localization.lang("Normalize en dashes"); | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return "normalize_en_dashes"; | ||
} | ||
|
||
@Override | ||
public String format(String value) { | ||
return value.replaceAll(" - ", " -- "); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return Localization.lang("Normalizes the en dashes."); | ||
} | ||
|
||
@Override | ||
public String getExampleInput() { | ||
return "Winery - A Modeling Tool for TOSCA-based Cloud Applications"; | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.jabref.logic.formatter.bibtexfields; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* Tests in addition to the general tests from {@link org.jabref.logic.formatter.FormatterTest} | ||
*/ | ||
public class NormalizeEnDashesFormatterTest { | ||
|
||
private NormalizeEnDashesFormatter formatter; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
formatter = new NormalizeEnDashesFormatter(); | ||
} | ||
|
||
@Test | ||
public void formatExample() { | ||
assertEquals("Winery -- A Modeling Tool for TOSCA-based Cloud Applications", formatter.format(formatter.getExampleInput())); | ||
} | ||
|
||
@Test | ||
public void formatExampleOfChangelog() { | ||
assertEquals("Example -- illustrative", formatter.format("Example - illustrative")); | ||
} | ||
|
||
@Test | ||
public void dashesWithinWordsAreKept() { | ||
assertEquals("Example-illustrative", formatter.format("Example-illustrative")); | ||
} | ||
|
||
@Test | ||
public void dashesPreceededByASpaceAreKept() { | ||
assertEquals("Example -illustrative", formatter.format("Example -illustrative")); | ||
} | ||
|
||
@Test | ||
public void dashesFollowedByASpaceAreKept() { | ||
assertEquals("Example- illustrative", formatter.format("Example- illustrative")); | ||
} | ||
|
||
@Test | ||
public void dashAtTheBeginningIsKept() { | ||
assertEquals("- illustrative", formatter.format("- illustrative")); | ||
} | ||
|
||
@Test | ||
public void dashAtTheEndIsKept() { | ||
assertEquals("Example-", formatter.format("Example-")); | ||
} | ||
} |