diff --git a/src/zcl_abapgit_news.clas.testclasses.abap b/src/zcl_abapgit_news.clas.testclasses.abap index a807ec8db..982dcd984 100644 --- a/src/zcl_abapgit_news.clas.testclasses.abap +++ b/src/zcl_abapgit_news.clas.testclasses.abap @@ -53,6 +53,55 @@ CLASS ltcl_relevant IMPLEMENTATION. ENDCLASS. +********************************************************************** +* Helper classed + +CLASS lcl_string_buffer DEFINITION FINAL. + PUBLIC SECTION. + DATA mt_buffer TYPE string_table. + METHODS add + IMPORTING + iv_str TYPE string. +ENDCLASS. + +CLASS lcl_string_buffer IMPLEMENTATION. + METHOD add. + APPEND iv_str TO mt_buffer. + ENDMETHOD. +ENDCLASS. + +CLASS lcl_log_entries DEFINITION FINAL. + PUBLIC SECTION. + DATA mt_log_entries TYPE zcl_abapgit_news=>tt_log. + METHODS add + IMPORTING + iv_str TYPE string. +ENDCLASS. + +CLASS lcl_log_entries IMPLEMENTATION. + METHOD add. + DATA ls_log LIKE LINE OF mt_log_entries. + DATA lv_pos_to_cur_str TYPE string. + + SPLIT iv_str AT '/' INTO + ls_log-version + ls_log-is_header + ls_log-is_important + lv_pos_to_cur_str + ls_log-text. + + CONDENSE ls_log-version. + CONDENSE ls_log-is_header. + CONDENSE ls_log-is_important. + CONDENSE ls_log-text. + ls_log-pos_to_cur = lv_pos_to_cur_str. + + APPEND ls_log TO mt_log_entries. + ENDMETHOD. +ENDCLASS. + +********************************************************************** + CLASS ltcl_news DEFINITION DEFERRED. CLASS zcl_abapgit_news DEFINITION LOCAL FRIENDS ltcl_news. @@ -204,83 +253,77 @@ CLASS ltcl_news IMPLEMENTATION. METHOD parse. - DEFINE _add_news_log_entry. - CLEAR: ls_log. - ls_log-version = &1. - ls_log-is_header = &2. - ls_log-is_important = &3. - ls_log-pos_to_cur = &4. - ls_log-text = &5. - APPEND ls_log TO lt_log_exp. - END-OF-DEFINITION. - - DEFINE _add_news_txt_entry. - APPEND &1 TO lt_lines. - END-OF-DEFINITION. - - DATA: lt_log_exp TYPE zcl_abapgit_news=>tt_log, - lt_log_act TYPE zcl_abapgit_news=>tt_log, - ls_log LIKE LINE OF lt_log_exp, - lt_lines TYPE string_table. + DATA lt_log_act TYPE zcl_abapgit_news=>tt_log. + DATA lo_src_text_buf TYPE REF TO lcl_string_buffer. + DATA lo_log_entries TYPE REF TO lcl_log_entries. " Generate test data - _add_news_txt_entry '======'. - _add_news_txt_entry '------'. - _add_news_txt_entry ` `. - _add_news_txt_entry 'abapGit changelog'. - _add_news_txt_entry '2017-02-13 v1.28.0'. - _add_news_txt_entry '------------------'. - _add_news_txt_entry '+ Staging page redesigned'. - _add_news_txt_entry '! Support for core data services'. - _add_news_txt_entry ` `. - _add_news_txt_entry '2017-01-25 v1.27.0'. - _add_news_txt_entry '------------------'. - _add_news_txt_entry '+ Two factor authentication with github.com'. - _add_news_txt_entry '2017-01-25 v1.26.0'. + CREATE OBJECT lo_src_text_buf. + lo_src_text_buf->add( '======' ). + lo_src_text_buf->add( '------' ). + lo_src_text_buf->add( ` ` ). + lo_src_text_buf->add( 'abapGit changelog' ). + lo_src_text_buf->add( '2017-02-13 v1.28.0' ). + lo_src_text_buf->add( '------------------' ). + lo_src_text_buf->add( '+ Staging page redesigned' ). + lo_src_text_buf->add( '! Support for core data services' ). + lo_src_text_buf->add( ` ` ). + lo_src_text_buf->add( '2017-01-25 v1.27.0' ). + lo_src_text_buf->add( '------------------' ). + lo_src_text_buf->add( '+ Two factor authentication with github.com' ). + lo_src_text_buf->add( '2017-01-25 v1.26.0' ). " Case 1 " Generate expected results - " VERSION HEAD IMP POS TEXT - _add_news_log_entry '1.28.0' 'X' '' 1 '2017-02-13 v1.28.0'. - _add_news_log_entry '1.28.0' '' '' 0 '+ Staging page redesigned'. - _add_news_log_entry '1.28.0' '' 'X' 0 '! Support for core data services'. - _add_news_log_entry '1.27.0' 'X' '' 1 '2017-01-25 v1.27.0'. - _add_news_log_entry '1.27.0' '' '' 0 '+ Two factor authentication with github.com'. + CREATE OBJECT lo_log_entries. + " VERSION HEAD IMP POS TEXT + lo_log_entries->add( '1.28.0 /X / /1 /2017-02-13 v1.28.0' ). + lo_log_entries->add( '1.28.0 / / /0 /+ Staging page redesigned' ). + lo_log_entries->add( '1.28.0 / /X /0 /! Support for core data services' ). + lo_log_entries->add( '1.27.0 /X / /1 /2017-01-25 v1.27.0' ). + lo_log_entries->add( '1.27.0 / / /0 /+ Two factor authentication with github.com' ). - lt_log_act = zcl_abapgit_news=>parse( it_lines = lt_lines iv_current_version = '1.26.01' ). - cl_abap_unit_assert=>assert_equals( exp = lt_log_exp - act = lt_log_act - msg = ' Error during parsing: Case 1.' ). + lt_log_act = zcl_abapgit_news=>parse( + it_lines = lo_src_text_buf->mt_buffer + iv_current_version = '1.26.01' ). + cl_abap_unit_assert=>assert_equals( + exp = lo_log_entries->mt_log_entries + act = lt_log_act + msg = ' Error during parsing: Case 1.' ). " Case 2 (exect version match) - CLEAR lt_log_exp. + CREATE OBJECT lo_log_entries. " VERSION HEAD IMP UPD TEXT - _add_news_log_entry '1.28.0' 'X' '' 1 '2017-02-13 v1.28.0'. - _add_news_log_entry '1.28.0' '' '' 0 '+ Staging page redesigned'. - _add_news_log_entry '1.28.0' '' 'X' 0 '! Support for core data services'. + lo_log_entries->add( '1.28.0 /X / /1 /2017-02-13 v1.28.0' ). + lo_log_entries->add( '1.28.0 / / /0 /+ Staging page redesigned' ). + lo_log_entries->add( '1.28.0 / /X /0 /! Support for core data services' ). - " Case 1: Test parsing of data - lt_log_act = zcl_abapgit_news=>parse( it_lines = lt_lines iv_current_version = '1.27.00' ). - cl_abap_unit_assert=>assert_equals( exp = lt_log_exp - act = lt_log_act - msg = ' Error during parsing: Case 2.' ). + lt_log_act = zcl_abapgit_news=>parse( + it_lines = lo_src_text_buf->mt_buffer + iv_current_version = '1.27.00' ). + cl_abap_unit_assert=>assert_equals( + exp = lo_log_entries->mt_log_entries + act = lt_log_act + msg = ' Error during parsing: Case 2.' ). " Case 3 (display tail) - CLEAR lt_log_exp. + CREATE OBJECT lo_log_entries. " VERSION HEAD IMP UPD TEXT - _add_news_log_entry '1.28.0' 'X' '' 0 '2017-02-13 v1.28.0'. - _add_news_log_entry '1.28.0' '' '' 0 '+ Staging page redesigned'. - _add_news_log_entry '1.28.0' '' 'X' 0 '! Support for core data services'. - _add_news_log_entry '1.27.0' 'X' '' -1 '2017-01-25 v1.27.0'. - _add_news_log_entry '1.27.0' '' '' 0 '+ Two factor authentication with github.com'. - _add_news_log_entry '1.26.0' 'X' '' -1 '2017-01-25 v1.26.0'. + lo_log_entries->add( '1.28.0 /X / /0 /2017-02-13 v1.28.0' ). + lo_log_entries->add( '1.28.0 / / /0 /+ Staging page redesigned' ). + lo_log_entries->add( '1.28.0 / /X /0 /! Support for core data services' ). + lo_log_entries->add( '1.27.0 /X / /-1 /2017-01-25 v1.27.0' ). + lo_log_entries->add( '1.27.0 / / /0 /+ Two factor authentication with github.com' ). + lo_log_entries->add( '1.26.0 /X / /-1 /2017-01-25 v1.26.0' ). - " Case 1: Test parsing of data - lt_log_act = zcl_abapgit_news=>parse( it_lines = lt_lines iv_current_version = '1.28.00' ). - cl_abap_unit_assert=>assert_equals( exp = lt_log_exp - act = lt_log_act - msg = ' Error during parsing: Case 3.' ). + lt_log_act = zcl_abapgit_news=>parse( + it_lines = lo_src_text_buf->mt_buffer + iv_current_version = '1.28.00' ). + cl_abap_unit_assert=>assert_equals( + exp = lo_log_entries->mt_log_entries + act = lt_log_act + msg = ' Error during parsing: Case 3.' ). ENDMETHOD.