Skip to content

Commit b7a88da

Browse files
committed
v7.7.3
Update from 7.7.1 to 7.7.3 (already contains npm/node-semver#835)
1 parent 889e589 commit b7a88da

14 files changed

Lines changed: 771 additions & 568 deletions

src/classes/#apmg#cl_semver.clas.abap

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,20 @@ CLASS /apmg/cl_semver IMPLEMENTATION.
162162

163163
CHECK semver IS BOUND.
164164

165-
result = /apmg/cl_semver_identifiers=>compare_identifiers( a = major b = semver->major ).
166-
IF result = 0.
167-
result = /apmg/cl_semver_identifiers=>compare_identifiers( a = minor b = semver->minor ).
168-
IF result = 0.
169-
result = /apmg/cl_semver_identifiers=>compare_identifiers( a = patch b = semver->patch ).
170-
ENDIF.
165+
IF major < semver->major.
166+
result = -1.
167+
ELSEIF major > semver->major.
168+
result = 1.
169+
ELSEIF minor < semver->minor.
170+
result = -1.
171+
ELSEIF minor > semver->minor.
172+
result = 1.
173+
ELSEIF patch < semver->patch.
174+
result = -1.
175+
ELSEIF patch > semver->patch.
176+
result = 1.
177+
ELSE.
178+
result = 0.
171179
ENDIF.
172180

173181
ENDMETHOD.
@@ -499,12 +507,11 @@ CLASS /apmg/cl_semver IMPLEMENTATION.
499507
IF identifier IS NOT INITIAL.
500508
DATA(regex) = COND #(
501509
WHEN options-loose = abap_true
502-
THEN |^{ /apmg/cl_semver_re=>token-prereleaseloose-safe_src }$|
503-
ELSE |^{ /apmg/cl_semver_re=>token-prerelease-safe_src }$| ).
510+
THEN /apmg/cl_semver_re=>token-prereleaseloose-regex
511+
ELSE /apmg/cl_semver_re=>token-prerelease-regex ).
504512

505513
TRY.
506-
DATA(r) = NEW cl_abap_regex( pattern = regex ) ##REGEX_POSIX.
507-
DATA(m) = r->create_matcher( text = |-{ identifier }| ).
514+
DATA(m) = regex->create_matcher( text = |-{ identifier }| ).
508515

509516
IF NOT m->match( ) OR m->get_submatch( 1 ) <> identifier.
510517
RAISE EXCEPTION TYPE /apmg/cx_error_text

src/classes/#apmg#cl_semver.clas.testclasses.abap

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CLASS ltcl_semver DEFINITION FOR TESTING RISK LEVEL HARMLESS
77
comparisons FOR TESTING RAISING /apmg/cx_error,
88
equality FOR TESTING RAISING /apmg/cx_error,
99
to_string FOR TESTING RAISING /apmg/cx_error,
10+
valid_versions FOR TESTING RAISING /apmg/cx_error,
1011
invalid_versions FOR TESTING RAISING /apmg/cx_error,
1112
options FOR TESTING RAISING /apmg/cx_error,
1213
really_big FOR TESTING RAISING /apmg/cx_error,
@@ -69,6 +70,46 @@ CLASS ltcl_semver IMPLEMENTATION.
6970

7071
ENDMETHOD.
7172

73+
METHOD valid_versions.
74+
75+
LOOP AT /apmg/cl_semver_fixtures=>valid_versions( ) INTO DATA(valid_version).
76+
DATA(msg) = valid_version-version.
77+
78+
TRY.
79+
DATA(s) = /apmg/cl_semver=>create( version = valid_version-version ).
80+
81+
cl_abap_unit_assert=>assert_equals(
82+
act = s->major
83+
exp = valid_version-major
84+
msg = msg ).
85+
cl_abap_unit_assert=>assert_equals(
86+
act = s->minor
87+
exp = valid_version-minor
88+
msg = msg ).
89+
cl_abap_unit_assert=>assert_equals(
90+
act = s->patch
91+
exp = valid_version-patch
92+
msg = msg ).
93+
cl_abap_unit_assert=>assert_equals(
94+
act = s->prerelease
95+
exp = valid_version-prerelease
96+
msg = msg ).
97+
cl_abap_unit_assert=>assert_equals(
98+
act = s->build
99+
exp = valid_version-build
100+
msg = msg ).
101+
cl_abap_unit_assert=>assert_equals(
102+
act = s->raw
103+
exp = valid_version-version
104+
msg = msg ).
105+
106+
CATCH /apmg/cx_error.
107+
cl_abap_unit_assert=>fail( msg = msg ).
108+
ENDTRY.
109+
ENDLOOP.
110+
111+
ENDMETHOD.
112+
72113
METHOD invalid_versions.
73114
" throws when presented with garbage
74115

@@ -205,8 +246,8 @@ CLASS ltcl_semver IMPLEMENTATION.
205246

206247
TRY.
207248
v->inc(
208-
release_type = 'prerelease'
209-
identifier = 'hot/mess' ).
249+
release_type = 'prerelease'
250+
identifier = 'hot/mess' ).
210251
CATCH /apmg/cx_error ##NO_HANDLER.
211252
" ignore but check that the version has not changed
212253
ENDTRY.

src/classes/#apmg#cl_semver_range.clas.abap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,10 @@ CLASS /apmg/cl_semver_range IMPLEMENTATION.
425425

426426

427427
METHOD parse_comparator.
428-
result = comp.
428+
result = replace(
429+
val = comp
430+
regex = /apmg/cl_semver_re=>token-build-src
431+
with = '' ) ##REGEX_POSIX.
429432
result = replace_carets( comp = result loose = loose incpre = incpre ).
430433
result = replace_tildes( comp = result loose = loose incpre = incpre ).
431434
result = replace_xranges( comp = result loose = loose incpre = incpre ).

src/cli/#apmg#cl_semver_cli.clas.abap

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,11 @@ CLASS /apmg/cl_semver_cli IMPLEMENTATION.
253253
DATA(tabix) = sy-tabix.
254254

255255
IF coerce = abap_true.
256-
DATA(semver) = /apmg/cl_semver_functions=>coerce( version = <version> rtl = rtl ).
256+
DATA(semver) = /apmg/cl_semver_functions=>coerce(
257+
version = <version>
258+
rtl = rtl
259+
loose = loose
260+
incpre = incpre ).
257261
IF semver IS BOUND.
258262
<version> = semver->version.
259263
ELSE.
@@ -262,8 +266,12 @@ CLASS /apmg/cl_semver_cli IMPLEMENTATION.
262266
ENDIF.
263267
ENDIF.
264268

265-
IF NOT /apmg/cl_semver_functions=>valid( <version> ).
269+
DATA(valid) = /apmg/cl_semver_functions=>valid( version = <version> loose = loose incpre = incpre ).
270+
271+
IF valid IS INITIAL.
266272
DELETE versions INDEX tabix.
273+
ELSE.
274+
<version> = valid.
267275
ENDIF.
268276

269277
ENDLOOP.

src/cli/#apmg#cl_semver_cli.clas.testclasses.abap

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ CLASS ltcl_semver_cli IMPLEMENTATION.
9898
args = '-i 1.2.3'
9999
out = |1.2.4\n| ).
100100

101+
test(
102+
args = '-i release 1.0.0-pre'
103+
out = |1.0.0\n| ).
104+
101105
ENDMETHOD.
102106

103107
METHOD sorting_and_filtering.
@@ -124,7 +128,11 @@ CLASS ltcl_semver_cli IMPLEMENTATION.
124128

125129
test(
126130
args = '1.2.3foo 1.2.3-bar -l'
127-
out = |1.2.3-bar\n| ).
131+
out = |1.2.3-bar\n1.2.3-foo\n| ).
132+
133+
test(
134+
args = '1.2.3beta -l'
135+
out = |1.2.3-beta\n| ).
128136

129137
test(
130138
args = '1.2.3 3.2.1 -r 2.x 2.3.4'
@@ -140,7 +148,7 @@ CLASS ltcl_semver_cli IMPLEMENTATION.
140148

141149
test(
142150
args = '3.2.1 2.3.4 2.3.4-beta 2.0.0asdf -r 2.x -p -l'
143-
out = |2.3.4-beta\n2.3.4\n| ).
151+
out = |2.0.0-asdf\n2.3.4-beta\n2.3.4\n| ).
144152

145153
test(
146154
args = '1.2.3 3.2.1 -r 2.x'

src/functions/#apmg#cl_semver_functions.clas.testclasses.abap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,21 @@ CLASS ltcl_semver_functions IMPLEMENTATION.
315315
( version = '1.2.3-rc.5/a' res = '1.2.3-rc.5' )
316316
( version = '1.2.3.4-rc.5' res = '1.2.3' )
317317
( version = '1.2.3.4+rev.6' res = '1.2.3' )
318+
319+
( version = '1.0.0-1a' res = '1.0.0-1a' )
320+
( version = '1.0.0-alpha.12ab' res = '1.0.0-alpha.12ab' )
321+
( version = '1.0.0-alpha.1234.23cd' res = '1.0.0-alpha.1234.23cd' )
322+
( version = '1.0.0-nightly.abc123' res = '1.0.0-nightly.abc123' )
323+
( version = '1.0.0-nightly.abcdef' res = '1.0.0-nightly.abcdef' )
324+
( version = '1.0.0-nightly.123456' res = '1.0.0-nightly.123456' )
325+
318326
( version = '1+rev.6' res = '1.0.0+rev.6' )
319327
( version = '1.2+rev.6' res = '1.2.0+rev.6' )
320328
( version = '1.2.3+rev.6' res = '1.2.3+rev.6' )
321329
( version = '1.2.3+rev.6/a' res = '1.2.3+rev.6' )
322330
( version = '1.2.3.4-rc.5' res = '1.2.3' )
323331
( version = '1.2.3.4+rev.6' res = '1.2.3' )
332+
324333
( version = '1-rc.5+rev.6' res = '1.0.0-rc.5+rev.6' )
325334
( version = '1.2-rc.5+rev.6' res = '1.2.0-rc.5+rev.6' )
326335
( version = '1.2.3-rc.5+rev.6' res = '1.2.3-rc.5+rev.6' )

src/internal/#apmg#cl_semver_identifiers.clas.abap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ CLASS /apmg/cl_semver_identifiers IMPLEMENTATION.
3636

3737
METHOD compare_identifiers.
3838

39+
" Using RTTI isn't faster and there's no built in typeof
40+
" if (typeof a === 'number' && typeof b === 'number') {
41+
" return a === b ? 0 : a < b ? -1 : 1
42+
" }
43+
3944
DATA(anum) = /apmg/cl_semver_utils=>is_numeric( a ).
4045
DATA(bnum) = /apmg/cl_semver_utils=>is_numeric( b ).
4146

src/internal/#apmg#cl_semver_identifiers.clas.testclasses.abap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ CLASS ltcl_semver_identifiers IMPLEMENTATION.
3535
act = /apmg/cl_semver_identifiers=>rcompare_identifiers( a = '0' b = 'beta' )
3636
exp = +1 ).
3737

38+
cl_abap_unit_assert=>assert_equals(
39+
act = /apmg/cl_semver_identifiers=>compare_identifiers( a = 1 b = 2 )
40+
exp = -1 ).
41+
42+
cl_abap_unit_assert=>assert_equals(
43+
act = /apmg/cl_semver_identifiers=>rcompare_identifiers( a = 1 b = 2 )
44+
exp = +1 ).
45+
3846
cl_abap_unit_assert=>assert_equals(
3947
act = /apmg/cl_semver_identifiers=>compare_identifiers( a = '0' b = '0' )
4048
exp = 0 ).
@@ -43,6 +51,14 @@ CLASS ltcl_semver_identifiers IMPLEMENTATION.
4351
act = /apmg/cl_semver_identifiers=>rcompare_identifiers( a = '0' b = '0' )
4452
exp = 0 ).
4553

54+
cl_abap_unit_assert=>assert_equals(
55+
act = /apmg/cl_semver_identifiers=>compare_identifiers( a = 1 b = 1 )
56+
exp = 0 ).
57+
58+
cl_abap_unit_assert=>assert_equals(
59+
act = /apmg/cl_semver_identifiers=>rcompare_identifiers( a = 1 b = 1 )
60+
exp = 0 ).
61+
4662
ENDMETHOD.
4763

4864
ENDCLASS.

src/internal/#apmg#cl_semver_re.clas.abap

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,18 @@ CLASS /apmg/cl_semver_re IMPLEMENTATION.
155155

156156
" ## Pre-release Version Identifier
157157
" A numeric identifier, or a non-numeric identifier.
158+
" Non-numberic identifiers include numeric identifiers but can be longer.
159+
" Therefore non-numeric identifiers must go first.
158160

159161
create_token(
160162
name = 'PRERELEASEIDENTIFIER'
161-
value = |(?:{ token-numericidentifier-src }\|| &&
162-
|{ token-nonnumericidentifier-src })| ).
163+
value = |(?:{ token-nonnumericidentifier-src }\|| &&
164+
|{ token-numericidentifier-src })| ).
163165

164166
create_token(
165167
name = 'PRERELEASEIDENTIFIERLOOSE'
166-
value = |(?:{ token-numericidentifierloose-src }\|| &&
167-
|{ token-nonnumericidentifier-src })| ).
168+
value = |(?:{ token-nonnumericidentifier-src }\|| &&
169+
|{ token-numericidentifierloose-src })| ).
168170

169171
" ## Pre-release Version
170172
" Hyphen, followed by one or more dot-separated pre-release version

src/internal/#apmg#cl_semver_utils.clas.abap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ CLASS /apmg/cl_semver_utils IMPLEMENTATION.
4242
" Unsigned number (could be bigger than int4 or even int8)
4343

4444
TRY.
45-
result = xsdbool( |{ data }| CO '0123456789' ).
45+
result = xsdbool( condense( |{ data }| ) CO '0123456789' ).
4646
CATCH cx_root.
4747
" can't be converted to string/numeric
4848
result = abap_false.

0 commit comments

Comments
 (0)