Skip to content
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

Convert RemoveBracesFormatterTest to @ParameterizedTest #11033

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading