build-a-semver-parser / lesson-11.md
Lesson 11 · Version precedence

Build metadata is ignored, and equality

Two versions that differ only in build metadata are the same release, so they compare equal. Today you confirm that your compare ignores build entirely and add an Equal helper that reads naturally.

The goal

Add Equal on top of Compare and confirm build metadata never changes precedence.

Start here - the target
TO DO
Scenario: Build metadata does not affect precedence
Givenversions that differ only in build metadata
Whenthey are compared
ThenCompare(1.0.0+build.1, 1.0.0+build.2) is 0 and Equal(1.0.0+build.1, 1.0.0+build.2) is true
AndEqual(1.0.0, 1.0.0-alpha) is false and Equal(1.2.3, 1.2.3) is true
Background

The SemVer spec is explicit: build metadata must be ignored when determining version precedence. Two versions that differ only after the + - 1.0.0+build.1 and 1.0.0+build.2 - are the very same release built two different ways, so they compare equal. This is exactly why build identifiers were allowed to have leading zeros back in the parsing chapter: since they never affect ordering, there is no ambiguity to prevent.

If your Compare is written correctly it already satisfies this, because it only ever looks at the core numbers and the prerelease - it has no reason to read Build at all. So today is a confirmation beat with a small addition: prove that two build-only-different versions compare equal, and wrap the result in an Equal helper (Compare(a, b) == 0) that makes intent obvious at call sites and reads better than a bare == 0. Note the contrast the spec draws: build metadata is invisible to ordering, but a prerelease is not - 1.0.0 and 1.0.0-alpha are genuinely different releases, so Equal on them is false.

Make it work
// Compare already reads only Major/Minor/Patch and Prerelease - it never touches Build.
// So versions differing only in build are already equal; today just confirm it and add:
func Equal(a, b Version) bool { return Compare(a, b) == 0 }
CheckpointDONE
Build metadata is confirmed irrelevant to ordering, and Equal reads cleanly. Commit and stop here.