Skip to content

Commit 2ea1a88

Browse files
committed
Update to 7.4.0
1 parent 087eb7a commit 2ea1a88

11 files changed

+252
-123
lines changed

src/classes/zcl_semver.clas.abap

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ CLASS zcl_semver DEFINITION
7979

8080
METHODS inc
8181
IMPORTING
82-
release TYPE string
83-
identifier TYPE string OPTIONAL
82+
release TYPE string
83+
identifier TYPE string OPTIONAL
84+
identifier_base TYPE i DEFAULT 0
8485
RETURNING
85-
VALUE(result) TYPE REF TO zcl_semver
86+
VALUE(result) TYPE REF TO zcl_semver
8687
RAISING
8788
zcx_semver_error.
8889

@@ -320,26 +321,26 @@ CLASS zcl_semver IMPLEMENTATION.
320321
patch = 0.
321322
minor = 0.
322323
major += 1.
323-
inc( release = 'pre' identifier = identifier ).
324+
inc( release = 'pre' identifier = identifier identifier_base = identifier_base ).
324325
WHEN 'preminor'.
325326
CLEAR prerelease.
326327
patch = 0.
327328
minor += 1.
328-
inc( release = 'pre' identifier = identifier ).
329+
inc( release = 'pre' identifier = identifier identifier_base = identifier_base ).
329330
WHEN 'prepatch'.
330331
" If this is already a prerelease, it will bump to the next version
331332
" drop any prereleases that might already exist, since they are not
332333
" relevant at this point.
333334
CLEAR prerelease.
334-
inc( release = 'patch' identifier = identifier ).
335-
inc( release = 'pre' identifier = identifier ).
335+
inc( release = 'patch' identifier = identifier identifier_base = identifier_base ).
336+
inc( release = 'pre' identifier = identifier identifier_base = identifier_base ).
336337
WHEN 'prerelease'.
337338
" If the input is a non-prerelease version, this acts the same as
338339
" prepatch.
339340
IF prerelease IS INITIAL.
340-
inc( release = 'patch' identifier = identifier ).
341+
inc( release = 'patch' identifier = identifier identifier_base = identifier_base ).
341342
ENDIF.
342-
inc( release = 'pre' identifier = identifier ).
343+
inc( release = 'pre' identifier = identifier identifier_base = identifier_base ).
343344
WHEN 'major'.
344345
" If this is a pre-major version, bump up to the same major version.
345346
" Otherwise increment major.
@@ -391,14 +392,15 @@ CLASS zcl_semver IMPLEMENTATION.
391392
ENDIF.
392393
ENDIF.
393394
IF identifier IS NOT INITIAL.
395+
DATA(base) = COND #( WHEN identifier_base <> 0 THEN `1` ELSE `0` ).
394396
" 1.2.0-beta.1 bumps to 1.2.0-beta.2,
395397
" 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
396398
IF zcl_semver_identifiers=>compare_identifiers( a = prerelease[ 1 ] b = identifier ) = 0.
397399
IF NOT zcl_semver_utils=>is_numeric( VALUE #( prerelease[ 2 ] DEFAULT `-` ) ).
398-
prerelease = VALUE #( ( identifier ) ( `0` ) ).
400+
prerelease = VALUE #( ( identifier ) ( base ) ).
399401
ENDIF.
400402
ELSE.
401-
prerelease = VALUE #( ( identifier ) ( `0` ) ).
403+
prerelease = VALUE #( ( identifier ) ( base ) ).
402404
ENDIF.
403405
ENDIF.
404406

src/classes/zcl_semver.clas.testclasses.abap

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ CLASS ltcl_semver IMPLEMENTATION.
118118
TRY.
119119
DATA(s) = zcl_semver=>create( version = increments-version loose = increments-loose ).
120120

121-
s->inc( release = increments-release identifier = increments-identifier ).
121+
s->inc(
122+
release = increments-release
123+
identifier = increments-identifier
124+
identifier_base = increments-identifier_base ).
122125
cl_abap_unit_assert=>fail( msg = msg ).
123126
CATCH zcx_semver_error ##NO_HANDLER.
124127
" throws when presented with garbage
@@ -127,7 +130,10 @@ CLASS ltcl_semver IMPLEMENTATION.
127130
s = zcl_semver=>create( version = increments-version loose = increments-loose ).
128131

129132
cl_abap_unit_assert=>assert_equals(
130-
act = s->inc( release = increments-release identifier = increments-identifier )->version
133+
act = s->inc(
134+
release = increments-release
135+
identifier = increments-identifier
136+
identifier_base = increments-identifier_base )->version
131137
exp = increments-res
132138
msg = msg ).
133139
ENDIF.

src/classes/zcl_semver_comparator.clas.abap

Lines changed: 84 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -160,40 +160,90 @@ CLASS zcl_semver_comparator IMPLEMENTATION.
160160
result = semrange->test( semcomp->semver ).
161161
ENDIF.
162162
ELSE.
163-
DATA(same_direction_increasing) = xsdbool(
164-
( operator = '>=' OR operator = '>' ) AND
165-
( semcomp->operator = '>=' OR semcomp->operator = '>' ) ).
166-
DATA(same_direction_decreasing) = xsdbool(
167-
( operator = '<=' OR operator = '<' ) AND
168-
( semcomp->operator = '<=' OR semcomp->operator = '<' ) ).
169-
DATA(same_semver) = xsdbool(
170-
semver->version = semcomp->semver->version ).
171-
DATA(different_directions_inclusive) = xsdbool(
172-
( operator = '>=' OR operator = '<=' ) AND
173-
( semcomp->operator = '>=' OR semcomp->operator = '<=' ) ).
174-
DATA(opposite_directions_less) = xsdbool(
175-
zcl_semver_functions=>cmp(
176-
a = semver->version
177-
op = '<'
178-
b = semcomp->semver->version
179-
loose = loose ) AND
180-
( operator = '>=' OR operator = '>' ) AND
181-
( semcomp->operator = '<=' OR semcomp->operator = '<' ) ).
182-
DATA(opposite_directions_greater) = xsdbool(
183-
zcl_semver_functions=>cmp(
184-
a = semver->version
185-
op = '>'
186-
b = semcomp->semver->version
187-
loose = loose ) AND
188-
( operator = '<=' OR operator = '<' ) AND
189-
( semcomp->operator = '>=' OR semcomp->operator = '>' ) ).
190-
191-
result = xsdbool(
192-
same_direction_increasing = abap_true OR
193-
same_direction_decreasing = abap_true OR
194-
( same_semver = abap_true AND different_directions_inclusive = abap_true ) OR
195-
opposite_directions_less = abap_true OR
196-
opposite_directions_greater = abap_true ).
163+
" Special cases where nothing can possibly be lower
164+
IF incpre = abap_true AND value = '<0.0.0-0' OR semcomp->value = '<0.0.0-0'.
165+
result = abap_false.
166+
RETURN.
167+
ENDIF.
168+
IF incpre = abap_false AND value CP '<0.0.0*' OR semcomp->value CP '<0.0.0*'.
169+
result = abap_false.
170+
RETURN.
171+
ENDIF.
172+
173+
" Same direction increasing (> or >=)
174+
IF operator CP '>*' AND semcomp->operator CP '>*'.
175+
result = abap_true.
176+
RETURN.
177+
ENDIF.
178+
" Same direction decreasing (< or <=)
179+
IF operator CP '<*' AND semcomp->operator CP '<*'.
180+
result = abap_true.
181+
RETURN.
182+
ENDIF.
183+
184+
" same SemVer and both sides are inclusive (<= or >=)
185+
IF semver->version = semcomp->semver->version AND operator CA '=' AND semcomp->operator CA '='.
186+
result = abap_true.
187+
RETURN.
188+
ENDIF.
189+
190+
" opposite directions less than
191+
IF zcl_semver_functions=>cmp(
192+
a = semver->version
193+
op = '<'
194+
b = semcomp->semver->version
195+
loose = loose
196+
incpre = incpre ) AND operator CP '>*' AND semcomp->operator CP '<*'.
197+
result = abap_true.
198+
RETURN.
199+
ENDIF.
200+
" opposite directions greater than
201+
IF zcl_semver_functions=>cmp(
202+
a = semver->version
203+
op = '>'
204+
b = semcomp->semver->version
205+
loose = loose
206+
incpre = incpre ) AND operator CP '<*' AND semcomp->operator CP '>*'.
207+
result = abap_true.
208+
RETURN.
209+
ENDIF.
210+
result = abap_false.
211+
212+
213+
* DATA(same_direction_increasing) = xsdbool(
214+
* ( operator = '>=' OR operator = '>' ) AND
215+
* ( semcomp->operator = '>=' OR semcomp->operator = '>' ) ).
216+
* DATA(same_direction_decreasing) = xsdbool(
217+
* ( operator = '<=' OR operator = '<' ) AND
218+
* ( semcomp->operator = '<=' OR semcomp->operator = '<' ) ).
219+
* DATA(same_semver) = xsdbool(
220+
* semver->version = semcomp->semver->version ).
221+
* DATA(different_directions_inclusive) = xsdbool(
222+
* ( operator = '>=' OR operator = '<=' ) AND
223+
* ( semcomp->operator = '>=' OR semcomp->operator = '<=' ) ).
224+
* DATA(opposite_directions_less) = xsdbool(
225+
* zcl_semver_functions=>cmp(
226+
* a = semver->version
227+
* op = '<'
228+
* b = semcomp->semver->version
229+
* loose = loose ) AND
230+
* ( operator = '>=' OR operator = '>' ) AND
231+
* ( semcomp->operator = '<=' OR semcomp->operator = '<' ) ).
232+
* DATA(opposite_directions_greater) = xsdbool(
233+
* zcl_semver_functions=>cmp(
234+
* a = semver->version
235+
* op = '>'
236+
* b = semcomp->semver->version
237+
* loose = loose ) AND
238+
* ( operator = '<=' OR operator = '<' ) AND
239+
* ( semcomp->operator = '>=' OR semcomp->operator = '>' ) ).
240+
*
241+
* result = xsdbool(
242+
* same_direction_increasing = abap_true OR
243+
* same_direction_decreasing = abap_true OR
244+
* ( same_semver = abap_true AND different_directions_inclusive = abap_true ) OR
245+
* opposite_directions_less = abap_true OR
246+
* opposite_directions_greater = abap_true ).
197247
ENDIF.
198248

199249
ENDMETHOD.

src/classes/zcl_semver_comparator.clas.testclasses.abap

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ CLASS ltcl_semver_comparator IMPLEMENTATION.
6060
DATA(comp1) = zcl_semver_comparator=>create( intersection-c1 ).
6161

6262
cl_abap_unit_assert=>assert_equals(
63-
act = comp0->intersects( comp1 )
63+
act = comp0->intersects( comp = comp1 incpre = intersection-incpre )
64+
exp = intersection-res
65+
msg = msg ).
66+
67+
cl_abap_unit_assert=>assert_equals(
68+
act = comp1->intersects( comp = comp0 incpre = intersection-incpre )
6469
exp = intersection-res
6570
msg = msg ).
6671
ENDLOOP.

src/cli/zcl_semver_cli.clas.abap

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@ CLASS zcl_semver_cli DEFINITION
3434
PRIVATE SECTION.
3535

3636
CLASS-DATA:
37-
argv TYPE string_table,
38-
versions TYPE string_table,
39-
ranges TYPE string_table,
40-
inc TYPE string,
41-
identifier TYPE string,
42-
loose TYPE abap_bool,
43-
incpre TYPE abap_bool,
44-
coerce TYPE abap_bool,
45-
rtl TYPE abap_bool,
46-
reverse TYPE abap_bool.
37+
argv TYPE string_table,
38+
versions TYPE string_table,
39+
ranges TYPE string_table,
40+
inc TYPE string,
41+
identifier TYPE string,
42+
identifier_base TYPE i,
43+
loose TYPE abap_bool,
44+
incpre TYPE abap_bool,
45+
coerce TYPE abap_bool,
46+
rtl TYPE abap_bool,
47+
reverse TYPE abap_bool.
4748

4849
ENDCLASS.
4950

@@ -83,6 +84,9 @@ CLASS zcl_semver_cli IMPLEMENTATION.
8384
( `-l --loose` )
8485
( ` Interpret versions and ranges loosely` )
8586
( `` )
87+
( `-n <0|1>` )
88+
( ` This is the base to be used for the prerelease identifier.` )
89+
( `` )
8690
( `-p --include-prerelease` )
8791
( ` Always include prerelease versions in range matching` )
8892
( `` )
@@ -107,7 +111,9 @@ CLASS zcl_semver_cli IMPLEMENTATION.
107111

108112
METHOD main.
109113

110-
CLEAR: argv, versions, ranges, inc, identifier, loose, incpre, coerce, rtl, reverse.
114+
CLEAR:
115+
argv, versions, ranges, inc, identifier, identifier_base,
116+
loose, incpre, coerce, rtl, reverse.
111117

112118
IF args IS INITIAL.
113119
result = help( ).
@@ -153,6 +159,12 @@ CLASS zcl_semver_cli IMPLEMENTATION.
153159
idx += 1.
154160
val = VALUE #( argv[ idx ] OPTIONAL ).
155161
INSERT val INTO TABLE ranges.
162+
WHEN '-n'.
163+
idx += 1.
164+
TRY.
165+
identifier_base = VALUE #( argv[ idx ] OPTIONAL ).
166+
CATCH cx_root.
167+
ENDTRY.
156168
WHEN '-c' OR '--coerce'.
157169
coerce = abap_true.
158170
WHEN '--rtl'.
@@ -230,8 +242,13 @@ CLASS zcl_semver_cli IMPLEMENTATION.
230242

231243
IF inc IS NOT INITIAL.
232244
LOOP AT versions ASSIGNING <version>.
233-
DATA(semver) = zcl_semver_functions=>inc( version = <version> release = inc identifier = identifier
234-
loose = loose incpre = incpre ).
245+
DATA(semver) = zcl_semver_functions=>inc(
246+
version = <version>
247+
release = inc
248+
identifier = identifier
249+
identifier_base = identifier_base
250+
loose = loose
251+
incpre = incpre ).
235252

236253
IF semver IS BOUND.
237254
<version> = semver->version.

src/cli/zcl_semver_cli.clas.testclasses.abap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ CLASS ltcl_semver_cli IMPLEMENTATION.
8686
args = '-i premajor 1.0.0 --preid=beta'
8787
out = |2.0.0-beta.0\n| ).
8888

89+
test(
90+
args = '-i premajor 1.0.0 --preid=beta -n 1'
91+
out = |2.0.0-beta.1\n| ).
92+
8993
test(
9094
args = '-i 1.2.3'
9195
out = |1.2.4\n| ).

src/functions/zcl_semver_functions.clas.abap

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,14 @@ CLASS zcl_semver_functions DEFINITION
120120

121121
CLASS-METHODS inc
122122
IMPORTING
123-
version TYPE any
124-
release TYPE string
125-
identifier TYPE string OPTIONAL
126-
loose TYPE abap_bool DEFAULT abap_false
127-
incpre TYPE abap_bool DEFAULT abap_false
123+
version TYPE any
124+
release TYPE string
125+
identifier TYPE string OPTIONAL
126+
identifier_base TYPE i DEFAULT 0
127+
loose TYPE abap_bool DEFAULT abap_false
128+
incpre TYPE abap_bool DEFAULT abap_false
128129
RETURNING
129-
VALUE(result) TYPE REF TO zcl_semver.
130+
VALUE(result) TYPE REF TO zcl_semver.
130131

131132
CLASS-METHODS lt
132133
IMPORTING
@@ -445,6 +446,16 @@ CLASS zcl_semver_functions IMPLEMENTATION.
445446
result = prefix && 'minor'.
446447
ELSEIF semver_1->patch <> semver_2->patch.
447448
result = prefix && 'patch'.
449+
ELSEIF semver_1->prerelease IS INITIAL OR semver_2->prerelease IS INITIAL.
450+
IF semver_1->patch IS NOT INITIAL.
451+
result = 'patch'.
452+
ELSEIF semver_1->minor IS NOT INITIAL.
453+
result = 'minor'.
454+
ELSEIF semver_1->major IS NOT INITIAL.
455+
result = 'major'.
456+
ELSE.
457+
result = default_result. " may be undefined
458+
ENDIF.
448459
ELSE.
449460
result = default_result. " may be undefined
450461
ENDIF.
@@ -500,7 +511,7 @@ CLASS zcl_semver_functions IMPLEMENTATION.
500511

501512
CHECK result IS BOUND.
502513

503-
result->inc( release = release identifier = identifier ).
514+
result->inc( release = release identifier = identifier identifier_base = identifier_base ).
504515
CATCH zcx_semver_error.
505516
CLEAR result.
506517
ENDTRY.
@@ -558,25 +569,9 @@ CLASS zcl_semver_functions IMPLEMENTATION.
558569

559570
CHECK strlen( version ) <= zif_semver_constants=>max_length.
560571

561-
DATA(r) = COND #(
562-
WHEN loose = abap_true
563-
THEN zcl_semver_re=>token-loose-regex
564-
ELSE zcl_semver_re=>token-full-regex ).
565-
566572
TRY.
567-
DATA(m) = r->create_matcher( text = version ).
568-
569-
IF m->match( ).
570-
571-
TRY.
572-
result = zcl_semver=>create( version = version loose = loose incpre = incpre ).
573-
CATCH zcx_semver_error ##NO_HANDLER.
574-
ENDTRY.
575-
576-
ENDIF.
577-
578-
CATCH cx_sy_matcher.
579-
zcx_semver_error=>raise( |Error evaluating regex for { version }| ).
573+
result = zcl_semver=>create( version = version loose = loose incpre = incpre ).
574+
CATCH zcx_semver_error ##NO_HANDLER.
580575
ENDTRY.
581576

582577
ENDMETHOD.

0 commit comments

Comments
 (0)