File: version_spec.rb

package info (click to toggle)
ruby-semantic-puppet 1.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 292 kB
  • sloc: ruby: 2,898; makefile: 6
file content (823 lines) | stat: -rw-r--r-- 29,994 bytes parent folder | download | duplicates (4)
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
require 'spec_helper'
require 'semantic_puppet/version'

describe SemanticPuppet::Version do

  def subject(str)
    SemanticPuppet::Version.parse(str)
  end

  describe '.parse' do

    let(:parse_failure) do
      /Unable to parse .* as a semantic version identifier/
    end

    let(:no_leading_zeroes) do
      'Numeric pre-release identifiers MUST NOT contain leading zeroes'
    end

    context 'Spec v2.0.0' do
      context 'Section 2' do
        # A normal version number MUST take the form X.Y.Z where X, Y, and Z are
        # non-negative integers, and MUST NOT contain leading zeroes. X is the
        # major version, Y is the minor version, and Z is the patch version.
        # Each element MUST increase numerically.
        # For instance: 1.9.0 -> 1.10.0 -> 1.11.0.

        it 'rejects versions that contain too few parts' do
          expect { subject('1.2') }.to raise_error(parse_failure)
        end

        it 'rejects versions that contain too many parts' do
          expect { subject('1.2.3.4') }.to raise_error(parse_failure)
        end

        it 'rejects versions that contain non-integers' do
          expect { subject('x.2.3') }.to raise_error(parse_failure)
          expect { subject('1.y.3') }.to raise_error(parse_failure)
          expect { subject('1.2.z') }.to raise_error(parse_failure)
        end

        it 'rejects versions that contain negative integers' do
          expect { subject('-1.2.3') }.to raise_error(parse_failure)
          expect { subject('1.-2.3') }.to raise_error(parse_failure)
          expect { subject('1.2.-3') }.to raise_error(parse_failure)
        end

        it 'rejects version numbers containing leading zeroes' do
          expect { subject('01.2.3') }.to raise_error(parse_failure)
          expect { subject('1.02.3') }.to raise_error(parse_failure)
          expect { subject('1.2.03') }.to raise_error(parse_failure)
        end

        it 'permits zeroes in version number parts' do
          expect { subject('0.2.3') }.to_not raise_error
          expect { subject('1.0.3') }.to_not raise_error
          expect { subject('1.2.0') }.to_not raise_error
        end

        context 'examples' do
          example '1.9.0' do
            version = subject('1.9.0')
            expect(version.major).to eql 1
            expect(version.minor).to eql 9
            expect(version.patch).to eql 0
          end

          example '1.10.0' do
            version = subject('1.10.0')
            expect(version.major).to eql 1
            expect(version.minor).to eql 10
            expect(version.patch).to eql 0
          end

          example '1.11.0' do
            version = subject('1.11.0')
            expect(version.major).to eql 1
            expect(version.minor).to eql 11
            expect(version.patch).to eql 0
          end
        end
      end

      context 'Section 9' do
        # A pre-release version MAY be denoted by appending a hyphen and a
        # series of dot separated identifiers immediately following the patch
        # version. Identifiers MUST comprise only ASCII alphanumerics and
        # hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty. Numeric
        # identifiers MUST NOT include leading zeroes. Pre-release versions
        # have a lower precedence than the associated normal version. A
        # pre-release version indicates that the version is unstable and
        # might not satisfy the intended compatibility requirements as denoted
        # by its associated normal version.
        # Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92.

        it 'rejects prerelease identifiers with non-alphanumerics' do
          expect { subject('1.2.3-$100') }.to raise_error(parse_failure)
          expect { subject('1.2.3-rc.1@me') }.to raise_error(parse_failure)
        end

        it 'rejects empty prerelease versions' do
          expect { subject('1.2.3-') }.to raise_error(parse_failure)
        end

        it 'rejects empty prerelease version identifiers' do
          expect { subject('1.2.3-.rc1') }.to raise_error(parse_failure)
          expect { subject('1.2.3-rc1.') }.to raise_error(parse_failure)
          expect { subject('1.2.3-rc..1') }.to raise_error(parse_failure)
        end

        it 'rejects numeric prerelease identifiers with leading zeroes' do
          expect { subject('1.2.3-01') }.to raise_error(no_leading_zeroes)
          expect { subject('1.2.3-rc.01') }.to raise_error(no_leading_zeroes)
        end

        it 'permits numeric prerelease identifiers of zero' do
          expect { subject('1.2.3-0') }.to_not raise_error
          expect { subject('1.2.3-rc.0') }.to_not raise_error
        end

        it 'permits non-numeric prerelease identifiers with leading zeroes' do
          expect { subject('1.2.3-0xDEADBEEF') }.to_not raise_error
          expect { subject('1.2.3-rc.0x10c') }.to_not raise_error
        end

        context 'examples' do
          example '1.0.0-alpha' do
            version = subject('1.0.0-alpha')
            expect(version.major).to eql 1
            expect(version.minor).to eql 0
            expect(version.patch).to eql 0
            expect(version.prerelease).to eql 'alpha'
          end

          example '1.0.0-alpha.1' do
            version = subject('1.0.0-alpha.1')
            expect(version.major).to eql 1
            expect(version.minor).to eql 0
            expect(version.patch).to eql 0
            expect(version.prerelease).to eql 'alpha.1'
          end

          example '1.0.0-0.3.7' do
            version = subject('1.0.0-0.3.7')
            expect(version.major).to eql 1
            expect(version.minor).to eql 0
            expect(version.patch).to eql 0
            expect(version.prerelease).to eql '0.3.7'
          end

          example '1.0.0-x.7.z.92' do
            version = subject('1.0.0-x.7.z.92')
            expect(version.major).to eql 1
            expect(version.minor).to eql 0
            expect(version.patch).to eql 0
            expect(version.prerelease).to eql 'x.7.z.92'
          end
        end
      end

      context 'Section 10' do
        # Build metadata MAY be denoted by appending a plus sign and a series
        # of dot separated identifiers immediately following the patch or
        # pre-release version. Identifiers MUST comprise only ASCII
        # alphanumerics and hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty.
        # Build metadata SHOULD be ignored when determining version precedence.
        # Thus two versions that differ only in the build metadata, have the
        # same precedence.
        # Examples: 1.0.0-alpha+001, 1.0.0+20130313144700,
        # 1.0.0-beta+exp.sha.5114f85.

        it 'rejects build identifiers with non-alphanumerics' do
          expect { subject('1.2.3+$100') }.to raise_error(parse_failure)
          expect { subject('1.2.3+rc.1@me') }.to raise_error(parse_failure)
        end

        it 'rejects empty build metadata' do
          expect { subject('1.2.3+') }.to raise_error(parse_failure)
        end

        it 'rejects empty build identifiers' do
          expect { subject('1.2.3+.rc1') }.to raise_error(parse_failure)
          expect { subject('1.2.3+rc1.') }.to raise_error(parse_failure)
          expect { subject('1.2.3+rc..1') }.to raise_error(parse_failure)
        end

        it 'permits numeric build identifiers with leading zeroes' do
          expect { subject('1.2.3+01') }.to_not raise_error
          expect { subject('1.2.3+rc.01') }.to_not raise_error
        end

        it 'permits numeric build identifiers of zero' do
          expect { subject('1.2.3+0') }.to_not raise_error
          expect { subject('1.2.3+rc.0') }.to_not raise_error
        end

        it 'permits non-numeric build identifiers with leading zeroes' do
          expect { subject('1.2.3+0xDEADBEEF') }.to_not raise_error
          expect { subject('1.2.3+rc.0x10c') }.to_not raise_error
        end

        context 'examples' do
          example '1.0.0-alpha+001' do
            version = subject('1.0.0-alpha+001')
            expect(version.major).to eql 1
            expect(version.minor).to eql 0
            expect(version.patch).to eql 0
            expect(version.prerelease).to eql 'alpha'
            expect(version.build).to eql '001'
          end

          example '1.0.0+20130313144700' do
            version = subject('1.0.0+20130313144700')
            expect(version.major).to eql 1
            expect(version.minor).to eql 0
            expect(version.patch).to eql 0
            expect(version.prerelease).to eql nil
            expect(version.build).to eql '20130313144700'
          end

          example '1.0.0-beta+exp.sha.5114f85' do
            version = subject('1.0.0-beta+exp.sha.5114f85')
            expect(version.major).to eql 1
            expect(version.minor).to eql 0
            expect(version.patch).to eql 0
            expect(version.prerelease).to eql 'beta'
            expect(version.build).to eql 'exp.sha.5114f85'
          end
        end
      end
    end

    context 'Spec v1.0.0' do
      context 'Section 2' do
        # A normal version number MUST take the form X.Y.Z where X, Y, and Z
        # are integers. X is the major version, Y is the minor version, and Z
        # is the patch version. Each element MUST increase numerically by
        # increments of one.
        # For instance: 1.9.0 -> 1.10.0 -> 1.11.0

        it 'rejects versions that contain too few parts' do
          expect { subject('1.2') }.to raise_error(parse_failure)
        end

        it 'rejects versions that contain too many parts' do
          expect { subject('1.2.3.4') }.to raise_error(parse_failure)
        end

        it 'rejects versions that contain non-integers' do
          expect { subject('x.2.3') }.to raise_error(parse_failure)
          expect { subject('1.y.3') }.to raise_error(parse_failure)
          expect { subject('1.2.z') }.to raise_error(parse_failure)
        end

        it 'permits zeroes in version number parts' do
          expect { subject('0.2.3') }.to_not raise_error
          expect { subject('1.0.3') }.to_not raise_error
          expect { subject('1.2.0') }.to_not raise_error
        end

        context 'examples' do
          example '1.9.0' do
            version = subject('1.9.0')
            expect(version.major).to eql 1
            expect(version.minor).to eql 9
            expect(version.patch).to eql 0
          end

          example '1.10.0' do
            version = subject('1.10.0')
            expect(version.major).to eql 1
            expect(version.minor).to eql 10
            expect(version.patch).to eql 0
          end

          example '1.11.0' do
            version = subject('1.11.0')
            expect(version.major).to eql 1
            expect(version.minor).to eql 11
            expect(version.patch).to eql 0
          end
        end
      end

      context 'Section 4' do
        # A pre-release version number MAY be denoted by appending an arbitrary
        # string immediately following the patch version and a dash. The string
        # MUST be comprised of only alphanumerics plus dash [0-9A-Za-z-].
        # Pre-release versions satisfy but have a lower precedence than the
        # associated normal version. Precedence SHOULD be determined by
        # lexicographic ASCII sort order.
        # For instance: 1.0.0-alpha1 < 1.0.0-beta1 < 1.0.0-beta2 < 1.0.0-rc1

        it 'rejects prerelease identifiers with non-alphanumerics' do
          expect { subject('1.2.3-$100') }.to raise_error(parse_failure)
          expect { subject('1.2.3-rc.1@me') }.to raise_error(parse_failure)
        end

        it 'rejects empty prerelease versions' do
          expect { subject('1.2.3-') }.to raise_error(parse_failure)
        end

        it 'rejects numeric prerelease identifiers with leading zeroes' do
          expect { subject('1.2.3-01') }.to raise_error(no_leading_zeroes)
        end

        it 'permits numeric prerelease identifiers of zero' do
          expect { subject('1.2.3-0') }.to_not raise_error
        end

        it 'permits non-numeric prerelease identifiers with leading zeroes' do
          expect { subject('1.2.3-0xDEADBEEF') }.to_not raise_error
        end

        context 'examples' do
          example '1.0.0-alpha1' do
            version = subject('1.0.0-alpha1')
            expect(version.major).to eql 1
            expect(version.minor).to eql 0
            expect(version.patch).to eql 0
            expect(version.prerelease).to eql 'alpha1'
          end

          example '1.0.0-beta1' do
            version = subject('1.0.0-beta1')
            expect(version.major).to eql 1
            expect(version.minor).to eql 0
            expect(version.patch).to eql 0
            expect(version.prerelease).to eql 'beta1'
          end

          example '1.0.0-beta2' do
            version = subject('1.0.0-beta2')
            expect(version.major).to eql 1
            expect(version.minor).to eql 0
            expect(version.patch).to eql 0
            expect(version.prerelease).to eql 'beta2'
          end

          example '1.0.0-rc1' do
            version = subject('1.0.0-rc1')
            expect(version.major).to eql 1
            expect(version.minor).to eql 0
            expect(version.patch).to eql 0
            expect(version.prerelease).to eql 'rc1'
          end
        end
      end
    end

  end

  describe '.valid?' do
    def subject(str)
      SemanticPuppet::Version.valid?(str)
    end

    context 'Spec v2.0.0' do
      context 'Section 2' do
        # A normal version number MUST take the form X.Y.Z where X, Y, and Z are
        # non-negative integers, and MUST NOT contain leading zeroes. X is the
        # major version, Y is the minor version, and Z is the patch version.

        it 'rejects versions that contain too few parts' do
          expect(subject('1.2')).to be false
        end

        it 'rejects versions that contain too many parts' do
          expect(subject('1.2.3.4')).to be false
        end

        it 'rejects versions that contain non-integers' do
          expect(subject('x.2.3')).to be false
          expect(subject('1.y.3')).to be false
          expect(subject('1.2.z')).to be false
        end

        it 'rejects versions that contain negative integers' do
          expect(subject('-1.2.3')).to be false
          expect(subject('1.-2.3')).to be false
          expect(subject('1.2.-3')).to be false
        end

        it 'rejects version numbers containing leading zeroes' do
          expect(subject('01.2.3')).to be false
          expect(subject('1.02.3')).to be false
          expect(subject('1.2.03')).to be false
        end

        it 'permits zeroes in version number parts' do
          expect(subject('0.2.3')).to be true
          expect(subject('1.0.3')).to be true
          expect(subject('1.2.0')).to be true
        end
      end

      context 'Section 9' do
        # A pre-release version MAY be denoted by appending a hyphen and a
        # series of dot separated identifiers immediately following the patch
        # version. Identifiers MUST comprise only ASCII alphanumerics and
        # hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty. Numeric
        # identifiers MUST NOT include leading zeroes. Pre-release versions
        # have a lower precedence than the associated normal version. A
        # pre-release version indicates that the version is unstable and
        # might not satisfy the intended compatibility requirements as denoted
        # by its associated normal version.
        # Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92.

        it 'rejects prerelease identifiers with non-alphanumerics' do
          expect(subject('1.2.3-$100')).to be false
          expect(subject('1.2.3-rc.1@me')).to be false
        end

        it 'rejects empty prerelease versions' do
          expect(subject('1.2.3-')).to be false
        end

        it 'rejects empty prerelease version identifiers' do
          expect(subject('1.2.3-.rc1')).to be false
          expect(subject('1.2.3-rc1.')).to be false
          expect(subject('1.2.3-rc..1')).to be false
        end

        it 'rejects numeric prerelease identifiers with leading zeroes' do
          expect(subject('1.2.3-01')).to be false
          expect(subject('1.2.3-rc.01')).to be false
        end

        it 'permits numeric prerelease identifiers of zero' do
          expect(subject('1.2.3-0')).to be true
          expect(subject('1.2.3-rc.0')).to be true
        end

        it 'permits non-numeric prerelease identifiers' do
          expect(subject('1.2.3-DEADBEEF')).to be true
          expect(subject('1.2.3-DE.AD.BE.EF')).to be true
          expect(subject('2.1.0-12-BE-EF')).to be true
        end

        it 'permits non-numeric prerelease identifiers with leading zeroes' do
          expect(subject('1.2.3-0xDEADBEEF')).to be true
          expect(subject('1.2.3-rc.0x10c')).to be true
          expect(subject('2.1.0-0016-13fae4a9')).to be true
        end
      end

      context 'Section 10' do
        # Build metadata MAY be denoted by appending a plus sign and a series
        # of dot separated identifiers immediately following the patch or
        # pre-release version. Identifiers MUST comprise only ASCII
        # alphanumerics and hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty.
        # Build metadata SHOULD be ignored when determining version precedence.
        # Thus two versions that differ only in the build metadata, have the
        # same precedence.
        # Examples: 1.0.0-alpha+001, 1.0.0+20130313144700,
        # 1.0.0-beta+exp.sha.5114f85.

        it 'rejects build identifiers with non-alphanumerics' do
          expect(subject('1.2.3+$100')).to be false
          expect(subject('1.2.3+rc.1@me')).to be false
        end

        it 'rejects empty build metadata' do
          expect(subject('1.2.3+')).to be false
        end

        it 'rejects empty build identifiers' do
          expect(subject('1.2.3+.rc1')).to be false
          expect(subject('1.2.3+rc1.')).to be false
          expect(subject('1.2.3+rc..1')).to be false
        end

        it 'permits numeric build identifiers with leading zeroes' do
          expect(subject('1.2.3+01')).to be true
          expect(subject('1.2.3+rc.01')).to be true
        end

        it 'permits numeric build identifiers of zero' do
          expect(subject('1.2.3+0')).to be true
          expect(subject('1.2.3+rc.0')).to be true
        end

        it 'permits non-numeric build identifiers with leading zeroes' do
          expect(subject('1.2.3+0xDEADBEEF')).to be true
          expect(subject('1.2.3+rc.0x10c')).to be true
        end
      end
    end

    context 'Spec v1.0.0' do
      context 'Section 2' do
        # A normal version number MUST take the form X.Y.Z where X, Y, and Z
        # are integers. X is the major version, Y is the minor version, and Z
        # is the patch version.

        it 'rejects versions that contain too few parts' do
          expect(subject('1.2')).to be false
        end

        it 'rejects versions that contain too many parts' do
          expect(subject('1.2.3.4')).to be false
        end

        it 'rejects versions that contain non-integers' do
          expect(subject('x.2.3')).to be false
          expect(subject('1.y.3')).to be false
          expect(subject('1.2.z')).to be false
        end

        it 'permits zeroes in version number parts' do
          expect(subject('0.2.3')).to be true
          expect(subject('1.0.3')).to be true
          expect(subject('1.2.0')).to be true
        end
      end

      context 'Section 4' do
        # A pre-release version number MAY be denoted by appending an arbitrary
        # string immediately following the patch version and a dash. The string
        # MUST be comprised of only alphanumerics plus dash [0-9A-Za-z-].
        # Pre-release versions satisfy but have a lower precedence than the
        # associated normal version. Precedence SHOULD be determined by
        # lexicographic ASCII sort order.
        # For instance: 1.0.0-alpha1 < 1.0.0-beta1 < 1.0.0-beta2 < 1.0.0-rc1

        it 'rejects prerelease identifiers with non-alphanumerics' do
          expect(subject('1.2.3-$100')).to be false
          expect(subject('1.2.3-rc.1@me')).to be false
        end

        it 'rejects empty prerelease versions' do
          expect(subject('1.2.3-')).to be false
        end

        it 'rejects numeric prerelease identifiers with leading zeroes' do
          expect(subject('1.2.3-01')).to be false
        end

        it 'permits numeric prerelease identifiers of zero' do
          expect(subject('1.2.3-0')).to be true
        end

        it 'permits non-numeric prerelease identifiers with leading zeroes' do
          expect(subject('1.2.3-0xDEADBEEF')).to be true
        end
      end
    end
  end

  describe '#==' do
    def parse(vstring)
      SemanticPuppet::Version.parse(vstring)
    end

    it 'should yield true when comparing two equal instances' do
      x = parse('1.2.3-alpha')
      y = parse('1.2.3-alpha')
      expect(x == y).to eql(true)
    end

    it 'should yield false when the major differs' do
      x = parse('1.2.3-alpha')
      y = parse('2.2.3-alpha')
      expect(x == y).to eql(false)
    end

    it 'should yield false when the minor differs' do
      x = parse('1.2.3-alpha')
      y = parse('1.3.3-alpha')
      expect(x == y).to eql(false)
    end

    it 'should yield false when the patch differs' do
      x = parse('1.2.3-alpha')
      y = parse('1.2.4-alpha')
      expect(x == y).to eql(false)
    end

    it 'should yield false when the prerelease differs' do
      x = parse('1.2.3-alpha')
      y = parse('1.2.3-beta')
      expect(x == y).to eql(false)
    end

    it 'should yield false when compared to something that is not a Version' do
      x = parse('1.2.3-alpha')
      expect(x == :undef).to eql(false)
    end
  end

  describe '#<=>' do
    def parse(vstring)
      SemanticPuppet::Version.parse(vstring)
    end

    context 'Spec v2.0.0' do
      context 'Section 11' do
        # Precedence refers to how versions are compared to each other when
        # ordered. Precedence MUST be calculated by separating the version into
        # major, minor, patch and pre-release identifiers in that order (Build
        # metadata does not figure into precedence). Precedence is determined
        # by the first difference when comparing each of these identifiers from
        # left to right as follows: Major, minor, and patch versions are always
        # compared numerically.
        # Example: 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1.
        # When major, minor, and patch are equal, a pre-release version has
        # lower precedence than a normal version.
        # Example: 1.0.0-alpha < 1.0.0.
        # Precedence for two pre-release versions with the same major, minor,
        # and patch version MUST be determined by comparing each dot separated
        # identifier from left to right until a difference is found as follows:
        # identifiers consisting of only digits are compared numerically and
        # identifiers with letters or hyphens are compared lexically in ASCII
        # sort order. Numeric identifiers always have lower precedence than
        # non-numeric identifiers. A larger set of pre-release fields has a
        # higher precedence than a smaller set, if all of the preceding
        # identifiers are equal.
        # Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta
        # < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.

        context 'comparisons without prereleases' do
          subject do
            %w[ 1.0.0 2.0.0 2.1.0 2.1.1 ].map { |v| parse(v) }.shuffle
          end

          example 'sorted order' do
            sorted = subject.sort.map { |v| v.to_s }
            expect(sorted).to eql(%w[ 1.0.0 2.0.0 2.1.0 2.1.1 ])
          end
        end

        context 'comparisons against prereleases' do
          let(:stable) { parse('1.0.0') }
          let(:prerelease) { parse('1.0.0-alpha') }

          example 'prereleases have lower precedence' do
            expect(stable).to be > prerelease
            expect(prerelease).to be < stable
          end
        end

        context 'comparisions between prereleases' do
          example 'identical prereleases are equal' do
            expect(parse('1.0.0-rc1')).to eql parse('1.0.0-rc1')
          end

          example 'non-numeric identifiers sort ASCIIbetically' do
            alpha, beta = parse('1.0.0-alpha'), parse('1.0.0-beta')
            expect(alpha).to be < beta
            expect(beta).to be > alpha
          end

          example 'numeric identifiers sort numerically' do
            two, eleven = parse('1.0.0-2'), parse('1.0.0-11')
            expect(two).to be < eleven
            expect(eleven).to be > two
          end

          example 'non-numeric identifiers have a higher precendence' do
            number, word = parse('1.0.0-1'), parse('1.0.0-one')
            expect(number).to be < word
            expect(word).to be > number
          end

          example 'identifiers are parsed left-to-right' do
            a = parse('1.0.0-these.parts.are.the-same.but.not.waffles.123')
            b = parse('1.0.0-these.parts.are.the-same.but.not.123.waffles')
            expect(b).to be < a
            expect(a).to be > b
          end

          example 'larger identifier sets have precendence' do
            a = parse('1.0.0-alpha')
            b = parse('1.0.0-alpha.1')
            expect(a).to be < b
            expect(b).to be > a
          end

          example 'build metadata does figure into equality' do
            a = parse('1.0.0-alpha+SHA1')
            b = parse('1.0.0-alpha+MD5')
            expect(a).not_to eql b
            expect(a.to_s).to_not eql b.to_s
          end

          example 'build metadata does not figure into precendence' do
            a = parse('1.0.0-alpha+SHA1')
            b = parse('1.0.0-alpha+MD5')
            expect(a <=> b).to eql(0)
          end

          example 'sorted order' do
            list = %w[
              1.0.0-alpha
              1.0.0-alpha.1
              1.0.0-alpha.beta
              1.0.0-beta
              1.0.0-beta.2
              1.0.0-beta.11
              1.0.0-rc.1
              1.0.0
            ].map { |v| parse(v) }.shuffle

            sorted = list.sort.map { |v| v.to_s }
            expect(sorted).to eql %w[
              1.0.0-alpha
              1.0.0-alpha.1
              1.0.0-alpha.beta
              1.0.0-beta
              1.0.0-beta.2
              1.0.0-beta.11
              1.0.0-rc.1
              1.0.0
            ]
          end
        end
      end
    end

    context 'Spec v1.0.0' do
      context 'Section 4' do
        # A pre-release version number MAY be denoted by appending an arbitrary
        # string immediately following the patch version and a dash. The string
        # MUST be comprised of only alphanumerics plus dash [0-9A-Za-z-].
        # Pre-release versions satisfy but have a lower precedence than the
        # associated normal version. Precedence SHOULD be determined by
        # lexicographic ASCII sort order.
        # For instance: 1.0.0-alpha1 < 1.0.0-beta1 < 1.0.0-beta2 < 1.0.0-rc1 <
        # 1.0.0

        example 'sorted order' do
          list = %w[
            1.0.0-alpha1
            1.0.0-beta1
            1.0.0-beta2
            1.0.0-rc1
            1.0.0
          ].map { |v| parse(v) }.shuffle

          sorted = list.sort.map { |v| v.to_s }
          expect(sorted).to eql %w[
            1.0.0-alpha1
            1.0.0-beta1
            1.0.0-beta2
            1.0.0-rc1
            1.0.0
          ]
        end
      end
    end

  end

  describe '#next' do
    context 'with :major' do
      it 'returns the next major version' do
        expect(subject('1.0.0').next(:major)).to eql(subject('2.0.0'))
      end

      it 'does not modify the original version' do
        v1 = subject('1.0.0')
        v2 = v1.next(:major)
        expect(v1).to_not eql(v2)
      end

      it 'resets the minor and patch versions to 0' do
        expect(subject('1.1.1').next(:major)).to eql(subject('2.0.0'))
      end

      it 'removes any prerelease information' do
        expect(subject('1.0.0-alpha').next(:major)).to eql(subject('2.0.0'))
      end

      it 'removes any build information' do
        expect(subject('1.0.0+abc').next(:major)).to eql(subject('2.0.0'))
      end
    end

    context 'with :minor' do
      it 'returns the next minor version' do
        expect(subject('1.0.0').next(:minor)).to eql(subject('1.1.0'))
      end

      it 'does not modify the original version' do
        v1 = subject('1.0.0')
        v2 = v1.next(:minor)
        expect(v1).to_not eql(v2)
      end

      it 'resets the patch version to 0' do
        expect(subject('1.1.1').next(:minor)).to eql(subject('1.2.0'))
      end

      it 'removes any prerelease information' do
        expect(subject('1.1.0-alpha').next(:minor)).to eql(subject('1.2.0'))
      end

      it 'removes any build information' do
        expect(subject('1.1.0+abc').next(:minor)).to eql(subject('1.2.0'))
      end
    end

    context 'with :patch' do
      it 'returns the next patch version' do
        expect(subject('1.1.1').next(:patch)).to eql(subject('1.1.2'))
      end

      it 'does not modify the original version' do
        v1 = subject('1.0.0')
        v2 = v1.next(:patch)
        expect(v1).to_not eql(v2)
      end

      it 'removes any prerelease information' do
        expect(subject('1.0.0-alpha').next(:patch)).to eql(subject('1.0.1'))
      end

      it 'removes any build information' do
        expect(subject('1.0.0+abc').next(:patch)).to eql(subject('1.0.1'))
      end
    end
  end
end