diff --git a/src/utils/zcl_abapgit_diff.clas.abap b/src/utils/zcl_abapgit_diff.clas.abap index a3319f1eb..b8e936abd 100644 --- a/src/utils/zcl_abapgit_diff.clas.abap +++ b/src/utils/zcl_abapgit_diff.clas.abap @@ -89,6 +89,12 @@ CLASS zcl_abapgit_diff DEFINITION VALUE(rt_diff) TYPE zif_abapgit_definitions=>ty_diffs_tt. METHODS calculate_stats. METHODS adjust_diff. + METHODS has_line_diff + IMPORTING + iv_old TYPE string + iv_new TYPE string + RETURNING + VALUE(rv_has_diff) TYPE abap_bool. ENDCLASS. @@ -262,43 +268,27 @@ CLASS zcl_abapgit_diff IMPLEMENTATION. METHOD compute_diff_extra. DATA: - lv_last_new TYPE c LENGTH 1, - lv_last_old TYPE c LENGTH 1, - ls_diff LIKE LINE OF rt_diff. + ls_diff LIKE LINE OF rt_diff. FIELD-SYMBOLS: - LIKE LINE OF it_old, - LIKE LINE OF it_new. + LIKE LINE OF it_old, + LIKE LINE OF it_new. - LOOP AT it_old ASSIGNING . + LOOP AT it_old ASSIGNING . CLEAR ls_diff. ls_diff-old_num = sy-tabix. - ls_diff-old = . - READ TABLE it_new ASSIGNING INDEX sy-tabix. + ls_diff-old = . + READ TABLE it_new ASSIGNING INDEX sy-tabix. IF sy-subrc <> 0. EXIT. ENDIF. ls_diff-new_num = sy-tabix. - ls_diff-new = . - " SAP function ignores lines that contain only whitespace so we compare directly - " Also check if one line has trailing space(s) - IF ( mv_compare_mode = 1 OR mv_compare_mode = 3 ) AND <> . + ls_diff-new = . - IF strlen( condense( ) ) = 0 OR strlen( condense( ) ) = 0. - - ls_diff-result = zif_abapgit_definitions=>c_diff-update. - - ELSEIF strlen( ) > 0 AND strlen( ) > 0. - - lv_last_new = substring( val = - off = strlen( ) - 1 ). - lv_last_old = substring( val = - off = strlen( ) - 1 ). - IF lv_last_new = space OR lv_last_old = space. - ls_diff-result = zif_abapgit_definitions=>c_diff-update. - ENDIF. - - ENDIF. + IF ( mv_compare_mode = 1 OR mv_compare_mode = 3 ) + AND has_line_diff( iv_old = + iv_new = ) = abap_true. + ls_diff-result = zif_abapgit_definitions=>c_diff-update. ENDIF. APPEND ls_diff TO rt_diff. ENDLOOP. @@ -575,4 +565,17 @@ CLASS zcl_abapgit_diff IMPLEMENTATION. SPLIT lv_old AT cl_abap_char_utilities=>newline INTO TABLE et_old. ENDMETHOD. + + + METHOD has_line_diff. + + " SAP function ignores lines that contain only whitespace so we compare directly + " Also check if length differs and implicitly if one line has trailing space(s) + rv_has_diff = boolc( iv_old <> iv_new + AND ( strlen( condense( iv_old ) ) = 0 + OR strlen( condense( iv_new ) ) = 0 + OR strlen( iv_old ) <> strlen( iv_new ) ) ). + + ENDMETHOD. + ENDCLASS. diff --git a/src/utils/zcl_abapgit_diff.clas.testclasses.abap b/src/utils/zcl_abapgit_diff.clas.testclasses.abap index 2746a78ae..a44c503c1 100644 --- a/src/utils/zcl_abapgit_diff.clas.testclasses.abap +++ b/src/utils/zcl_abapgit_diff.clas.testclasses.abap @@ -48,6 +48,8 @@ CLASS ltcl_diff DEFINITION FOR TESTING diff14 FOR TESTING RAISING zcx_abapgit_exception, diff15 FOR TESTING RAISING zcx_abapgit_exception, diff16 FOR TESTING RAISING zcx_abapgit_exception, + diff17 FOR TESTING RAISING zcx_abapgit_exception, + diff18 FOR TESTING RAISING zcx_abapgit_exception, map_beacons FOR TESTING RAISING zcx_abapgit_exception. ENDCLASS. @@ -609,6 +611,42 @@ CLASS ltcl_diff IMPLEMENTATION. ENDMETHOD. + METHOD diff17. + + " tab vs space + add_new( |*\tTest| ). + + add_old( `* Test` ). + + add_expected( iv_new_num = ' 1' + iv_new = |*\tTest| + iv_result = zif_abapgit_definitions=>c_diff-update + iv_old_num = ' 1' + iv_old = `* Test` ). + + test( ). + + ENDMETHOD. + + + METHOD diff18. + + " no diff + add_new( `* Test` ). + + add_old( `* Test` ). + + add_expected( iv_new_num = ' 1' + iv_new = `* Test` + iv_result = zif_abapgit_definitions=>c_diff-unchanged + iv_old_num = ' 1' + iv_old = `* Test` ). + + test( ). + + ENDMETHOD. + + METHOD map_beacons. add_new( `REPORT ztest_beacon.` ). diff --git a/test/abap_transpile.json b/test/abap_transpile.json index d62a3a1ab..5ebc942bc 100644 --- a/test/abap_transpile.json +++ b/test/abap_transpile.json @@ -164,6 +164,8 @@ {"object": "ZCL_ABAPGIT_DIFF", "class": "ltcl_diff", "method": "diff14", "note": "fm RS_CMP_COMPUTE_DELTA + Void type: RSWSOURCET"}, {"object": "ZCL_ABAPGIT_DIFF", "class": "ltcl_diff", "method": "diff15", "note": "fm RS_CMP_COMPUTE_DELTA + Void type: RSWSOURCET"}, {"object": "ZCL_ABAPGIT_DIFF", "class": "ltcl_diff", "method": "diff16", "note": "fm RS_CMP_COMPUTE_DELTA + Void type: RSWSOURCET"}, + {"object": "ZCL_ABAPGIT_DIFF", "class": "ltcl_diff", "method": "diff17", "note": "fm RS_CMP_COMPUTE_DELTA + Void type: RSWSOURCET"}, + {"object": "ZCL_ABAPGIT_DIFF", "class": "ltcl_diff", "method": "diff18", "note": "fm RS_CMP_COMPUTE_DELTA + Void type: RSWSOURCET"}, {"object": "ZCL_ABAPGIT_DIFF", "class": "ltcl_diff", "method": "map_beacons", "note": "fm RS_CMP_COMPUTE_DELTA + Void type: RSWSOURCET"}, {"object": "ZCL_ABAPGIT_USER_RECORD", "class": "ltcl_user_record", "method": "test_invalid_user", "note": "Void type: BAPIADDR3"},