ajson, Automatic Update (#6174)

This commit is contained in:
github-actions[bot] 2023-03-28 10:23:46 +02:00 committed by GitHub
parent 8ae35648e4
commit ba6e530627
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 12 deletions

View File

@ -826,24 +826,30 @@ CLASS zcl_abapgit_ajson IMPLEMENTATION.
DATA lv_normalized_path TYPE string.
DATA ls_path_parts TYPE zif_abapgit_ajson_types=>ty_path_name.
DATA lv_path_len TYPE i.
DATA lv_path_pattern TYPE string.
CREATE OBJECT lo_section.
lv_normalized_path = lcl_utils=>normalize_path( iv_path ).
lv_path_len = strlen( lv_normalized_path ).
ls_path_parts = lcl_utils=>split_path( lv_normalized_path ).
LOOP AT mt_json_tree INTO ls_item.
" TODO potentially improve performance due to sorted tree (all path started from same prefix go in a row)
IF strlen( ls_item-path ) >= lv_path_len
AND substring( val = ls_item-path
len = lv_path_len ) = lv_normalized_path.
ls_item-path = substring( val = ls_item-path
off = lv_path_len - 1 ). " less closing '/'
INSERT ls_item INTO TABLE lo_section->mt_json_tree.
ELSEIF ls_item-path = ls_path_parts-path AND ls_item-name = ls_path_parts-name.
CLEAR: ls_item-path, ls_item-name. " this becomes a new root
INSERT ls_item INTO TABLE lo_section->mt_json_tree.
ENDIF.
READ TABLE mt_json_tree INTO ls_item
WITH KEY path = ls_path_parts-path name = ls_path_parts-name.
IF sy-subrc <> 0.
RETURN.
ENDIF.
CLEAR: ls_item-path, ls_item-name. " this becomes a new root
INSERT ls_item INTO TABLE lo_section->mt_json_tree.
lv_path_pattern = lv_normalized_path && `*`.
LOOP AT mt_json_tree INTO ls_item WHERE path CP lv_path_pattern.
ls_item-path = substring( val = ls_item-path
off = lv_path_len - 1 ). " less closing '/'
INSERT ls_item INTO TABLE lo_section->mt_json_tree.
ENDLOOP.
ri_json = lo_section.

View File

@ -1361,6 +1361,9 @@ CLASS ltcl_json_to_abap DEFINITION
METHODS to_abap_array
FOR TESTING
RAISING zcx_abapgit_ajson_error.
METHODS to_abap_array_of_arrays_simple
FOR TESTING
RAISING zcx_abapgit_ajson_error.
METHODS to_abap_array_of_arrays
FOR TESTING
RAISING zcx_abapgit_ajson_error.
@ -1513,6 +1516,40 @@ CLASS ltcl_json_to_abap IMPLEMENTATION.
ENDMETHOD.
METHOD to_abap_array_of_arrays_simple.
DATA lo_cut TYPE REF TO lcl_json_to_abap.
DATA lt_mock TYPE TABLE OF string_table.
DATA lt_exp TYPE TABLE OF string_table.
DATA lt_tmp TYPE string_table.
DATA lo_nodes TYPE REF TO lcl_nodes_helper.
CREATE OBJECT lo_nodes.
lo_nodes->add( ' | |array | | ' ).
lo_nodes->add( '/ |1 |array | |1' ).
lo_nodes->add( '/ |2 |array | |2' ).
lo_nodes->add( '/1/ |1 |str |One |1' ).
lo_nodes->add( '/2/ |1 |str |Two |1' ).
CREATE OBJECT lo_cut.
lo_cut->to_abap(
EXPORTING
it_nodes = lo_nodes->sorted( )
CHANGING
c_container = lt_mock ).
APPEND 'One' TO lt_tmp.
APPEND lt_tmp TO lt_exp.
CLEAR lt_tmp.
APPEND 'Two' TO lt_tmp.
APPEND lt_tmp TO lt_exp.
cl_abap_unit_assert=>assert_equals(
act = lt_mock
exp = lt_exp ).
ENDMETHOD.
METHOD to_abap_array_of_arrays.
DATA lo_cut TYPE REF TO lcl_json_to_abap.