Skip to content

Commit

Permalink
Convert RemoveBracesFormatterTest to @ParameterizedTest (JabRef#11033)
Browse files Browse the repository at this point in the history
* Convert to @ParameterizedTest

* Convert to csvsource

---------

Co-authored-by: Carl Christian Snethlage <[email protected]>
  • Loading branch information
koppor and calixtus authored Mar 15, 2024
1 parent a6eee32 commit f5f92f9
Showing 1 changed file with 21 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.jabref.logic.formatter.bibtexfields;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -10,67 +11,25 @@
*/
public class RemoveBracesFormatterTest {

private RemoveBracesFormatter formatter;

@BeforeEach
public void setUp() {
formatter = new RemoveBracesFormatter();
}

@Test
public void formatRemovesSingleEnclosingBraces() {
assertEquals("test", formatter.format("{test}"));
}

@Test
public void formatKeepsUnmatchedBracesAtBeginning() {
assertEquals("{test", formatter.format("{test"));
}

@Test
public void formatKeepsUnmatchedBracesAtEnd() {
assertEquals("test}", formatter.format("test}"));
}

@Test
public void formatKeepsShortString() {
assertEquals("t", formatter.format("t"));
}

@Test
public void formatRemovesBracesOnly() {
assertEquals("", formatter.format("{}"));
}

@Test
public void formatKeepsEmptyString() {
assertEquals("", formatter.format(""));
}

@Test
public void formatRemovesDoubleEnclosingBraces() {
assertEquals("test", formatter.format("{{test}}"));
}

@Test
public void formatRemovesTripleEnclosingBraces() {
assertEquals("test", formatter.format("{{{test}}}"));
}

@Test
public void formatKeepsNonMatchingBraces() {
assertEquals("{A} and {B}", formatter.format("{A} and {B}"));
}

@Test
public void formatRemovesOnlyMatchingBraces() {
assertEquals("{A} and {B}", formatter.format("{{A} and {B}}"));
}

@Test
public void formatDoesNotRemoveBracesInBrokenString() {
// We opt here for a conservative approach although one could argue that "A} and {B}" is also a valid return
assertEquals("{A} and {B}}", formatter.format("{A} and {B}}"));
private final RemoveBracesFormatter formatter = new RemoveBracesFormatter();

@ParameterizedTest
@CsvSource({
"test, {test}", // formatRemovesSingleEnclosingBraces
"{test, {test", // formatKeepsUnmatchedBracesAtBeginning
"test}, test}", // formatKeepsUnmatchedBracesAtEnd
"t, t", // formatKeepsShortString
"'', {}", // formatRemovesBracesOnly
"test, {{test}}", // formatKeepsEmptyString
"test, {{{test}}}", // formatRemovesDoubleEnclosingBraces
"{A} and {B}, {A} and {B}", // formatRemovesTripleEnclosingBraces
"{A} and {B}, {{A} and {B}}", // formatKeepsNonMatchingBraces
"{A} and {B}}, {A} and {B}}", // formatRemovesOnlyMatchingBraces
"Vall{\\'e}e Poussin, {Vall{\\'e}e Poussin}", // formatDoesNotRemoveBracesInBrokenString
"Vall{\\'e}e Poussin, Vall{\\'e}e Poussin"
})
public void format(String expected, String input) {
assertEquals(expected, formatter.format(input));
}

@Test
Expand Down

0 comments on commit f5f92f9

Please sign in to comment.