@@ -2712,6 +2712,289 @@ 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
+ @ MetafixToDo ("See https://github.com/metafacture/metafacture-fix/issues/278" )
2775
+ public void addFieldWithReplaceAllArray () {
2776
+ addFieldWithReplaceAllArray (true );
2777
+ }
2778
+
2779
+ private void addFieldWithReplaceAllArray (final boolean replaceAll ) {
2780
+ MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
2781
+ "do list(path: 'contribution[]', 'var': '$i')" ,
2782
+ " set_array('$i.agent.altLabel[]')" ,
2783
+ " add_field('$i.agent.altLabel[].$append', 'contribution')" ,
2784
+ "end" ,
2785
+ "do list(path: 'subject[]', 'var': '$i')" ,
2786
+ " set_array('$i.altLabel[]')" ,
2787
+ " add_field('$i.altLabel[].$append', 'subject')" ,
2788
+ "end" ,
2789
+ replaceAll ? "replace_all('contribution[].*.agent.altLabel[].*', 't', '')" : "" ,
2790
+ replaceAll ? "replace_all('subject[].*.altLabel[].*', 't', '')" : ""
2791
+ ),
2792
+ i -> {
2793
+ i .startRecord ("1" );
2794
+ i .startEntity ("contribution[]" );
2795
+ i .startEntity ("1" );
2796
+ i .literal ("label" , "contribution" );
2797
+ i .endEntity ();
2798
+ i .endEntity ();
2799
+ i .startEntity ("subject[]" );
2800
+ i .startEntity ("1" );
2801
+ i .literal ("label" , "subject" );
2802
+ i .endEntity ();
2803
+ i .endEntity ();
2804
+ i .endRecord ();
2805
+ },
2806
+ (o , f ) -> {
2807
+ o .get ().startRecord ("1" );
2808
+ o .get ().startEntity ("contribution[]" );
2809
+ o .get ().startEntity ("1" );
2810
+ o .get ().literal ("label" , "contribution" );
2811
+ o .get ().startEntity ("agent" );
2812
+ o .get ().startEntity ("altLabel[]" );
2813
+ o .get ().literal ("1" , replaceAll ? "conribuion" : "contribution" );
2814
+ f .apply (4 ).endEntity ();
2815
+ o .get ().startEntity ("subject[]" );
2816
+ o .get ().startEntity ("1" );
2817
+ o .get ().literal ("label" , "subject" );
2818
+ o .get ().startEntity ("altLabel[]" );
2819
+ o .get ().literal ("1" , replaceAll ? "subjec" : "subject" );
2820
+ f .apply (3 ).endEntity ();
2821
+ o .get ().endRecord ();
2822
+ }
2823
+ );
2824
+ }
2825
+
2826
+ @ Test
2827
+ public void setArrayWithoutReplaceAll () {
2828
+ setArrayWithReplaceAll (false );
2829
+ }
2830
+
2831
+ @ Test
2832
+ @ MetafixToDo ("See https://github.com/metafacture/metafacture-fix/issues/278" )
2833
+ public void setArrayWithReplaceAll () {
2834
+ setArrayWithReplaceAll (true );
2835
+ }
2836
+
2837
+ private void setArrayWithReplaceAll (final boolean replaceAll ) {
2838
+ MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
2839
+ "do list(path: 'contribution[]', 'var': '$i')" ,
2840
+ " set_array('$i.agent.altLabel[]', 'contribution')" ,
2841
+ "end" ,
2842
+ "do list(path: 'subject[]', 'var': '$i')" ,
2843
+ " set_array('$i.altLabel[]', 'subject')" ,
2844
+ "end" ,
2845
+ replaceAll ? "replace_all('contribution[].*.agent.altLabel[].*', 't', '')" : "" ,
2846
+ replaceAll ? "replace_all('subject[].*.altLabel[].*', 't', '')" : ""
2847
+ ),
2848
+ i -> {
2849
+ i .startRecord ("1" );
2850
+ i .startEntity ("contribution[]" );
2851
+ i .startEntity ("1" );
2852
+ i .literal ("label" , "contribution" );
2853
+ i .endEntity ();
2854
+ i .endEntity ();
2855
+ i .startEntity ("subject[]" );
2856
+ i .startEntity ("1" );
2857
+ i .literal ("label" , "subject" );
2858
+ i .endEntity ();
2859
+ i .endEntity ();
2860
+ i .endRecord ();
2861
+ },
2862
+ (o , f ) -> {
2863
+ o .get ().startRecord ("1" );
2864
+ o .get ().startEntity ("contribution[]" );
2865
+ o .get ().startEntity ("1" );
2866
+ o .get ().literal ("label" , "contribution" );
2867
+ o .get ().startEntity ("agent" );
2868
+ o .get ().startEntity ("altLabel[]" );
2869
+ o .get ().literal ("1" , replaceAll ? "conribuion" : "contribution" );
2870
+ f .apply (4 ).endEntity ();
2871
+ o .get ().startEntity ("subject[]" );
2872
+ o .get ().startEntity ("1" );
2873
+ o .get ().literal ("label" , "subject" );
2874
+ o .get ().startEntity ("altLabel[]" );
2875
+ o .get ().literal ("1" , replaceAll ? "subjec" : "subject" );
2876
+ f .apply (3 ).endEntity ();
2877
+ o .get ().endRecord ();
2878
+ }
2879
+ );
2880
+ }
2881
+
2882
+ @ Test
2883
+ public void copyFieldWithoutReplaceAllArray () {
2884
+ copyFieldWithReplaceAllArray (false );
2885
+ }
2886
+
2887
+ @ Test
2888
+ @ MetafixToDo ("See https://github.com/metafacture/metafacture-fix/issues/278" )
2889
+ public void copyFieldWithReplaceAllArray () {
2890
+ copyFieldWithReplaceAllArray (true );
2891
+ }
2892
+
2893
+ private void copyFieldWithReplaceAllArray (final boolean replaceAll ) {
2894
+ MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
2895
+ "do list(path: 'contribution[]', 'var': '$i')" ,
2896
+ " set_array('$i.agent.altLabel[]')" ,
2897
+ " copy_field('$i.label', '$i.agent.altLabel[].$append')" ,
2898
+ "end" ,
2899
+ "do list(path: 'subject[]', 'var': '$i')" ,
2900
+ " set_array('$i.altLabel[]')" ,
2901
+ " copy_field('$i.label', '$i.altLabel[].$append')" ,
2902
+ "end" ,
2903
+ replaceAll ? "replace_all('contribution[].*.agent.altLabel[].*', 't', '')" : "" ,
2904
+ replaceAll ? "replace_all('subject[].*.altLabel[].*', 't', '')" : ""
2905
+ ),
2906
+ i -> {
2907
+ i .startRecord ("1" );
2908
+ i .startEntity ("contribution[]" );
2909
+ i .startEntity ("1" );
2910
+ i .literal ("label" , "contribution" );
2911
+ i .endEntity ();
2912
+ i .endEntity ();
2913
+ i .startEntity ("subject[]" );
2914
+ i .startEntity ("1" );
2915
+ i .literal ("label" , "subject" );
2916
+ i .endEntity ();
2917
+ i .endEntity ();
2918
+ i .endRecord ();
2919
+ },
2920
+ (o , f ) -> {
2921
+ o .get ().startRecord ("1" );
2922
+ o .get ().startEntity ("contribution[]" );
2923
+ o .get ().startEntity ("1" );
2924
+ o .get ().literal ("label" , "contribution" );
2925
+ o .get ().startEntity ("agent" );
2926
+ o .get ().startEntity ("altLabel[]" );
2927
+ o .get ().literal ("1" , replaceAll ? "conribuion" : "contribution" );
2928
+ f .apply (4 ).endEntity ();
2929
+ o .get ().startEntity ("subject[]" );
2930
+ o .get ().startEntity ("1" );
2931
+ o .get ().literal ("label" , "subject" );
2932
+ o .get ().startEntity ("altLabel[]" );
2933
+ o .get ().literal ("1" , replaceAll ? "subjec" : "subject" );
2934
+ f .apply (3 ).endEntity ();
2935
+ o .get ().endRecord ();
2936
+ }
2937
+ );
2938
+ }
2939
+
2940
+ @ Test
2941
+ public void pasteWithoutReplaceAll () {
2942
+ pasteWithReplaceAll (false );
2943
+ }
2944
+
2945
+ @ Test
2946
+ @ MetafixToDo ("See https://github.com/metafacture/metafacture-fix/issues/278" )
2947
+ public void pasteWithReplaceAll () {
2948
+ pasteWithReplaceAll (true );
2949
+ }
2950
+
2951
+ private void pasteWithReplaceAll (final boolean replaceAll ) {
2952
+ MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
2953
+ "do list(path: 'contribution[]', 'var': '$i')" ,
2954
+ " set_array('$i.agent.altLabel[]')" ,
2955
+ " paste('$i.agent.altLabel[].$append', '$i.label', '~!')" ,
2956
+ "end" ,
2957
+ "do list(path: 'subject[]', 'var': '$i')" ,
2958
+ " set_array('$i.altLabel[]')" ,
2959
+ " paste('$i.altLabel[].$append', '$i.label', '~!')" ,
2960
+ "end" ,
2961
+ replaceAll ? "replace_all('contribution[].*.agent.altLabel[].*', '!', '')" : "" ,
2962
+ replaceAll ? "replace_all('subject[].*.altLabel[].*', '!', '')" : ""
2963
+ ),
2964
+ i -> {
2965
+ i .startRecord ("1" );
2966
+ i .startEntity ("contribution[]" );
2967
+ i .startEntity ("1" );
2968
+ i .literal ("label" , "contribution" );
2969
+ i .endEntity ();
2970
+ i .endEntity ();
2971
+ i .startEntity ("subject[]" );
2972
+ i .startEntity ("1" );
2973
+ i .literal ("label" , "subject" );
2974
+ i .endEntity ();
2975
+ i .endEntity ();
2976
+ i .endRecord ();
2977
+ },
2978
+ (o , f ) -> {
2979
+ o .get ().startRecord ("1" );
2980
+ o .get ().startEntity ("contribution[]" );
2981
+ o .get ().startEntity ("1" );
2982
+ o .get ().literal ("label" , "contribution" );
2983
+ o .get ().startEntity ("agent" );
2984
+ o .get ().startEntity ("altLabel[]" );
2985
+ o .get ().literal ("1" , replaceAll ? "contribution" : "contribution !" );
2986
+ f .apply (4 ).endEntity ();
2987
+ o .get ().startEntity ("subject[]" );
2988
+ o .get ().startEntity ("1" );
2989
+ o .get ().literal ("label" , "subject" );
2990
+ o .get ().startEntity ("altLabel[]" );
2991
+ o .get ().literal ("1" , replaceAll ? "subject" : "subject !" );
2992
+ f .apply (3 ).endEntity ();
2993
+ o .get ().endRecord ();
2994
+ }
2995
+ );
2996
+ }
2997
+
2715
2998
@ Test
2716
2999
public void shouldReplaceAllRegexesInArrayByIndex () {
2717
3000
MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
0 commit comments