From 6f8a136cde5706486dfba808e6ca55057d0fea28 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 26 Feb 2024 06:32:32 +0100 Subject: [PATCH] ajson, Automatic Update (#6827) Co-authored-by: larshp Co-authored-by: Lars Hvam --- src/json/zcl_abapgit_ajson.clas.abap | 8 +++-- .../zcl_abapgit_ajson.clas.testclasses.abap | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/json/zcl_abapgit_ajson.clas.abap b/src/json/zcl_abapgit_ajson.clas.abap index ec1bfb80ed..d59af1358a 100644 --- a/src/json/zcl_abapgit_ajson.clas.abap +++ b/src/json/zcl_abapgit_ajson.clas.abap @@ -924,8 +924,12 @@ CLASS zcl_abapgit_ajson IMPLEMENTATION. ls_new_node-name = ls_split_path-name. ls_new_node-type = zif_abapgit_ajson_types=>node_type-array. - IF ms_opts-keep_item_order = abap_true AND ls_deleted_node IS NOT INITIAL. - ls_new_node-order = ls_deleted_node-order. + IF ms_opts-keep_item_order = abap_true. + IF ls_deleted_node IS NOT INITIAL. + ls_new_node-order = ls_deleted_node-order. + ELSE. + ls_new_node-order = lr_parent->children. + ENDIF. ENDIF. INSERT ls_new_node INTO TABLE mt_json_tree. diff --git a/src/json/zcl_abapgit_ajson.clas.testclasses.abap b/src/json/zcl_abapgit_ajson.clas.testclasses.abap index df950ce5e0..611f68d5bd 100644 --- a/src/json/zcl_abapgit_ajson.clas.testclasses.abap +++ b/src/json/zcl_abapgit_ajson.clas.testclasses.abap @@ -2198,6 +2198,7 @@ CLASS ltcl_writer_test DEFINITION FINAL METHODS read_only FOR TESTING RAISING zcx_abapgit_ajson_error. METHODS set_array_obj FOR TESTING RAISING zcx_abapgit_ajson_error. METHODS set_with_type FOR TESTING RAISING zcx_abapgit_ajson_error. + METHODS new_array_w_keep_order_touch FOR TESTING RAISING zcx_abapgit_ajson_error. METHODS overwrite_w_keep_order_touch FOR TESTING RAISING zcx_abapgit_ajson_error. METHODS overwrite_w_keep_order_set FOR TESTING RAISING zcx_abapgit_ajson_error. METHODS setx FOR TESTING RAISING zcx_abapgit_ajson_error. @@ -3271,6 +3272,37 @@ CLASS ltcl_writer_test IMPLEMENTATION. ENDMETHOD. + METHOD new_array_w_keep_order_touch. + + DATA li_cut TYPE REF TO zif_abapgit_ajson. + + " default order adds new arrays at beginning of node (pos 0) + li_cut = zcl_abapgit_ajson=>create_empty( + )->set( + iv_path = '/b' + iv_val = 1 ). + + li_cut->touch_array( '/a' ). + + cl_abap_unit_assert=>assert_equals( + act = li_cut->stringify( ) + exp = '{"a":[],"b":1}' ). + + " with keep order, new array is created at end of node + li_cut = zcl_abapgit_ajson=>create_empty( + )->keep_item_order( + )->set( + iv_path = '/b' + iv_val = 1 ). + + li_cut->touch_array( '/a' ). + + cl_abap_unit_assert=>assert_equals( + act = li_cut->stringify( ) + exp = '{"b":1,"a":[]}' ). + + ENDMETHOD. + METHOD overwrite_w_keep_order_touch. DATA li_cut TYPE REF TO zif_abapgit_ajson.