1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-12-22 02:49:06 +00:00

test: first commit for some unit tests of tim/stdlib functions

- `AlwaysFalse`
  - `AlwaysTrue`
  - `Dec2hex`
  - `Feature`
  - `GetJsonKey`
  - `GetJsonType`
  - `Hex2dec`
  - `Lower`
  - `Size`
  - `Upper`
  - TBC...
This commit is contained in:
The-Lum 2023-09-17 19:18:35 +00:00
parent 957726fda0
commit f91e0db9eb
11 changed files with 663 additions and 1 deletions

View File

@ -0,0 +1,50 @@
package net.sourceforge.plantuml.tim.stdlib;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.IndicativeSentencesGeneration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.converter.ConvertWith;
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.TFunction;
/**
* Tests the builtin function.
*/
@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class)
class AlwaysFalseTest {
TFunction cut = new AlwaysFalse();
final String cutName = "AlwaysFalse";
@Test
void Test_without_Param() throws EaterException, EaterExceptionLocated {
assertTimExpectedOutput(cut, "0");
}
@ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}")
@CsvSource(nullValues = "null", value = {
" 0 , 0 ",
" 1 , 0 ",
" 'a' , 0 ",
})
void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(nullValues = "null", value = {
" 0 , 0 ",
" 1 , 0 ",
" 123 , 0 ",
})
void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
}

View File

@ -0,0 +1,50 @@
package net.sourceforge.plantuml.tim.stdlib;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.IndicativeSentencesGeneration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.converter.ConvertWith;
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.TFunction;
/**
* Tests the builtin function.
*/
@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class)
class AlwaysTrueTest {
TFunction cut = new AlwaysTrue();
final String cutName = "AlwaysTrue";
@Test
void Test_without_Param() throws EaterException, EaterExceptionLocated {
assertTimExpectedOutput(cut, "1");
}
@ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}")
@CsvSource(nullValues = "null", value = {
" 0 , 1 ",
" 1 , 1 ",
" 'a' , 1 ",
})
void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(nullValues = "null", value = {
" 0 , 1 ",
" 1 , 1 ",
" 123 , 1 ",
})
void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
}

View File

@ -0,0 +1,58 @@
package net.sourceforge.plantuml.tim.stdlib;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.IndicativeSentencesGeneration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.converter.ConvertWith;
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.TFunction;
/**
* Tests the builtin function.
*/
@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class)
class Dec2hexTest {
TFunction cut = new Dec2hex();
final String cutName = "Dec2hex";
@Test
void Test_without_Param() throws EaterException, EaterExceptionLocated {
assertTimExpectedOutput(cut, "");
}
@ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}")
@CsvSource(nullValues = "null", value = {
" 0 , 0 ",
" 1 , 0 ",
" 10 , 0 ",
" 15 , 0 ",
" 16 , 0 ",
" 255 , 0 ",
" 65535 , 0 ",
})
void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(nullValues = "null", value = {
" 0 , 0 ",
" 1 , 1 ",
" 10 , a ",
" 15 , f ",
" 16 , 10 ",
" 255 , ff ",
" 65535 , ffff ",
})
void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
}

View File

@ -0,0 +1,68 @@
package net.sourceforge.plantuml.tim.stdlib;
import static net.sourceforge.plantuml.test.JunitUtils.StringJsonConverter;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.IndicativeSentencesGeneration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.converter.ConvertWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import net.sourceforge.plantuml.json.JsonValue;
import net.sourceforge.plantuml.tim.EaterException;
import net.sourceforge.plantuml.tim.EaterExceptionLocated;
import net.sourceforge.plantuml.tim.TFunction;
/**
* Tests the builtin function.
*/
@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class)
class FeatureTest {
TFunction cut = new Feature();
final String cutName = "Feature";
@Disabled
@Test
void Test_without_Param() throws EaterException, EaterExceptionLocated {
assertTimExpectedOutput(cut, "0");
}
@ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}")
@CsvSource(nullValues = "null", value = {
" style, 1",
" theme, 1",
" Style, 1",
" Theme, 1",
" 0 , 0",
" 1 , 0",
" abc , 0",
})
void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(nullValues = "null", value = {
" 0, 0",
" 10, 0",
})
void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(value = {
" \"style\", 1",
" \"theme\", 1",
" 0, 0",
})
void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
}

View File

@ -0,0 +1,73 @@
package net.sourceforge.plantuml.tim.stdlib;
import static net.sourceforge.plantuml.test.JunitUtils.StringJsonConverter;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.IndicativeSentencesGeneration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.converter.ConvertWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import net.sourceforge.plantuml.json.JsonValue;
import net.sourceforge.plantuml.tim.EaterException;
import net.sourceforge.plantuml.tim.EaterExceptionLocated;
import net.sourceforge.plantuml.tim.TFunction;
/**
* Tests the builtin function.
*/
@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class)
class GetJsonKeyTest {
TFunction cut = new GetJsonKey();
final String cutName = "GetJsonKey";
@Disabled
@Test
void Test_without_Param() throws EaterException, EaterExceptionLocated {
assertTimExpectedOutput(cut, "0");
}
@Disabled // EaterException: Not JSON data
@ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}")
@CsvSource(nullValues = "null", value = {
" 0, Not JSON data",
" a, Not JSON data",
" -1, Not JSON data",
})
void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@Disabled // EaterException: Not JSON data
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(nullValues = "null", value = {
" 0, Not JSON data",
" -1, Not JSON data",
})
void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(value = {
" [] , []",
" '{\"a\":[1, 2]}' , [\"a\"]",
" '[{\"a\":[1, 2]}]' , [\"a\"]",
" '{\"a\":\"abc\"}' , [\"a\"]",
" '[{\"a\":[1, 2]}, {\"b\":[3, 4]}]' , '[\"a\",\"b\"]'",
" '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}' , '[\"a\",\"b\",\"b\"]'",
// TODO: Manage Array with different type inside
// Ref.:
// - https://datatracker.ietf.org/doc/html/rfc8259#section-5
// - https://json-schema.org/understanding-json-schema/reference/array.html
//" '[3, \"different\", { \"types\" : \"of values\" }]', [\"types\"]",
})
void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
}

View File

@ -0,0 +1,73 @@
package net.sourceforge.plantuml.tim.stdlib;
import static net.sourceforge.plantuml.test.JunitUtils.StringJsonConverter;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.IndicativeSentencesGeneration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.converter.ConvertWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import net.sourceforge.plantuml.json.JsonValue;
import net.sourceforge.plantuml.tim.EaterException;
import net.sourceforge.plantuml.tim.EaterExceptionLocated;
import net.sourceforge.plantuml.tim.TFunction;
/**
* Tests the builtin function.
*/
@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class)
class GetJsonTypeTest {
TFunction cut = new GetJsonType();
final String cutName = "GetJsonType";
@Disabled
@Test
void Test_without_Param() throws EaterException, EaterExceptionLocated {
assertTimExpectedOutput(cut, "0");
}
@ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}")
@CsvSource(nullValues = "null", value = {
" 0, string",
" a, string",
" -1, string",
})
void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(nullValues = "null", value = {
" 0, number",
" -1, number",
})
void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(value = {
" 0 , number",
" 123 , number",
" \"abc\" , string",
" \"string\" , string",
" '[1, 2]' , array",
" '[\"a\", \"b\"]' , array",
" '{\"a\":[1, 2]}' , object",
" '{\"a\":\"abc\"}' , object",
" true , boolean ",
" false , boolean ",
" 1 , number ",
" null , json ",
" '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}' , object",
})
void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
}

View File

@ -0,0 +1,61 @@
package net.sourceforge.plantuml.tim.stdlib;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.IndicativeSentencesGeneration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.converter.ConvertWith;
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.TFunction;
/**
* Tests the builtin function.
*/
@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class)
class Hex2decTest {
TFunction cut = new Hex2dec();
final String cutName = "Hex2dec";
@Test
void Test_without_Param() throws EaterException, EaterExceptionLocated {
assertTimExpectedOutput(cut, "0");
}
@ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}")
@CsvSource(nullValues = "null", value = {
" 0 , 0 ",
" 1 , 1 ",
" a , 10 ",
" f , 15 ",
" 10 , 16 ",
" ff , 255 ",
" ffff , 65535 ",
" ' ' , 0 ",
" g , 0 ",
" -g , 0 ",
" à , 0 ",
" -1 , -1 ",
" -a , -10 ",
})
void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(nullValues = "null", value = {
" 0 , 0 ",
" 1 , 1 ",
" 10 , 16 ",
" -1 , -1 ",
})
void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
}

View File

@ -0,0 +1,76 @@
package net.sourceforge.plantuml.tim.stdlib;
import static net.sourceforge.plantuml.test.JunitUtils.StringJsonConverter;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.IndicativeSentencesGeneration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.converter.ConvertWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import net.sourceforge.plantuml.json.JsonValue;
import net.sourceforge.plantuml.tim.EaterException;
import net.sourceforge.plantuml.tim.EaterExceptionLocated;
import net.sourceforge.plantuml.tim.TFunction;
/**
* Tests the builtin function.
*/
@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class)
class LowerTest {
TFunction cut = new Lower();
final String cutName = "Lower";
// TODO: Manage Lower function without param. (today: we observe `Function not found %lower`)
@Disabled
@Test
void Test_without_Param() throws EaterException, EaterExceptionLocated {
assertTimExpectedOutput(cut, "");
}
@ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}")
@CsvSource(nullValues = "null", value = {
" 0 , 0 ",
" 1 , 1 ",
" A , a ",
" a , a ",
" F , f ",
" G , g ",
" É , é ",
" 😀 , 😀 ",
})
void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(nullValues = "null", value = {
" 0 , 0 ",
" 1 , 1 ",
" 10 , 10 ",
" -1 , -1 ",
})
void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(value = {
" '{\"a\":[1, 2]}' , '{\"a\":[1,2]}'",
" '{\"A\":[1, 2]}' , '{\"a\":[1,2]}'",
" '[1, 2]' , '[1,2]'",
" '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}' , '{\"a\":[1,2],\"b\":\"abc\",\"b\":true}'",
" '{\"A\":[1, 2], \"B\":\"ABC\", \"B\":true}' , '{\"a\":[1,2],\"b\":\"abc\",\"b\":true}' ",
" true, true"
// TODO: See JSON management of TRUE/FALSE
//" TRUE , true ",
})
void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
}

View File

@ -0,0 +1,81 @@
package net.sourceforge.plantuml.tim.stdlib;
import static net.sourceforge.plantuml.test.JunitUtils.StringJsonConverter;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.IndicativeSentencesGeneration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.converter.ConvertWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import net.sourceforge.plantuml.json.JsonValue;
import net.sourceforge.plantuml.tim.EaterException;
import net.sourceforge.plantuml.tim.EaterExceptionLocated;
import net.sourceforge.plantuml.tim.TFunction;
/**
* Tests the builtin function.
*/
@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class)
class SizeTest {
TFunction cut = new Size();
final String cutName = "Size";
// TODO: Manage `Size` function without param. (today: we observe `Function not found`)
@Disabled
@Test
void Test_without_Param() throws EaterException, EaterExceptionLocated {
assertTimExpectedOutput(cut, "0");
}
@ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}")
@CsvSource(nullValues = "null", value = {
" 0 , 1 ",
" 1 , 1 ",
" 10 , 2 ",
" a , 1 ",
" A , 1 ",
" ABC , 3 ",
" '[1, 2]' , 6 ",
" '{[1, 2]}' , 8 ",
" à , 1 ",
// TODO: fix `Size` to allow Unicode chars, the corresponding tests are here:
// " 😀 , 1 ",
// " \uD83D\uDE00 , 1",
})
void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(nullValues = "null", value = {
" 0 , 0 ",
" 1 , 0 ",
" 10 , 0 ",
})
void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(value = {
" 0, 0",
" \"abc\", 0",
" '\"abc\"', 0",
" '{\"a\":[1, 2]}' , 1",
" '[1, 2]' , 2",
" '[\"a\", \"b\"]' , 2",
" '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}' , 3",
" true, 0 ",
" 1, 0 ",
" null, 0 ",
})
void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
}

View File

@ -0,0 +1,72 @@
package net.sourceforge.plantuml.tim.stdlib;
import static net.sourceforge.plantuml.test.JunitUtils.StringJsonConverter;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput;
import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.IndicativeSentencesGeneration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.converter.ConvertWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import net.sourceforge.plantuml.json.JsonValue;
import net.sourceforge.plantuml.tim.EaterException;
import net.sourceforge.plantuml.tim.EaterExceptionLocated;
import net.sourceforge.plantuml.tim.TFunction;
/**
* Tests the builtin function.
*/
@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class)
class UpperTest {
TFunction cut = new Upper();
final String cutName = "Upper";
// TODO: Manage Upper function without param. (today: we observe `Function not found %upper`)
@Disabled
@Test
void Test_without_Param() throws EaterException, EaterExceptionLocated {
assertTimExpectedOutput(cut, "");
}
@ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}")
@CsvSource(nullValues = "null", value = {
" 0 , 0 ",
" 1 , 1 ",
" a , A ",
" A , A ",
" f , F ",
" g , G ",
" é , É ",
" 😀 , 😀 ",
})
void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(nullValues = "null", value = {
" 0 , 0 ",
" 1 , 1 ",
" 10 , 10 ",
" -1 , -1 ",
})
void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
@ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}")
@CsvSource(value = {
" '{\"a\":[1, 2]}' , '{\"A\":[1,2]}'",
" '[1, 2]' , '[1,2]'",
" '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}' , '{\"A\":[1,2],\"B\":\"ABC\",\"B\":TRUE}'",
" true , TRUE ",
})
void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);
}
}

View File

@ -30,7 +30,7 @@ class XXXTest {
@Test
void Test_without_Param() throws EaterException, EaterExceptionLocated {
assertTimExpectedOutput(cut, "0"); // Change expetected value here
assertTimExpectedOutput(cut, "0"); // Change expected value here
}
@ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}")