All files / src/utils zcl_abapgit_path.clas.testclasses.abap

100% Statements 206/206
100% Branches 5/5
100% Functions 5/5
100% Lines 206/206

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 2071x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
 
CLASS ltcl_path DEFINITION FOR TESTING
  DURATION SHORT
  RISK LEVEL HARMLESS.
 
  PUBLIC SECTION.
    METHODS is_root FOR TESTING.
    METHODS split_file_location FOR TESTING.
    METHODS is_subdir FOR TESTING.
    METHODS change_dir FOR TESTING.
    METHODS get_filename_from_syspath FOR TESTING.
 
ENDCLASS.
 
 
CLASS ltcl_path IMPLEMENTATION.
 
  METHOD is_root.
 
    cl_abap_unit_assert=>assert_equals(
      exp = abap_true
      act = zcl_abapgit_path=>is_root( '/' ) ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = abap_false
      act = zcl_abapgit_path=>is_root( '' ) ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = abap_false
      act = zcl_abapgit_path=>is_root( 'somedir' ) ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = abap_false
      act = zcl_abapgit_path=>is_root( '/somedir' ) ).
 
  ENDMETHOD.
 
  METHOD split_file_location.
 
    DATA: lv_path TYPE string,
          lv_name TYPE string.
 
    zcl_abapgit_path=>split_file_location(
      EXPORTING iv_fullpath = ''
      IMPORTING ev_path     = lv_path ev_filename = lv_name ).
    cl_abap_unit_assert=>assert_equals( act = lv_path
                                        exp = '' ).
    cl_abap_unit_assert=>assert_equals( act = lv_name
                                        exp = '' ).
 
    zcl_abapgit_path=>split_file_location(
      EXPORTING iv_fullpath = 'somefile'
      IMPORTING ev_path     = lv_path ev_filename = lv_name ).
    cl_abap_unit_assert=>assert_equals( act = lv_path
                                        exp = '' ).
    cl_abap_unit_assert=>assert_equals( act = lv_name
                                        exp = 'somefile' ).
 
    zcl_abapgit_path=>split_file_location(
      EXPORTING iv_fullpath = '/'
      IMPORTING ev_path     = lv_path ev_filename = lv_name ).
    cl_abap_unit_assert=>assert_equals( act = lv_path
                                        exp = '/' ).
    cl_abap_unit_assert=>assert_equals( act = lv_name
                                        exp = '' ).
 
    zcl_abapgit_path=>split_file_location(
      EXPORTING iv_fullpath = '/somefile'
      IMPORTING ev_path     = lv_path ev_filename = lv_name ).
    cl_abap_unit_assert=>assert_equals( act = lv_path
                                        exp = '/' ).
    cl_abap_unit_assert=>assert_equals( act = lv_name
                                        exp = 'somefile' ).
 
    zcl_abapgit_path=>split_file_location(
      EXPORTING iv_fullpath = '/somedir/'
      IMPORTING ev_path     = lv_path ev_filename = lv_name ).
    cl_abap_unit_assert=>assert_equals( act = lv_path
                                        exp = '/somedir/' ).
    cl_abap_unit_assert=>assert_equals( act = lv_name
                                        exp = '' ).
 
    zcl_abapgit_path=>split_file_location(
      EXPORTING iv_fullpath = '/somedir/somefile'
      IMPORTING ev_path     = lv_path ev_filename = lv_name ).
    cl_abap_unit_assert=>assert_equals( act = lv_path
                                        exp = '/somedir/' ).
    cl_abap_unit_assert=>assert_equals( act = lv_name
                                        exp = 'somefile' ).
 
 
  ENDMETHOD.
 
  METHOD is_subdir.
 
    DATA lv_yes TYPE abap_bool.
 
    lv_yes = zcl_abapgit_path=>is_subdir( iv_path   = '/dir/subdir'
                                          iv_parent = '/dir' ).
    cl_abap_unit_assert=>assert_equals( act = lv_yes
                                        exp = abap_true ).
 
    lv_yes = zcl_abapgit_path=>is_subdir( iv_path   = '/dir/subdir'
                                          iv_parent = '/dir/' ).
    cl_abap_unit_assert=>assert_equals( act = lv_yes
                                        exp = abap_true ).
 
    lv_yes = zcl_abapgit_path=>is_subdir( iv_path   = '/another'
                                          iv_parent = '/dir' ).
    cl_abap_unit_assert=>assert_equals( act = lv_yes
                                        exp = abap_false ).
 
    lv_yes = zcl_abapgit_path=>is_subdir( iv_path   = '/dir'
                                          iv_parent = '/dir' ).
    cl_abap_unit_assert=>assert_equals( act = lv_yes
                                        exp = abap_false ).
 
    lv_yes = zcl_abapgit_path=>is_subdir( iv_path   = '/dir'
                                          iv_parent = '/' ).
    cl_abap_unit_assert=>assert_equals( act = lv_yes
                                        exp = abap_true ).
 
    lv_yes = zcl_abapgit_path=>is_subdir( iv_path   = '/dir2'
                                          iv_parent = '/dir' ).
    cl_abap_unit_assert=>assert_equals( act = lv_yes
                                        exp = abap_false ).
 
  ENDMETHOD.
 
  METHOD change_dir.
 
    DATA lv_path TYPE string.
 
    lv_path = zcl_abapgit_path=>change_dir( iv_cur_dir = ''
                                            iv_cd      = '' ).
    cl_abap_unit_assert=>assert_equals( act = lv_path
                                        exp = '' ).
 
    lv_path = zcl_abapgit_path=>change_dir( iv_cur_dir = '/dir'
                                            iv_cd      = '' ).
    cl_abap_unit_assert=>assert_equals( act = lv_path
                                        exp = '/dir' ).
 
    lv_path = zcl_abapgit_path=>change_dir( iv_cur_dir = '/dir'
                                            iv_cd      = '.' ).
    cl_abap_unit_assert=>assert_equals( act = lv_path
                                        exp = '/dir' ).
 
    lv_path = zcl_abapgit_path=>change_dir( iv_cur_dir = '/dir'
                                            iv_cd      = '..' ).
    cl_abap_unit_assert=>assert_equals( act = lv_path
                                        exp = '/' ).
 
    lv_path = zcl_abapgit_path=>change_dir( iv_cur_dir = '/dir/sub'
                                            iv_cd      = '..' ).
    cl_abap_unit_assert=>assert_equals( act = lv_path
                                        exp = '/dir/' ).
 
    lv_path = zcl_abapgit_path=>change_dir( iv_cur_dir = '/dir/'
                                            iv_cd      = 'sub' ).
    cl_abap_unit_assert=>assert_equals( act = lv_path
                                        exp = '/dir/sub' ).
 
    lv_path = zcl_abapgit_path=>change_dir( iv_cur_dir = '/dir'
                                            iv_cd      = 'sub' ).
    cl_abap_unit_assert=>assert_equals( act = lv_path
                                        exp = '/dir/sub' ).
 
  ENDMETHOD.
 
  METHOD get_filename_from_syspath.
 
    DATA lv_filename TYPE string.
 
    lv_filename = zcl_abapgit_path=>get_filename_from_syspath( 'file.txt' ).
    cl_abap_unit_assert=>assert_equals( act = lv_filename
                                        exp = 'file.txt' ).
 
    lv_filename = zcl_abapgit_path=>get_filename_from_syspath( 'c:\dir\file.txt' ).
    cl_abap_unit_assert=>assert_equals( act = lv_filename
                                        exp = 'file.txt' ).
 
    lv_filename = zcl_abapgit_path=>get_filename_from_syspath( 'c:\file.txt' ).
    cl_abap_unit_assert=>assert_equals( act = lv_filename
                                        exp = 'file.txt' ).
 
    lv_filename = zcl_abapgit_path=>get_filename_from_syspath( '/dir/file.txt' ).
    cl_abap_unit_assert=>assert_equals( act = lv_filename
                                        exp = 'file.txt' ).
 
    lv_filename = zcl_abapgit_path=>get_filename_from_syspath( '/file.txt' ).
    cl_abap_unit_assert=>assert_equals( act = lv_filename
                                        exp = 'file.txt' ).
 
    lv_filename = zcl_abapgit_path=>get_filename_from_syspath( '\\server$\file.txt' ).
    cl_abap_unit_assert=>assert_equals( act = lv_filename
                                        exp = 'file.txt' ).
 
    lv_filename = zcl_abapgit_path=>get_filename_from_syspath(
      'C:\foo\bar\moo.boo\dev\qas\_blah\goog\muuh\sap\hello\world\lorem\ipsum\s_foo.gif' ).
    cl_abap_unit_assert=>assert_equals( act = lv_filename
                                        exp = 's_foo.gif' ).
 
  ENDMETHOD.
 
ENDCLASS.