@@ -2620,6 +2620,7 @@ def generateTestClasses(): Unit = {
2620
2620
genVavrFile(" io.vavr" , s " APITest " , baseDir = TARGET_TEST )((im : ImportManager , packageName, className) => {
2621
2621
2622
2622
val assertThat = im.getStatic(" org.assertj.core.api.Assertions.assertThat" )
2623
+ val nested = im.getType(" org.junit.jupiter.api.Nested" )
2623
2624
val test = im.getType(" org.junit.jupiter.api.Test" )
2624
2625
val assertThrows = im.getStatic(" org.junit.jupiter.api.Assertions.assertThrows" )
2625
2626
@@ -2892,168 +2893,188 @@ def generateTestClasses(): Unit = {
2892
2893
$AssertionsExtensions.assertThat( $API.class).isNotInstantiable();
2893
2894
}
2894
2895
2895
- // -- shortcuts
2896
+ @Nested
2897
+ class ShortcutTests {
2896
2898
2897
- ${genShortcutsTests(im, packageName, className)}
2899
+ ${genShortcutsTests(im, packageName, className)}
2900
+
2901
+ }
2898
2902
2899
2903
//
2900
2904
// Alias should return not null.
2901
2905
// More specific test for each aliased class implemented in separate test class
2902
2906
//
2903
2907
2904
- ${genAliasesTests(im, packageName, className)}
2908
+ @Nested
2909
+ class AliasTests {
2905
2910
2906
- // -- run
2911
+ ${genAliasesTests(im, packageName, className)}
2907
2912
2908
- @ $test
2909
- public void shouldRunUnitAndReturnVoid() {
2910
- int[] i = { 0 };
2911
- Void nothing = run(() -> i[0]++);
2912
- $assertThat(nothing).isNull();
2913
- $assertThat(i[0]).isEqualTo(1);
2914
2913
}
2915
2914
2916
- // -- For
2915
+ @Nested
2916
+ class RunTests {
2917
2917
2918
- @ $test
2919
- public void shouldIterateFor1UsingSimpleYield() {
2920
- final $ListType<Integer> list = List.of(1, 2, 3);
2921
- final $ListType<Integer> actual = For(list).yield().toList();
2922
- $assertThat(actual).isEqualTo(list);
2923
- }
2918
+ @ $test
2919
+ public void shouldRunUnitAndReturnVoid() {
2920
+ int[] i = { 0 };
2921
+ Void nothing = run(() -> i[0]++);
2922
+ $assertThat(nothing).isNull();
2923
+ $assertThat(i[0]).isEqualTo(1);
2924
+ }
2924
2925
2925
- ${(1 to N ).gen(i => xs """
2926
- @ $test
2927
- public void shouldIterateFor $ListType$i() {
2928
- final $ListType<Integer> result = For(
2929
- ${(1 to i).gen(j => s " $ListType.of(1, 2, 3) " )(" ,\n " )}
2930
- ).yield( ${(i > 1 ).gen(" (" )}${(1 to i).gen(j => s " i $j" )(" , " )}${(i > 1 ).gen(" )" )} -> ${(1 to i).gen(j => s " i $j" )(" + " )}).toList();
2931
- $assertThat(result.length()).isEqualTo((int) Math.pow(3, $i));
2932
- $assertThat(result.head()).isEqualTo( $i);
2933
- $assertThat(result.last()).isEqualTo(3 * $i);
2934
- }
2935
- """ )(" \n\n " )}
2926
+ }
2936
2927
2937
- ${monadicTypesFor.gen(mtype => (1 to N ).gen(i => { xs """
2938
- @ $test
2939
- public void shouldIterateFor $mtype$i() {
2940
- final $mtype<Integer> result = For(
2941
- ${(1 to i).gen(j => s " $mtype.of( $j) " )(" ,\n " )}
2942
- ).yield( ${(i > 1 ).gen(" (" )}${(1 to i).gen(j => s " i $j" )(" , " )}${(i > 1 ).gen(" )" )} -> ${(1 to i).gen(j => s " i $j" )(" + " )});
2943
- $assertThat(result.get()).isEqualTo( ${(1 to i).sum});
2944
- }
2945
- """ })(" \n\n " ))(" \n\n " )}
2928
+ @Nested
2929
+ class ForTests {
2946
2930
2947
- ${monadicFunctionTypesFor.gen(mtype => (1 to N ).gen(i => { xs """
2948
- @ $test
2949
- public void shouldIterateFor $mtype$i() {
2950
- final $mtype<Integer> result = For(
2951
- ${(1 to i).gen(j => s " $mtype.of(() -> $j) " )(" ,\n " )}
2952
- ).yield( ${(i > 1 ).gen(" (" )}${(1 to i).gen(j => s " i $j" )(" , " )}${(i > 1 ).gen(" )" )} -> ${(1 to i).gen(j => s " i $j" )(" + " )});
2953
- $assertThat(result.get()).isEqualTo( ${(1 to i).sum});
2954
- }
2955
- """ })(" \n\n " ))(" \n\n " )}
2931
+ @ $test
2932
+ public void shouldIterateFor1UsingSimpleYield() {
2933
+ final $ListType<Integer> list = List.of(1, 2, 3);
2934
+ final $ListType<Integer> actual = For(list).yield().toList();
2935
+ $assertThat(actual).isEqualTo(list);
2936
+ }
2956
2937
2957
- @ $test
2958
- public void shouldIterateNestedFor() {
2959
- final $ListType<String> result =
2960
- For( ${im.getType(" java.util.Arrays" )}.asList(1, 2), i ->
2961
- For( ${im.getType(" io.vavr.collection.List" )}.of('a', 'b')).yield(c -> i + ":" + c)).toList();
2962
- assertThat(result).isEqualTo( $ListType.of("1:a", "1:b", "2:a", "2:b"));
2963
- }
2938
+ ${(1 to N ).gen(i => xs """
2939
+ @ $test
2940
+ public void shouldIterateFor $ListType$i() {
2941
+ final $ListType<Integer> result = For(
2942
+ ${(1 to i).gen(j => s " $ListType.of(1, 2, 3) " )(" ,\n " )}
2943
+ ).yield( ${(i > 1 ).gen(" (" )}${(1 to i).gen(j => s " i $j" )(" , " )}${(i > 1 ).gen(" )" )} -> ${(1 to i).gen(j => s " i $j" )(" + " )}).toList();
2944
+ $assertThat(result.length()).isEqualTo((int) Math.pow(3, $i));
2945
+ $assertThat(result.head()).isEqualTo( $i);
2946
+ $assertThat(result.last()).isEqualTo(3 * $i);
2947
+ }
2948
+ """ )(" \n\n " )}
2964
2949
2965
- // -- Match
2950
+ ${monadicTypesFor.gen(mtype => (1 to N ).gen(i => { xs """
2951
+ @ $test
2952
+ public void shouldIterateFor $mtype$i() {
2953
+ final $mtype<Integer> result = For(
2954
+ ${(1 to i).gen(j => s " $mtype.of( $j) " )(" ,\n " )}
2955
+ ).yield( ${(i > 1 ).gen(" (" )}${(1 to i).gen(j => s " i $j" )(" , " )}${(i > 1 ).gen(" )" )} -> ${(1 to i).gen(j => s " i $j" )(" + " )});
2956
+ $assertThat(result.get()).isEqualTo( ${(1 to i).sum});
2957
+ }
2958
+ """ })(" \n\n " ))(" \n\n " )}
2966
2959
2967
- @ $test
2968
- public void shouldReturnSomeWhenApplyingCaseGivenPredicateAndSupplier() {
2969
- final Match.Case<Object, Integer> _case = Case( $$ (ignored -> true), ignored -> 1);
2970
- assertThat(_case.isDefinedAt(null)).isTrue();
2971
- assertThat(_case.apply(null)).isEqualTo(1);
2972
- }
2960
+ ${monadicFunctionTypesFor.gen(mtype => (1 to N ).gen(i => { xs """
2961
+ @ $test
2962
+ public void shouldIterateFor $mtype$i() {
2963
+ final $mtype<Integer> result = For(
2964
+ ${(1 to i).gen(j => s " $mtype.of(() -> $j) " )(" ,\n " )}
2965
+ ).yield( ${(i > 1 ).gen(" (" )}${(1 to i).gen(j => s " i $j" )(" , " )}${(i > 1 ).gen(" )" )} -> ${(1 to i).gen(j => s " i $j" )(" + " )});
2966
+ $assertThat(result.get()).isEqualTo( ${(1 to i).sum});
2967
+ }
2968
+ """ })(" \n\n " ))(" \n\n " )}
2973
2969
2974
- @ $test
2975
- public void shouldReturnNoneWhenApplyingCaseGivenPredicateAndSupplier() {
2976
- assertThat(Case( $$ (ignored -> false), ignored -> 1).isDefinedAt(null)).isFalse();
2977
- }
2970
+ @ $test
2971
+ public void shouldIterateNestedFor() {
2972
+ final $ListType<String> result =
2973
+ For( ${im.getType(" java.util.Arrays" )}.asList(1, 2), i ->
2974
+ For( ${im.getType(" io.vavr.collection.List" )}.of('a', 'b')).yield(c -> i + ":" + c)).toList();
2975
+ assertThat(result).isEqualTo( $ListType.of("1:a", "1:b", "2:a", "2:b"));
2976
+ }
2978
2977
2979
- @ $test
2980
- public void shouldReturnSomeWhenApplyingCaseGivenPredicateAndValue() {
2981
- final Match.Case<Object, Integer> _case = Case( $$ (ignored -> true), 1);
2982
- assertThat(_case.isDefinedAt(null)).isTrue();
2983
- assertThat(_case.apply(null)).isEqualTo(1);
2984
2978
}
2985
2979
2986
- @ $test
2987
- public void shouldReturnNoneWhenApplyingCaseGivenPredicateAndValue() {
2988
- assertThat(Case( $$ (ignored -> false), 1).isDefinedAt(null)).isFalse();
2989
- }
2980
+ @Nested
2981
+ class MatchTests {
2990
2982
2991
- @ $test
2992
- public void shouldPassIssue2401() {
2993
- final $SeqType<String> empty = $StreamType.empty();
2994
- try {
2995
- Match(empty).of(
2996
- Case( $$ ( $ListType.empty()), ignored -> "list")
2997
- );
2998
- fail("expected MatchError");
2999
- } catch (MatchError err) {
3000
- // ok!
2983
+ @ $test
2984
+ public void shouldReturnSomeWhenApplyingCaseGivenPredicateAndSupplier() {
2985
+ final Match.Case<Object, Integer> _case = Case( $$ (ignored -> true), ignored -> 1);
2986
+ assertThat(_case.isDefinedAt(null)).isTrue();
2987
+ assertThat(_case.apply(null)).isEqualTo(1);
3001
2988
}
3002
- }
3003
2989
3004
- @ $test
3005
- public void shouldCatchClassCastExceptionWhenPredicateHasDifferentType() {
3006
- try {
3007
- final Object o = "";
3008
- Match(o).of(
3009
- Case( $$ ((Integer i) -> true), "never")
3010
- );
3011
- fail("expected MatchError");
3012
- } catch (MatchError err) {
3013
- // ok!
2990
+ @ $test
2991
+ public void shouldReturnNoneWhenApplyingCaseGivenPredicateAndSupplier() {
2992
+ assertThat(Case( $$ (ignored -> false), ignored -> 1).isDefinedAt(null)).isFalse();
3014
2993
}
3015
- }
3016
-
3017
- // -- Match patterns
3018
2994
3019
- static class ClzMatch {}
3020
- static class ClzMatch1 extends ClzMatch {}
3021
- static class ClzMatch2 extends ClzMatch {}
2995
+ @ $test
2996
+ public void shouldReturnSomeWhenApplyingCaseGivenPredicateAndValue() {
2997
+ final Match.Case<Object, Integer> _case = Case( $$ (ignored -> true), 1);
2998
+ assertThat(_case.isDefinedAt(null)).isTrue();
2999
+ assertThat(_case.apply(null)).isEqualTo(1);
3000
+ }
3022
3001
3023
- ${(1 to N ).gen(i => {
3002
+ @ $test
3003
+ public void shouldReturnNoneWhenApplyingCaseGivenPredicateAndValue() {
3004
+ assertThat(Case( $$ (ignored -> false), 1).isDefinedAt(null)).isFalse();
3005
+ }
3024
3006
3025
- im.getStatic(" io.vavr.API.*" )
3026
- im.getStatic(" io.vavr.Patterns.*" )
3007
+ @ $test
3008
+ public void shouldPassIssue2401() {
3009
+ final $SeqType<String> empty = $StreamType.empty();
3010
+ try {
3011
+ Match(empty).of(
3012
+ Case( $$ ( $ListType.empty()), ignored -> "list")
3013
+ );
3014
+ fail("expected MatchError");
3015
+ } catch (MatchError err) {
3016
+ // ok!
3017
+ }
3018
+ }
3027
3019
3028
- xs """
3029
3020
@ $test
3030
- public void shouldMatchPattern $i() {
3031
- final Tuple $i< ${(1 to i).gen(j => s " Integer " )(" , " )}> tuple = Tuple.of( ${(1 to i).gen(j => s " 1 " )(" , " )});
3032
- final String func = Match(tuple).of(
3033
- Case( $$ Tuple $i( $d(0) ${(2 to i).gen(j => s " , $d() " )}), ( ${(1 to i).gen(j => s " m $j" )(" , " )}) -> "fail"),
3034
- Case( $$ Tuple $i( ${(1 to i).gen(j => s " $d() " )(" , " )}), ( ${(1 to i).gen(j => s " m $j" )(" , " )}) -> "okFunc")
3035
- );
3036
- assertThat(func).isEqualTo("okFunc");
3037
- final String supp = Match(tuple).of(
3038
- Case( $$ Tuple $i( $d(0) ${(2 to i).gen(j => s " , $d() " )}), () -> "fail"),
3039
- Case( $$ Tuple $i( ${(1 to i).gen(j => s " $d() " )(" , " )}), () -> "okSupp")
3040
- );
3041
- assertThat(supp).isEqualTo("okSupp");
3042
- final String val = Match(tuple).of(
3043
- Case( $$ Tuple $i( $d(0) ${(2 to i).gen(j => s " , $d() " )}), "fail"),
3044
- Case( $$ Tuple $i( ${(1 to i).gen(j => s " $d() " )(" , " )}), "okVal")
3045
- );
3046
- assertThat(val).isEqualTo("okVal");
3047
-
3048
- final ClzMatch c = new ClzMatch2();
3049
- final String match = Match(c).of(
3050
- Case(Match.Pattern $i.of(ClzMatch1.class, ${(1 to i).gen(j => s " $d() " )(" , " )}, t -> Tuple.of( ${(1 to i).gen(j => s " null " )(" , " )})), "fail"),
3051
- Case(Match.Pattern $i.of(ClzMatch2.class, ${(1 to i).gen(j => s " $d() " )(" , " )}, t -> Tuple.of( ${(1 to i).gen(j => s " null " )(" , " )})), "okMatch")
3052
- );
3053
- assertThat(match).isEqualTo("okMatch");
3021
+ public void shouldCatchClassCastExceptionWhenPredicateHasDifferentType() {
3022
+ try {
3023
+ final Object o = "";
3024
+ Match(o).of(
3025
+ Case( $$ ((Integer i) -> true), "never")
3026
+ );
3027
+ fail("expected MatchError");
3028
+ } catch (MatchError err) {
3029
+ // ok!
3030
+ }
3054
3031
}
3055
- """
3056
- })(" \n\n " )}
3032
+
3033
+ }
3034
+
3035
+ @Nested
3036
+ class MatchPatternTests {
3037
+
3038
+ class ClzMatch {}
3039
+ class ClzMatch1 extends ClzMatch {}
3040
+ class ClzMatch2 extends ClzMatch {}
3041
+
3042
+ ${(1 to N ).gen(i => {
3043
+
3044
+ im.getStatic(" io.vavr.API.*" )
3045
+ im.getStatic(" io.vavr.Patterns.*" )
3046
+
3047
+ xs """
3048
+ @ $test
3049
+ public void shouldMatchPattern $i() {
3050
+ final Tuple $i< ${(1 to i).gen(j => s " Integer " )(" , " )}> tuple = Tuple.of( ${(1 to i).gen(j => s " 1 " )(" , " )});
3051
+ final String func = Match(tuple).of(
3052
+ Case( $$ Tuple $i( $d(0) ${(2 to i).gen(j => s " , $d() " )}), ( ${(1 to i).gen(j => s " m $j" )(" , " )}) -> "fail"),
3053
+ Case( $$ Tuple $i( ${(1 to i).gen(j => s " $d() " )(" , " )}), ( ${(1 to i).gen(j => s " m $j" )(" , " )}) -> "okFunc")
3054
+ );
3055
+ assertThat(func).isEqualTo("okFunc");
3056
+ final String supp = Match(tuple).of(
3057
+ Case( $$ Tuple $i( $d(0) ${(2 to i).gen(j => s " , $d() " )}), () -> "fail"),
3058
+ Case( $$ Tuple $i( ${(1 to i).gen(j => s " $d() " )(" , " )}), () -> "okSupp")
3059
+ );
3060
+ assertThat(supp).isEqualTo("okSupp");
3061
+ final String val = Match(tuple).of(
3062
+ Case( $$ Tuple $i( $d(0) ${(2 to i).gen(j => s " , $d() " )}), "fail"),
3063
+ Case( $$ Tuple $i( ${(1 to i).gen(j => s " $d() " )(" , " )}), "okVal")
3064
+ );
3065
+ assertThat(val).isEqualTo("okVal");
3066
+
3067
+ final ClzMatch c = new ClzMatch2();
3068
+ final String match = Match(c).of(
3069
+ Case(Match.Pattern $i.of(ClzMatch1.class, ${(1 to i).gen(j => s " $d() " )(" , " )}, t -> Tuple.of( ${(1 to i).gen(j => s " null " )(" , " )})), "fail"),
3070
+ Case(Match.Pattern $i.of(ClzMatch2.class, ${(1 to i).gen(j => s " $d() " )(" , " )}, t -> Tuple.of( ${(1 to i).gen(j => s " null " )(" , " )})), "okMatch")
3071
+ );
3072
+ assertThat(match).isEqualTo("okMatch");
3073
+ }
3074
+ """
3075
+ })(" \n\n " )}
3076
+
3077
+ }
3057
3078
}
3058
3079
"""
3059
3080
})
0 commit comments