@@ -2712,6 +2712,285 @@ public void shouldReplaceAllRegexesInNestedArray() {
2712
2712
);
2713
2713
}
2714
2714
2715
+ @ Test
2716
+ public void copyFieldWithoutReplaceAllString () {
2717
+ copyFieldWithReplaceAllString (false );
2718
+ }
2719
+
2720
+ @ Test
2721
+ public void copyFieldWithReplaceAllString () {
2722
+ copyFieldWithReplaceAllString (true );
2723
+ }
2724
+
2725
+ private void copyFieldWithReplaceAllString (final boolean replaceAll ) {
2726
+ MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
2727
+ "do list(path: 'contribution[]', 'var': '$i')" ,
2728
+ " copy_field('$i.label', '$i.agent.altLabel')" ,
2729
+ "end" ,
2730
+ "do list(path: 'subject[]', 'var': '$i')" ,
2731
+ " copy_field('$i.label', '$i.altLabel')" ,
2732
+ "end" ,
2733
+ replaceAll ? "replace_all('contribution[].*.agent.altLabel', 't', '')" : "" ,
2734
+ replaceAll ? "replace_all('subject[].*.altLabel', 't', '')" : ""
2735
+ ),
2736
+ i -> {
2737
+ i .startRecord ("1" );
2738
+ i .startEntity ("contribution[]" );
2739
+ i .startEntity ("1" );
2740
+ i .literal ("label" , "contribution" );
2741
+ i .endEntity ();
2742
+ i .endEntity ();
2743
+ i .startEntity ("subject[]" );
2744
+ i .startEntity ("1" );
2745
+ i .literal ("label" , "subject" );
2746
+ i .endEntity ();
2747
+ i .endEntity ();
2748
+ i .endRecord ();
2749
+ },
2750
+ (o , f ) -> {
2751
+ o .get ().startRecord ("1" );
2752
+ o .get ().startEntity ("contribution[]" );
2753
+ o .get ().startEntity ("1" );
2754
+ o .get ().literal ("label" , "contribution" );
2755
+ o .get ().startEntity ("agent" );
2756
+ o .get ().literal ("altLabel" , replaceAll ? "conribuion" : "contribution" );
2757
+ f .apply (3 ).endEntity ();
2758
+ o .get ().startEntity ("subject[]" );
2759
+ o .get ().startEntity ("1" );
2760
+ o .get ().literal ("label" , "subject" );
2761
+ o .get ().literal ("altLabel" , replaceAll ? "subjec" : "subject" );
2762
+ f .apply (2 ).endEntity ();
2763
+ o .get ().endRecord ();
2764
+ }
2765
+ );
2766
+ }
2767
+
2768
+ @ Test
2769
+ public void addFieldWithoutReplaceAllArray () {
2770
+ addFieldWithReplaceAllArray (false );
2771
+ }
2772
+
2773
+ @ Test
2774
+ public void addFieldWithReplaceAllArray () {
2775
+ addFieldWithReplaceAllArray (true );
2776
+ }
2777
+
2778
+ private void addFieldWithReplaceAllArray (final boolean replaceAll ) {
2779
+ MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
2780
+ "do list(path: 'contribution[]', 'var': '$i')" ,
2781
+ " set_array('$i.agent.altLabel[]')" ,
2782
+ " add_field('$i.agent.altLabel[].$append', 'contribution')" ,
2783
+ "end" ,
2784
+ "do list(path: 'subject[]', 'var': '$i')" ,
2785
+ " set_array('$i.altLabel[]')" ,
2786
+ " add_field('$i.altLabel[].$append', 'subject')" ,
2787
+ "end" ,
2788
+ replaceAll ? "replace_all('contribution[].*.agent.altLabel[].*', 't', '')" : "" ,
2789
+ replaceAll ? "replace_all('subject[].*.altLabel[].*', 't', '')" : ""
2790
+ ),
2791
+ i -> {
2792
+ i .startRecord ("1" );
2793
+ i .startEntity ("contribution[]" );
2794
+ i .startEntity ("1" );
2795
+ i .literal ("label" , "contribution" );
2796
+ i .endEntity ();
2797
+ i .endEntity ();
2798
+ i .startEntity ("subject[]" );
2799
+ i .startEntity ("1" );
2800
+ i .literal ("label" , "subject" );
2801
+ i .endEntity ();
2802
+ i .endEntity ();
2803
+ i .endRecord ();
2804
+ },
2805
+ (o , f ) -> {
2806
+ o .get ().startRecord ("1" );
2807
+ o .get ().startEntity ("contribution[]" );
2808
+ o .get ().startEntity ("1" );
2809
+ o .get ().literal ("label" , "contribution" );
2810
+ o .get ().startEntity ("agent" );
2811
+ o .get ().startEntity ("altLabel[]" );
2812
+ o .get ().literal ("1" , replaceAll ? "conribuion" : "contribution" );
2813
+ f .apply (4 ).endEntity ();
2814
+ o .get ().startEntity ("subject[]" );
2815
+ o .get ().startEntity ("1" );
2816
+ o .get ().literal ("label" , "subject" );
2817
+ o .get ().startEntity ("altLabel[]" );
2818
+ o .get ().literal ("1" , replaceAll ? "subjec" : "subject" );
2819
+ f .apply (3 ).endEntity ();
2820
+ o .get ().endRecord ();
2821
+ }
2822
+ );
2823
+ }
2824
+
2825
+ @ Test
2826
+ public void setArrayWithoutReplaceAll () {
2827
+ setArrayWithReplaceAll (false );
2828
+ }
2829
+
2830
+ @ Test
2831
+ public void setArrayWithReplaceAll () {
2832
+ setArrayWithReplaceAll (true );
2833
+ }
2834
+
2835
+ private void setArrayWithReplaceAll (final boolean replaceAll ) {
2836
+ MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
2837
+ "do list(path: 'contribution[]', 'var': '$i')" ,
2838
+ " set_array('$i.agent.altLabel[]', 'contribution')" ,
2839
+ "end" ,
2840
+ "do list(path: 'subject[]', 'var': '$i')" ,
2841
+ " set_array('$i.altLabel[]', 'subject')" ,
2842
+ "end" ,
2843
+ replaceAll ? "replace_all('contribution[].*.agent.altLabel[].*', 't', '')" : "" ,
2844
+ replaceAll ? "replace_all('subject[].*.altLabel[].*', 't', '')" : ""
2845
+ ),
2846
+ i -> {
2847
+ i .startRecord ("1" );
2848
+ i .startEntity ("contribution[]" );
2849
+ i .startEntity ("1" );
2850
+ i .literal ("label" , "contribution" );
2851
+ i .endEntity ();
2852
+ i .endEntity ();
2853
+ i .startEntity ("subject[]" );
2854
+ i .startEntity ("1" );
2855
+ i .literal ("label" , "subject" );
2856
+ i .endEntity ();
2857
+ i .endEntity ();
2858
+ i .endRecord ();
2859
+ },
2860
+ (o , f ) -> {
2861
+ o .get ().startRecord ("1" );
2862
+ o .get ().startEntity ("contribution[]" );
2863
+ o .get ().startEntity ("1" );
2864
+ o .get ().literal ("label" , "contribution" );
2865
+ o .get ().startEntity ("agent" );
2866
+ o .get ().startEntity ("altLabel[]" );
2867
+ o .get ().literal ("1" , replaceAll ? "conribuion" : "contribution" );
2868
+ f .apply (4 ).endEntity ();
2869
+ o .get ().startEntity ("subject[]" );
2870
+ o .get ().startEntity ("1" );
2871
+ o .get ().literal ("label" , "subject" );
2872
+ o .get ().startEntity ("altLabel[]" );
2873
+ o .get ().literal ("1" , replaceAll ? "subjec" : "subject" );
2874
+ f .apply (3 ).endEntity ();
2875
+ o .get ().endRecord ();
2876
+ }
2877
+ );
2878
+ }
2879
+
2880
+ @ Test
2881
+ public void copyFieldWithoutReplaceAllArray () {
2882
+ copyFieldWithReplaceAllArray (false );
2883
+ }
2884
+
2885
+ @ Test
2886
+ public void copyFieldWithReplaceAllArray () {
2887
+ copyFieldWithReplaceAllArray (true );
2888
+ }
2889
+
2890
+ private void copyFieldWithReplaceAllArray (final boolean replaceAll ) {
2891
+ MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
2892
+ "do list(path: 'contribution[]', 'var': '$i')" ,
2893
+ " set_array('$i.agent.altLabel[]')" ,
2894
+ " copy_field('$i.label', '$i.agent.altLabel[].$append')" ,
2895
+ "end" ,
2896
+ "do list(path: 'subject[]', 'var': '$i')" ,
2897
+ " set_array('$i.altLabel[]')" ,
2898
+ " copy_field('$i.label', '$i.altLabel[].$append')" ,
2899
+ "end" ,
2900
+ replaceAll ? "replace_all('contribution[].*.agent.altLabel[].*', 't', '')" : "" ,
2901
+ replaceAll ? "replace_all('subject[].*.altLabel[].*', 't', '')" : ""
2902
+ ),
2903
+ i -> {
2904
+ i .startRecord ("1" );
2905
+ i .startEntity ("contribution[]" );
2906
+ i .startEntity ("1" );
2907
+ i .literal ("label" , "contribution" );
2908
+ i .endEntity ();
2909
+ i .endEntity ();
2910
+ i .startEntity ("subject[]" );
2911
+ i .startEntity ("1" );
2912
+ i .literal ("label" , "subject" );
2913
+ i .endEntity ();
2914
+ i .endEntity ();
2915
+ i .endRecord ();
2916
+ },
2917
+ (o , f ) -> {
2918
+ o .get ().startRecord ("1" );
2919
+ o .get ().startEntity ("contribution[]" );
2920
+ o .get ().startEntity ("1" );
2921
+ o .get ().literal ("label" , "contribution" );
2922
+ o .get ().startEntity ("agent" );
2923
+ o .get ().startEntity ("altLabel[]" );
2924
+ o .get ().literal ("1" , replaceAll ? "conribuion" : "contribution" );
2925
+ f .apply (4 ).endEntity ();
2926
+ o .get ().startEntity ("subject[]" );
2927
+ o .get ().startEntity ("1" );
2928
+ o .get ().literal ("label" , "subject" );
2929
+ o .get ().startEntity ("altLabel[]" );
2930
+ o .get ().literal ("1" , replaceAll ? "subjec" : "subject" );
2931
+ f .apply (3 ).endEntity ();
2932
+ o .get ().endRecord ();
2933
+ }
2934
+ );
2935
+ }
2936
+
2937
+ @ Test
2938
+ public void pasteWithoutReplaceAll () {
2939
+ pasteWithReplaceAll (false );
2940
+ }
2941
+
2942
+ @ Test
2943
+ public void pasteWithReplaceAll () {
2944
+ pasteWithReplaceAll (true );
2945
+ }
2946
+
2947
+ private void pasteWithReplaceAll (final boolean replaceAll ) {
2948
+ MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
2949
+ "do list(path: 'contribution[]', 'var': '$i')" ,
2950
+ " set_array('$i.agent.altLabel[]')" ,
2951
+ " paste('$i.agent.altLabel[].$append', '$i.label', '~!')" ,
2952
+ "end" ,
2953
+ "do list(path: 'subject[]', 'var': '$i')" ,
2954
+ " set_array('$i.altLabel[]')" ,
2955
+ " paste('$i.altLabel[].$append', '$i.label', '~!')" ,
2956
+ "end" ,
2957
+ replaceAll ? "replace_all('contribution[].*.agent.altLabel[].*', ' !', '')" : "" ,
2958
+ replaceAll ? "replace_all('subject[].*.altLabel[].*', ' !', '')" : ""
2959
+ ),
2960
+ i -> {
2961
+ i .startRecord ("1" );
2962
+ i .startEntity ("contribution[]" );
2963
+ i .startEntity ("1" );
2964
+ i .literal ("label" , "contribution" );
2965
+ i .endEntity ();
2966
+ i .endEntity ();
2967
+ i .startEntity ("subject[]" );
2968
+ i .startEntity ("1" );
2969
+ i .literal ("label" , "subject" );
2970
+ i .endEntity ();
2971
+ i .endEntity ();
2972
+ i .endRecord ();
2973
+ },
2974
+ (o , f ) -> {
2975
+ o .get ().startRecord ("1" );
2976
+ o .get ().startEntity ("contribution[]" );
2977
+ o .get ().startEntity ("1" );
2978
+ o .get ().literal ("label" , "contribution" );
2979
+ o .get ().startEntity ("agent" );
2980
+ o .get ().startEntity ("altLabel[]" );
2981
+ o .get ().literal ("1" , replaceAll ? "contribution" : "contribution !" );
2982
+ f .apply (4 ).endEntity ();
2983
+ o .get ().startEntity ("subject[]" );
2984
+ o .get ().startEntity ("1" );
2985
+ o .get ().literal ("label" , "subject" );
2986
+ o .get ().startEntity ("altLabel[]" );
2987
+ o .get ().literal ("1" , replaceAll ? "subject" : "subject !" );
2988
+ f .apply (3 ).endEntity ();
2989
+ o .get ().endRecord ();
2990
+ }
2991
+ );
2992
+ }
2993
+
2715
2994
@ Test
2716
2995
public void shouldReplaceAllRegexesInArrayByIndex () {
2717
2996
MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
0 commit comments