mirror of
https://github.com/abapGit/abapGit.git
synced 2025-05-01 12:20:51 +08:00
class ZCL_ABAPGIT_XML_PRETTY add unit tests (#4263)
* class ZCL_ABAPGIT_XML_PRETTY add unit tests closes #4260 * Update zcl_abapgit_xml_pretty.clas.testclasses.abap * fix for byte order mark
This commit is contained in:
parent
abaac4ab9b
commit
f782190b3a
|
@ -3,13 +3,18 @@ CLASS zcl_abapgit_xml_pretty DEFINITION
|
||||||
CREATE PUBLIC .
|
CREATE PUBLIC .
|
||||||
|
|
||||||
PUBLIC SECTION.
|
PUBLIC SECTION.
|
||||||
CLASS-METHODS: print
|
|
||||||
IMPORTING iv_xml TYPE string
|
|
||||||
iv_ignore_errors TYPE abap_bool DEFAULT abap_true
|
|
||||||
iv_unpretty TYPE abap_bool DEFAULT abap_false
|
|
||||||
RETURNING VALUE(rv_xml) TYPE string
|
|
||||||
RAISING zcx_abapgit_exception.
|
|
||||||
|
|
||||||
|
CLASS-METHODS print
|
||||||
|
IMPORTING
|
||||||
|
!iv_xml TYPE string
|
||||||
|
!iv_ignore_errors TYPE abap_bool DEFAULT abap_true
|
||||||
|
!iv_unpretty TYPE abap_bool DEFAULT abap_false
|
||||||
|
RETURNING
|
||||||
|
VALUE(rv_xml) TYPE string
|
||||||
|
RAISING
|
||||||
|
zcx_abapgit_exception .
|
||||||
|
PROTECTED SECTION.
|
||||||
|
PRIVATE SECTION.
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|
||||||
|
|
||||||
|
|
108
src/xml/zcl_abapgit_xml_pretty.clas.testclasses.abap
Normal file
108
src/xml/zcl_abapgit_xml_pretty.clas.testclasses.abap
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
|
||||||
|
CLASS ltcl_test DEFINITION FOR TESTING
|
||||||
|
DURATION SHORT
|
||||||
|
RISK LEVEL HARMLESS.
|
||||||
|
|
||||||
|
PRIVATE SECTION.
|
||||||
|
DATA:
|
||||||
|
mo_cut TYPE REF TO zcl_abapgit_xml_pretty.
|
||||||
|
|
||||||
|
METHODS:
|
||||||
|
setup,
|
||||||
|
pretty1 FOR TESTING RAISING cx_static_check,
|
||||||
|
pretty2 FOR TESTING RAISING cx_static_check,
|
||||||
|
pretty3 FOR TESTING RAISING cx_static_check,
|
||||||
|
malformatted FOR TESTING RAISING cx_static_check,
|
||||||
|
dont_ignore_error FOR TESTING RAISING cx_static_check,
|
||||||
|
unpretty FOR TESTING RAISING cx_static_check.
|
||||||
|
|
||||||
|
ENDCLASS.
|
||||||
|
|
||||||
|
|
||||||
|
CLASS ltcl_test IMPLEMENTATION.
|
||||||
|
|
||||||
|
METHOD setup.
|
||||||
|
CREATE OBJECT mo_cut.
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD pretty1.
|
||||||
|
|
||||||
|
DATA lv_result TYPE string.
|
||||||
|
|
||||||
|
lv_result = mo_cut->print( '<foo></foo>' ).
|
||||||
|
lv_result = lv_result+1.
|
||||||
|
|
||||||
|
cl_abap_unit_assert=>assert_equals(
|
||||||
|
act = lv_result
|
||||||
|
exp = |<?xml version="1.0" encoding="utf-16"?>\n<foo/>\n| ).
|
||||||
|
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD pretty2.
|
||||||
|
|
||||||
|
DATA lv_result TYPE string.
|
||||||
|
|
||||||
|
lv_result = mo_cut->print( '<foo>2</foo>' ).
|
||||||
|
lv_result = lv_result+1.
|
||||||
|
|
||||||
|
cl_abap_unit_assert=>assert_equals(
|
||||||
|
act = lv_result
|
||||||
|
exp = |<?xml version="1.0" encoding="utf-16"?>\n<foo>2</foo>\n| ).
|
||||||
|
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD pretty3.
|
||||||
|
|
||||||
|
DATA lv_result TYPE string.
|
||||||
|
|
||||||
|
lv_result = mo_cut->print( '<foo><bar>2</bar></foo>' ).
|
||||||
|
lv_result = lv_result+1.
|
||||||
|
|
||||||
|
cl_abap_unit_assert=>assert_equals(
|
||||||
|
act = lv_result
|
||||||
|
exp = |<?xml version="1.0" encoding="utf-16"?>\n<foo>\n <bar>2</bar>\n</foo>\n| ).
|
||||||
|
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD malformatted.
|
||||||
|
|
||||||
|
DATA lv_result TYPE string.
|
||||||
|
|
||||||
|
lv_result = mo_cut->print( 'abc' ).
|
||||||
|
|
||||||
|
cl_abap_unit_assert=>assert_equals(
|
||||||
|
act = lv_result
|
||||||
|
exp = 'abc' ).
|
||||||
|
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD dont_ignore_error.
|
||||||
|
|
||||||
|
TRY.
|
||||||
|
mo_cut->print(
|
||||||
|
iv_xml = 'abc'
|
||||||
|
iv_ignore_errors = abap_false ).
|
||||||
|
cl_abap_unit_assert=>fail( ).
|
||||||
|
CATCH zcx_abapgit_exception.
|
||||||
|
RETURN.
|
||||||
|
ENDTRY.
|
||||||
|
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD unpretty.
|
||||||
|
|
||||||
|
DATA lv_result TYPE string.
|
||||||
|
|
||||||
|
lv_result = mo_cut->print(
|
||||||
|
iv_xml = |<foo>\n <bar>2</bar>\n</foo>|
|
||||||
|
iv_unpretty = abap_true ).
|
||||||
|
|
||||||
|
lv_result = lv_result+1.
|
||||||
|
|
||||||
|
cl_abap_unit_assert=>assert_equals(
|
||||||
|
act = lv_result
|
||||||
|
exp = |<?xml version="1.0" encoding="utf-16"?><foo><bar>2</bar></foo>| ).
|
||||||
|
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
ENDCLASS.
|
|
@ -10,6 +10,7 @@
|
||||||
<CLSCCINCL>X</CLSCCINCL>
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
<FIXPT>X</FIXPT>
|
<FIXPT>X</FIXPT>
|
||||||
<UNICODE>X</UNICODE>
|
<UNICODE>X</UNICODE>
|
||||||
|
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
|
||||||
</VSEOCLASS>
|
</VSEOCLASS>
|
||||||
</asx:values>
|
</asx:values>
|
||||||
</asx:abap>
|
</asx:abap>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user