1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-12-22 10:59:01 +00:00

refactor: use CSV Source for Math and UrlBuilder tests

For better readability and maintainability, use `@CsvSource` for:
- Math tests
- UrlBuilder tests

_[FYI: `testGetUrl42` and `testGetUrl50` seems to be identical!, I suppress one]_
This commit is contained in:
The-Lum 2023-07-27 15:25:42 +00:00
parent 74bcd0f668
commit c6cfd3cec6
12 changed files with 68 additions and 317 deletions

View File

@ -1,155 +0,0 @@
package net.sourceforge.plantuml;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import net.sourceforge.plantuml.url.Url;
import net.sourceforge.plantuml.url.UrlBuilder;
import net.sourceforge.plantuml.url.UrlMode;
class UrlBuilderTest {
@Test
public void testGetUrl10() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://foo", "http://foo", "http://foo", b.getUrl("[[http://foo]]"));
}
@Test
public void testGetUrl11() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://foo", "tooltip", "text", b.getUrl("[[http://foo{tooltip} text]]"));
}
@Test
public void testGetUrl12() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://foo", "tooltip", "text", b.getUrl("[[http://foo {tooltip} text]]"));
}
@Test
public void testGetUrl13() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://foo", "tooltip", "http://foo", b.getUrl("[[http://foo {tooltip}]]"));
}
@Test
public void testGetUrl15() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://foo", "http://foo", "text", b.getUrl("[[http://foo text]]"));
}
@Test
public void testGetUrl18() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://foo", "http://foo", "http://foo", b.getUrl("[[ http://foo ]]"));
}
@Test
public void testGetUrl20() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://foo test", "http://foo test", "http://foo test", b.getUrl("[[\"http://foo test\"]]"));
}
@Test
public void testGetUrl30() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.ANYWHERE);
assertUrl("http://foo test", "http://foo test", "http://foo test",
b.getUrl("start [[\"http://foo test\"]] end"));
}
@Test
public void testGetUrl40() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://google.com", "a nice toolip", "<img:HelloWorld.png{scale=2}>",
b.getUrl("[[http://google.com{a nice toolip} <img:HelloWorld.png{scale=2}>]]"));
}
@Test
public void testGetUrl41() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://google.com", "a nice toolip", "<img:HelloWorld.png{scale=2}>",
b.getUrl("[[http://google.com {a nice toolip} <img:HelloWorld.png{scale=2}>]]"));
}
@Test
public void testGetUrl42() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://google.com", "http://google.com", "<img:HelloWorld.png{scale=2}>",
b.getUrl("[[http://google.com <img:HelloWorld.png{scale=2}>]]"));
}
@Test
public void testGetUrl50() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://google.com", "http://google.com", "<img:HelloWorld.png{scale=2}>",
b.getUrl("[[http://google.com <img:HelloWorld.png{scale=2}>]]"));
}
@Test
public void testGetUrl60() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://foo?dummy={123}&action=edit", "http://foo?dummy={123}&action=edit",
"http://foo?dummy={123}&action=edit", b.getUrl("[[http://foo?dummy={123}&action=edit]]"));
}
@Test
public void testGetUrl70() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://www.plantuml.com", "Json: {\"firstName\":\"Bob\", \"lastName\":\"Smith\"}",
"http://www.plantuml.com",
b.getUrl("[[http://www.plantuml.com{Json: {\"firstName\":\"Bob\", \"lastName\":\"Smith\"}}]]"));
}
@Test
public void testGetUrl80() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://foo?dummy=", "123}z{", "http://foo?dummy=", b.getUrl("[[http://foo?dummy={123}z{}]]"));
}
@Test
public void testGetUrl90() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("", "tooltip", "some text", b.getUrl("[[{tooltip} some text]]"));
}
@Test
public void testGetUrl100() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.ANYWHERE);
assertUrl("www.google.com", "www.google.com", "POST /session/csrStart",
b.getUrl("fromor [[www.google.com POST /session/csrStart]] end"));
}
@Test
public void testGetUrl110() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("blaha(xyz,12)", " tooltip ", "blaha(xyz,12)", b.getUrl("[[ blaha(xyz,12){ tooltip } ]]"));
}
@Test
public void testGetUrl120() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("", "Json: {\"firstName\":\"Bob\", \"lastName\":\"Smith\"}", "",
b.getUrl("[[{Json: {\"firstName\":\"Bob\", \"lastName\":\"Smith\"}}]]"));
}
@Test
public void testGetUrl130() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://foo?dummy=", "123}{", "http://foo?dummy=", b.getUrl("[[http://foo?dummy={123}{}]]"));
}
@Test
public void testGetUrl140() {
final UrlBuilder b = new UrlBuilder(null, UrlMode.STRICT);
assertUrl("http://foo?dummy={123}", "", "http://foo?dummy={123}", b.getUrl("[[\"http://foo?dummy={123}\"{}]]"));
}
public void assertUrl(String urlLink, String tooltip, String label, Url url) {
assertEquals(urlLink, url.getUrl(), "url");
assertEquals(tooltip, url.getTooltip(), "tooltip");
assertEquals(label, url.getLabel(), "label");
}
}

View File

@ -1,18 +0,0 @@
package net.sourceforge.plantuml.math;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class Math01Test {
private final String math = "f(x)";
private final String expected = "{f{{\\left({x}\\right)}}}";
@Test
public void testJava() {
final String res = new ASCIIMathTeXImg().getTeX(math);
assertEquals(expected, res);
}
}

View File

@ -1,18 +0,0 @@
package net.sourceforge.plantuml.math;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class Math02Test {
private final String math = "x";
private final String expected = "{x}";
@Test
public void testJava() {
final String res = new ASCIIMathTeXImg().getTeX(math);
assertEquals(expected, res);
}
}

View File

@ -1,18 +0,0 @@
package net.sourceforge.plantuml.math;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class Math03Test {
private final String math = "color(red)(f(t))=color(blue)((a_0)/2 + sum_(n=1)^ooa_ncos((npit)/L)+sum_(n=1)^oo b_n\\ sin((npit)/L))";
private final String expected = "{\\textcolor{red}{{f{{\\left({t}\\right)}}}}}={\\textcolor{blue}{\\frac{{{a}_{{0}}}}{{2}}+{\\sum_{{{n}={1}}}^{\\infty}}{a}_{{n}}{\\cos{{\\left(\\frac{{{n}\\pi{t}}}{{L}}\\right)}}}+{\\sum_{{{n}={1}}}^{\\infty}}{b}_{{n}}\\ {\\sin{{\\left(\\frac{{{n}\\pi{t}}}{{L}}\\right)}}}}}";
@Test
public void testJava() {
final String res = new ASCIIMathTeXImg().getTeX(math);
assertEquals(expected, res);
}
}

View File

@ -1,18 +0,0 @@
package net.sourceforge.plantuml.math;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class Math04Test {
private final String math = "abs(x)";
private final String expected = "{\\left|{{x}}\\right|}";
@Test
public void testJava() {
final String res = new ASCIIMathTeXImg().getTeX(math);
assertEquals(expected, res);
}
}

View File

@ -1,18 +0,0 @@
package net.sourceforge.plantuml.math;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class Math05Test {
private final String math = "y=ceil(x)";
private final String expected = "{y}={\\left\\lceil{{x}}\\right\\rceil}";
@Test
public void testJava() {
final String res = new ASCIIMathTeXImg().getTeX(math);
assertEquals(expected, res);
}
}

View File

@ -1,18 +0,0 @@
package net.sourceforge.plantuml.math;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class Math06Test {
private final String math = "f(t)=(a_0)/2 + sum_(n=1)^ooa_ncos((npit)/L)+sum_(n=1)^oo b_n\\ sin((npit)/L)";
private final String expected = "{f{{\\left({t}\\right)}}}=\\frac{{{a}_{{0}}}}{{2}}+{\\sum_{{{n}={1}}}^{\\infty}}{a}_{{n}}{\\cos{{\\left(\\frac{{{n}\\pi{t}}}{{L}}\\right)}}}+{\\sum_{{{n}={1}}}^{\\infty}}{b}_{{n}}\\ {\\sin{{\\left(\\frac{{{n}\\pi{t}}}{{L}}\\right)}}}";
@Test
public void testJava() {
final String res = new ASCIIMathTeXImg().getTeX(math);
assertEquals(expected, res);
}
}

View File

@ -1,18 +0,0 @@
package net.sourceforge.plantuml.math;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class Math07Test {
private final String math = "[[a,b],[c,d]]";
private final String expected = "{\\left[\\begin{matrix}{a}&{b}\\\\{c}&{d}\\end{matrix}\\right]}";
@Test
public void testJava() {
final String res = new ASCIIMathTeXImg().getTeX(math);
assertEquals(expected, res);
}
}

View File

@ -1,18 +0,0 @@
package net.sourceforge.plantuml.math;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class Math08Test {
private final String math = "color(red)(x)";
private final String expected = "{\\textcolor{red}{{x}}}";
@Test
public void testJava() {
final String res = new ASCIIMathTeXImg().getTeX(math);
assertEquals(expected, res);
}
}

View File

@ -1,18 +0,0 @@
package net.sourceforge.plantuml.math;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class Math09Test {
private final String math = "color(red)(t)=color(blue)(x)";
private final String expected = "{\\textcolor{red}{{t}}}={\\textcolor{blue}{{x}}}";
@Test
public void testJava() {
final String res = new ASCIIMathTeXImg().getTeX(math);
assertEquals(expected, res);
}
}

View File

@ -0,0 +1,25 @@
package net.sourceforge.plantuml.math;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
class MathTest {
@ParameterizedTest
@CsvSource(value = {
" f(x), {f{{\\left({x}\\right)}}} ",
" x, {x} ",
" color(red)(f(t))=color(blue)((a_0)/2 + sum_(n=1)^ooa_ncos((npit)/L)+sum_(n=1)^oo b_n\\ sin((npit)/L)), {\\textcolor{red}{{f{{\\left({t}\\right)}}}}}={\\textcolor{blue}{\\frac{{{a}_{{0}}}}{{2}}+{\\sum_{{{n}={1}}}^{\\infty}}{a}_{{n}}{\\cos{{\\left(\\frac{{{n}\\pi{t}}}{{L}}\\right)}}}+{\\sum_{{{n}={1}}}^{\\infty}}{b}_{{n}}\\ {\\sin{{\\left(\\frac{{{n}\\pi{t}}}{{L}}\\right)}}}}} ",
" abs(x), {\\left|{{x}}\\right|} ",
" y=ceil(x), {y}={\\left\\lceil{{x}}\\right\\rceil} ",
" f(t)=(a_0)/2 + sum_(n=1)^ooa_ncos((npit)/L)+sum_(n=1)^oo b_n\\ sin((npit)/L), {f{{\\left({t}\\right)}}}=\\frac{{{a}_{{0}}}}{{2}}+{\\sum_{{{n}={1}}}^{\\infty}}{a}_{{n}}{\\cos{{\\left(\\frac{{{n}\\pi{t}}}{{L}}\\right)}}}+{\\sum_{{{n}={1}}}^{\\infty}}{b}_{{n}}\\ {\\sin{{\\left(\\frac{{{n}\\pi{t}}}{{L}}\\right)}}} ",
" '[[a,b],[c,d]]', {\\left[\\begin{matrix}{a}&{b}\\\\{c}&{d}\\end{matrix}\\right]} ",
" color(red)(x), {\\textcolor{red}{{x}}} ",
" color(red)(t)=color(blue)(x), {\\textcolor{red}{{t}}}={\\textcolor{blue}{{x}}} ",
})
public void testMath(String input, String expected) {
final String res = new ASCIIMathTeXImg().getTeX(input);
assertEquals(expected, res);
}
}

View File

@ -0,0 +1,43 @@
package net.sourceforge.plantuml;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import net.sourceforge.plantuml.url.Url;
import net.sourceforge.plantuml.url.UrlBuilder;
import net.sourceforge.plantuml.url.UrlMode;
class UrlBuilderTest {
@ParameterizedTest
@CsvSource(value = {
" [[http://foo]], STRICT, http://foo, http://foo, http://foo ",
" [[http://foo{tooltip} text]], STRICT, http://foo, tooltip, text ",
" [[http://foo {tooltip} text]], STRICT, http://foo, tooltip, text ",
" [[http://foo {tooltip}]], STRICT, http://foo, tooltip, http://foo ",
" [[http://foo text]], STRICT, http://foo, http://foo, text ",
" [[ http://foo ]], STRICT, http://foo, http://foo, http://foo ",
" [[\"http://foo text\"]], STRICT, http://foo text, http://foo text, http://foo text ",
" start [[\"http://foo test\"]] end, ANYWHERE, http://foo test, http://foo test, http://foo test ",
" [[http://google.com{a nice toolip} <img:HelloWorld.png{scale=2}>]], STRICT, http://google.com, a nice toolip, <img:HelloWorld.png{scale=2}> ",
" [[http://google.com {a nice toolip} <img:HelloWorld.png{scale=2}>]], STRICT, http://google.com, a nice toolip, <img:HelloWorld.png{scale=2}> ",
" [[http://google.com <img:HelloWorld.png{scale=2}>]], STRICT, http://google.com, http://google.com, <img:HelloWorld.png{scale=2}> ",
" [[http://foo?dummy={123}&action=edit]], STRICT, http://foo?dummy={123}&action=edit, http://foo?dummy={123}&action=edit, http://foo?dummy={123}&action=edit",
" '[[http://www.plantuml.com{Json: {\"firstName\":\"Bob\", \"lastName\":\"Smith\"}}]]', STRICT, http://www.plantuml.com, 'Json: {\"firstName\":\"Bob\", \"lastName\":\"Smith\"}', http://www.plantuml.com",
" [[http://foo?dummy={123}z{}]], STRICT, http://foo?dummy=, 123}z{, http://foo?dummy= ",
" [[{tooltip} some text]], STRICT, '', tooltip, some text ",
" fromor [[www.google.com POST /session/csrStart]] end, ANYWHERE, www.google.com, www.google.com, POST /session/csrStart ",
" '[[ blaha(xyz,12){ tooltip } ]]', STRICT, 'blaha(xyz,12)', ' tooltip ', 'blaha(xyz,12)' ",
" '[[{Json: {\"firstName\":\"Bob\", \"lastName\":\"Smith\"}}]]', STRICT, '', 'Json: {\"firstName\":\"Bob\", \"lastName\":\"Smith\"}','' ",
" [[http://foo?dummy={123}{}]], STRICT, http://foo?dummy=, 123}{, http://foo?dummy= ",
" [[\"http://foo?dummy={123}\"{}]], STRICT, http://foo?dummy={123}, '', http://foo?dummy={123} ",
})
public void testUrl(String input, String urlMode, String urlLink, String tooltip, String label) {
final UrlBuilder b = new UrlBuilder(null, UrlMode.valueOf(urlMode));
final Url url = b.getUrl(input);
assertEquals(urlLink, url.getUrl(), "url");
assertEquals(tooltip, url.getTooltip(), "tooltip");
assertEquals(label, url.getLabel(), "label");
}
}