Skip to content

Commit

Permalink
bugfix, xml pretty print (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
larshp authored Oct 16, 2023
1 parent 0009c6e commit 1cb7989
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"license": "MIT",
"dependencies": {
"@abaplint/cli": "^2.102.58",
"@abaplint/runtime": "^2.7.105",
"@abaplint/runtime": "^2.7.114",
"@abaplint/database-sqlite": "^2.7.101",
"@abaplint/transpiler-cli": "^2.7.105"
"@abaplint/transpiler-cli": "^2.7.114"
}
}
5 changes: 1 addition & 4 deletions src/ixml/cl_ixml.clas.locals_imp.abap
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ CLASS lcl_node IMPLEMENTATION.
IF li_children->get_length( ) > 0 OR mv_value IS NOT INITIAL.
ostream->write_string( lcl_escape=>escape_value( mv_value ) ).
IF mv_name <> '#text'.
IF ostream->get_pretty_print( ) = abap_true AND if_ixml_node~get_depth( ) > 1.
IF ostream->get_pretty_print( ) = abap_true AND has_direct_text( ) = abap_false.
ostream->write_string( repeat( val = | | occ = ostream->get_indent( ) ) ).
ENDIF.
ostream->write_string( '</' && lv_ns && mv_name && '>' ).
Expand All @@ -445,12 +445,9 @@ CLASS lcl_node IMPLEMENTATION.
ENDIF.

IF ostream->get_pretty_print( ) = abap_true AND mv_name <> '#text'.
WRITE / 'new line2'.
ostream->write_string( |\n| ).
ENDIF.

WRITE / 'endnode'.

ENDMETHOD.

METHOD if_ixml_element~set_attribute_node_ns.
Expand Down
38 changes: 38 additions & 0 deletions src/ixml/cl_ixml.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ CLASS ltcl_xml DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT FINAL.
METHODS pretty1 FOR TESTING RAISING cx_static_check.
METHODS pretty2 FOR TESTING RAISING cx_static_check.
METHODS pretty3 FOR TESTING RAISING cx_static_check.
METHODS pretty4 FOR TESTING RAISING cx_static_check.
METHODS pretty5 FOR TESTING RAISING cx_static_check.

DATA mi_ixml TYPE REF TO if_ixml.
DATA mi_document TYPE REF TO if_ixml_document.
Expand Down Expand Up @@ -1058,4 +1060,40 @@ CLASS ltcl_xml IMPLEMENTATION.

ENDMETHOD.

METHOD pretty4.

DATA: lv_xstring TYPE xstring,
lv_actual TYPE string,
lv_expected TYPE string.


parse( |<foo><bar></bar><moo></moo></foo>| ).

lv_actual = pretty_print( ).
lv_expected = |<?xml version="1.0" encoding="utf-8"?>\n<foo>\n <bar/>\n <moo/>\n</foo>\n|.

cl_abap_unit_assert=>assert_equals(
act = lv_actual
exp = lv_expected ).

ENDMETHOD.

METHOD pretty5.

DATA: lv_xstring TYPE xstring,
lv_actual TYPE string,
lv_expected TYPE string.


parse( |<top><foo><bar></bar><moo></moo></foo></top>| ).

lv_actual = pretty_print( ).
lv_expected = |<?xml version="1.0" encoding="utf-8"?>\n<top>\n <foo>\n <bar/>\n <moo/>\n </foo>\n</top>\n|.

cl_abap_unit_assert=>assert_equals(
act = lv_actual
exp = lv_expected ).

ENDMETHOD.

ENDCLASS.
2 changes: 2 additions & 0 deletions src/json/#ui2#cl_json.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ CLASS /ui2/cl_json IMPLEMENTATION.

IF jsonx IS NOT INITIAL.
mo_parsed->parse( cl_abap_codepage=>convert_from( jsonx ) ).
ELSEIF json IS INITIAL.
RETURN.
ELSE.
mo_parsed->parse( json ).
ENDIF.
Expand Down
4 changes: 2 additions & 2 deletions src/json/#ui2#cl_json.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ CLASS ltcl_deserialize IMPLEMENTATION.
json = ''
assoc_arrays = abap_true
CHANGING
data = ref ).
data = ref ).
cl_abap_unit_assert=>assert_initial( ref ).
ENDMETHOD.

Expand All @@ -318,7 +318,7 @@ CLASS ltcl_deserialize IMPLEMENTATION.
json = '2'
assoc_arrays = abap_true
CHANGING
data = ref ).
data = ref ).
cl_abap_unit_assert=>assert_initial( ref ).
ENDMETHOD.

Expand Down
6 changes: 3 additions & 3 deletions src/rtti/cl_abap_objectdescr.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CLASS cl_abap_objectdescr IMPLEMENTATION.
FIELD-SYMBOLS <ptype> LIKE LINE OF mt_parameter_types.

* set attributes
WRITE '@KERNEL for (const a in p_object.ATTRIBUTES || []) {'.
WRITE '@KERNEL for (const a in p_object?.ATTRIBUTES || []) {'.
WRITE '@KERNEL lv_name.set(a);'.
APPEND INITIAL LINE TO attributes ASSIGNING <attr>.
APPEND INITIAL LINE TO mt_attribute_types ASSIGNING <atype>.
Expand All @@ -99,15 +99,15 @@ CLASS cl_abap_objectdescr IMPLEMENTATION.
SORT attributes BY is_interface DESCENDING name ASCENDING.

* set interfaces
WRITE '@KERNEL for (const a of p_object.IMPLEMENTED_INTERFACES || []) {'.
WRITE '@KERNEL for (const a of p_object?.IMPLEMENTED_INTERFACES || []) {'.
WRITE '@KERNEL lv_name.set(a);'.
APPEND INITIAL LINE TO interfaces ASSIGNING <intf>.
<intf>-name = lv_name.
WRITE '@KERNEL }'.
SORT interfaces BY name ASCENDING.

* set methods
WRITE '@KERNEL for (const a in p_object.METHODS || []) {'.
WRITE '@KERNEL for (const a in p_object?.METHODS || []) {'.
WRITE '@KERNEL lv_name.set(a);'.
APPEND INITIAL LINE TO methods ASSIGNING <method>.
<method>-name = lv_name.
Expand Down

0 comments on commit 1cb7989

Please sign in to comment.