Skip to content

Commit

Permalink
Automatic Update STRINGMAP (#63)
Browse files Browse the repository at this point in the history
Automatic update from mirror
https://github.com/Marc-Bernard-Tools/Mirror-STRINGMAP

Co-authored-by: mbtools <mbtools@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and mbtools authored Jul 23, 2023
1 parent 1e6cfe0 commit e1eb56c
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/stringmap/#mbtools#cl_string_map.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ CLASS /mbtools/cl_string_map DEFINITION
!io_string_map TYPE REF TO /mbtools/cl_string_map
RETURNING
VALUE(ro_instance) TYPE REF TO /mbtools/cl_string_map.
METHODS merge
IMPORTING
!io_string_map TYPE REF TO /mbtools/cl_string_map
RETURNING
VALUE(ro_instance) TYPE REF TO /mbtools/cl_string_map.

METHODS to_struc
CHANGING
Expand Down Expand Up @@ -339,6 +344,19 @@ CLASS /mbtools/cl_string_map IMPLEMENTATION.
ENDMETHOD.


METHOD merge.

FIELD-SYMBOLS <entry> LIKE LINE OF mt_entries.

LOOP AT io_string_map->mt_entries ASSIGNING <entry>.
set(
iv_key = <entry>-k
iv_val = <entry>-v ).
ENDLOOP.

ENDMETHOD.


METHOD set.

DATA ls_entry LIKE LINE OF mt_entries.
Expand Down
71 changes: 71 additions & 0 deletions src/stringmap/#mbtools#cl_string_map.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ CLASS ltcl_string_map DEFINITION
METHODS from_entries FOR TESTING.
METHODS from_string FOR TESTING.
METHODS from_map FOR TESTING.
METHODS merge FOR TESTING.

METHODS to_struc FOR TESTING.
METHODS to_string FOR TESTING.
Expand Down Expand Up @@ -767,4 +768,74 @@ CLASS ltcl_string_map IMPLEMENTATION.

ENDMETHOD.

METHOD merge.

DATA lo_src TYPE REF TO /mbtools/cl_string_map.
DATA lo_cut TYPE REF TO /mbtools/cl_string_map.

lo_cut = /mbtools/cl_string_map=>create( ).
lo_cut->set(
iv_key = 'a'
iv_val = '1' ).
lo_cut->set(
iv_key = 'b'
iv_val = '2' ).

lo_src = /mbtools/cl_string_map=>create( ).
lo_src->set(
iv_key = 'b'
iv_val = '20' ).
lo_src->set(
iv_key = 'c'
iv_val = '30' ).

lo_cut->merge( lo_src ).

cl_abap_unit_assert=>assert_equals(
act = lo_cut->size( )
exp = 3 ).
cl_abap_unit_assert=>assert_equals(
act = lo_cut->get( 'a' )
exp = '1' ).
cl_abap_unit_assert=>assert_equals(
act = lo_cut->get( 'b' )
exp = '20' ).
cl_abap_unit_assert=>assert_equals(
act = lo_cut->get( 'c' )
exp = '30' ).

" Case 2
lo_cut = /mbtools/cl_string_map=>create( iv_case_insensitive = abap_true ).
lo_cut->set(
iv_key = 'a'
iv_val = '1' ).
lo_cut->set(
iv_key = 'b'
iv_val = '2' ).

lo_src = /mbtools/cl_string_map=>create( ).
lo_src->set(
iv_key = 'B'
iv_val = '200' ).
lo_src->set(
iv_key = 'D'
iv_val = '400' ).

lo_cut->merge( lo_src ).

cl_abap_unit_assert=>assert_equals(
act = lo_cut->size( )
exp = 3 ).
cl_abap_unit_assert=>assert_equals(
act = lo_cut->get( 'a' )
exp = '1' ).
cl_abap_unit_assert=>assert_equals(
act = lo_cut->get( 'b' )
exp = '200' ).
cl_abap_unit_assert=>assert_equals(
act = lo_cut->get( 'd' )
exp = '400' ).

ENDMETHOD.

ENDCLASS.

0 comments on commit e1eb56c

Please sign in to comment.