Skip to content

Commit ba223e5

Browse files
committed
test: Add cases for mixed semantic and non-semantic version comparisons
1 parent 199bcd6 commit ba223e5

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

packages/durabletask-js/test/versioning.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,49 @@ describe("compareVersions", () => {
106106
expect(compareVersions("1", "1")).toBe(0);
107107
});
108108
});
109+
110+
describe("mixed semantic and non-semantic versions", () => {
111+
it("should fall back to lexicographic when one version is semver and other is not", () => {
112+
// "1.0.0" is valid semver, "alpha" is not - should use lexicographic comparison
113+
// "1" < "a" in ASCII, so "1.0.0" < "alpha" lexicographically
114+
expect(compareVersions("1.0.0", "alpha")).toBeLessThan(0);
115+
expect(compareVersions("alpha", "1.0.0")).toBeGreaterThan(0);
116+
});
117+
118+
it("should handle semver vs prefixed version strings", () => {
119+
// "1.0.0" is valid semver, "v1.0.0" is not (has 'v' prefix)
120+
// Falls back to lexicographic: "1" < "v"
121+
expect(compareVersions("1.0.0", "v1.0.0")).toBeLessThan(0);
122+
expect(compareVersions("v1.0.0", "1.0.0")).toBeGreaterThan(0);
123+
});
124+
125+
it("should handle semver vs pre-release style versions", () => {
126+
// "2.0.0" is valid semver, "1.0.0-beta" is not (has "-beta" suffix)
127+
// Falls back to lexicographic: "2" > "1"
128+
expect(compareVersions("2.0.0", "1.0.0-beta")).toBeGreaterThan(0);
129+
expect(compareVersions("1.0.0-beta", "2.0.0")).toBeLessThan(0);
130+
});
131+
132+
it("should handle semver vs text-only versions", () => {
133+
// Comparing numeric semver with pure text versions
134+
expect(compareVersions("1.0.0", "latest")).toBeLessThan(0);
135+
expect(compareVersions("latest", "1.0.0")).toBeGreaterThan(0);
136+
expect(compareVersions("2.5.0", "stable")).toBeLessThan(0);
137+
expect(compareVersions("stable", "2.5.0")).toBeGreaterThan(0);
138+
});
139+
140+
it("should handle semver vs versions with build metadata", () => {
141+
// "1.0.0" is valid semver, "1.0.0+build123" is not (has build metadata)
142+
// Falls back to lexicographic
143+
expect(compareVersions("1.0.0", "1.0.0+build123")).toBeLessThan(0);
144+
expect(compareVersions("1.0.0+build123", "1.0.0")).toBeGreaterThan(0);
145+
});
146+
147+
it("should handle numeric semver vs alphanumeric non-semver", () => {
148+
// "3.0.0" is valid semver, "3.0.0rc1" is not (no separator before rc)
149+
// Falls back to lexicographic: "3.0.0" < "3.0.0rc1"
150+
expect(compareVersions("3.0.0", "3.0.0rc1")).toBeLessThan(0);
151+
expect(compareVersions("3.0.0rc1", "3.0.0")).toBeGreaterThan(0);
152+
});
153+
});
109154
});

0 commit comments

Comments
 (0)