|
34 | 34 | end |
35 | 35 | end |
36 | 36 |
|
| 37 | + # The build number is allowed to exceed 10^build_digits. The docstring guarantees ordering still |
| 38 | + # holds in that case (overflow "only costs human-readability, not ordering") *because* the build |
| 39 | + # number is globally monotonic. These lock that in — and guard against a future change such as |
| 40 | + # masking the build number with `% 10**build_digits`, which would silently break ordering. |
| 41 | + context 'when the build number overflows its reserved digits (10^build_digits)' do |
| 42 | + it 'still increases within the same version across the overflow boundary' do |
| 43 | + formatter = described_class.new(build_digits: 4) # 10^4 = 10_000 |
| 44 | + # 269 * 10_000 + 10_000 = 2_700_000 vs 269 * 10_000 + 9_999 = 2_699_999 |
| 45 | + expect(formatter.build_code(major: 26, minor: 9, build_number: 10_000)) |
| 46 | + .to be > formatter.build_code(major: 26, minor: 9, build_number: 9_999) |
| 47 | + end |
| 48 | + |
| 49 | + it 'still increases across a version bump while both build numbers are past the overflow point' do |
| 50 | + formatter = described_class.new(build_digits: 4) # 10^4 = 10_000 |
| 51 | + # 270 * 10_000 + 25_001 = 2_725_001 vs 269 * 10_000 + 25_000 = 2_715_000 |
| 52 | + expect(formatter.build_code(major: 27, minor: 0, build_number: 25_001)) |
| 53 | + .to be > formatter.build_code(major: 26, minor: 9, build_number: 25_000) |
| 54 | + end |
| 55 | + |
| 56 | + it 'can render identically to a later version once overflowed — the documented readability cost, which is harmless under a monotonic build number' do |
| 57 | + formatter = described_class.new(build_digits: 4) # 10^4 = 10_000 |
| 58 | + # Overflow makes the digits ambiguous: 26.9 build 10_000 and 27.0 build 0 both come out as 2_700_000. |
| 59 | + # That's the "only costs human-readability" caveat — and it's safe because a globally monotonic |
| 60 | + # build number means (27, 0, build: 0) never *follows* (26, 9, build: 10_000); the counter only goes up. |
| 61 | + expect(formatter.build_code(major: 26, minor: 9, build_number: 10_000)) |
| 62 | + .to eq(formatter.build_code(major: 27, minor: 0, build_number: 0)) |
| 63 | + end |
| 64 | + end |
| 65 | + |
37 | 66 | describe 'validation' do |
38 | 67 | it 'raises when minor is greater than 9' do |
39 | 68 | expect { described_class.new.build_code(major: 26, minor: 10, build_number: 1) } |
|
0 commit comments