Merge branch 'main' into patch-invalid-filename

This commit is contained in:
Marc Bernard 2025-01-23 11:53:42 +01:00 committed by GitHub
commit 137d9d19c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 70 additions and 27 deletions

View File

@ -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.
FIELD-SYMBOLS:
<ls_old> LIKE LINE OF it_old,
<ls_new> LIKE LINE OF it_new.
<lv_old> LIKE LINE OF it_old,
<lv_new> LIKE LINE OF it_new.
LOOP AT it_old ASSIGNING <ls_old>.
LOOP AT it_old ASSIGNING <lv_old>.
CLEAR ls_diff.
ls_diff-old_num = sy-tabix.
ls_diff-old = <ls_old>.
READ TABLE it_new ASSIGNING <ls_new> INDEX sy-tabix.
ls_diff-old = <lv_old>.
READ TABLE it_new ASSIGNING <lv_new> INDEX sy-tabix.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ls_diff-new_num = sy-tabix.
ls_diff-new = <ls_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_old> <> <ls_new>.
IF strlen( condense( <ls_old> ) ) = 0 OR strlen( condense( <ls_new> ) ) = 0.
ls_diff-new = <lv_new>.
IF ( mv_compare_mode = 1 OR mv_compare_mode = 3 )
AND has_line_diff( iv_old = <lv_old>
iv_new = <lv_new> ) = abap_true.
ls_diff-result = zif_abapgit_definitions=>c_diff-update.
ELSEIF strlen( <ls_old> ) > 0 AND strlen( <ls_new> ) > 0.
lv_last_new = substring( val = <ls_new>
off = strlen( <ls_new> ) - 1 ).
lv_last_old = substring( val = <ls_old>
off = strlen( <ls_old> ) - 1 ).
IF lv_last_new = space OR lv_last_old = space.
ls_diff-result = zif_abapgit_definitions=>c_diff-update.
ENDIF.
ENDIF.
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.

View File

@ -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.` ).

View File

@ -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"},