Merge pull request #1502 from The-Lum/Dev

refactor: use `CSV Source` for Math and UrlBuilder tests, test: add tests for the builtin function `%chr`
This commit is contained in:
PlantUML 2023-07-27 17:58:58 +02:00 committed by GitHub
commit 49115dfc7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 114 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,46 @@
package net.sourceforge.plantuml.tim.stdlib;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import net.sourceforge.plantuml.tim.EaterException;
import net.sourceforge.plantuml.tim.EaterExceptionLocated;
import net.sourceforge.plantuml.tim.expression.TValue;
/**
* Tests the builtin function %chr.
*/
class ChrTest {
/**
* Tests chr according to a list of input / expected output
*
* @throws EaterException should not
* @throws EaterExceptionLocated should not
*/
@ParameterizedTest
@CsvSource(nullValues = "null", value = {
" 65 , A ",
" 9 , '\t' ",
" 32 , ' ' ",
" 33 , '!' ",
" 34 , '\"' ",
" 224 , à ",
" 233 , é ",
// TODO: fix `%chr` to allow Unicode chars, the corresponding tests are here:
// " 128512 , 😀 ",
// " 128512 , \uD83D\uDE00 ",
})
void executeReturnFunctionChrTest(Integer input, String expected) throws EaterException, EaterExceptionLocated {
Chr cut = new Chr();
List<TValue> values = Collections.singletonList(TValue.fromInt(input));
TValue tValue = cut.executeReturnFunction(null, null, null, values, null);
assertEquals(expected, tValue.toString());
}
}

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");
}
}