-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(semver): add missing tests #6362
base: main
Are you sure you want to change the base?
Changes from all commits
1383839
0b3ba59
6e447bc
06d2250
c05d863
67fe705
4fa8705
4b7ecbf
fb67093
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
// Copyright 2018-2025 the Deno authors. MIT license. | ||
// Copyright Isaac Z. Schlueter and npm contributors. All rights reserved. ISC license. | ||
|
||
import { assert, assertFalse } from "@std/assert"; | ||
import { assert, assertEquals, assertFalse } from "@std/assert"; | ||
import { | ||
format, | ||
formatRange, | ||
greaterThanRange, | ||
parse, | ||
parseRange, | ||
} from "./mod.ts"; | ||
import type { Operator } from "./types.ts"; | ||
|
||
Deno.test("greaterThanRange() checks if the semver is greater than the range", async (t) => { | ||
// from https://github.com/npm/node-semver/blob/692451bd6f75b38a71a99f39da405c94a5954a22/test/fixtures/version-gt-range.js | ||
|
@@ -167,3 +168,43 @@ Deno.test("greaterThanRange() checks if the semver is greater than the range", a | |
}); | ||
} | ||
}); | ||
|
||
Deno.test("greaterThanRange() handles equals operator", () => { | ||
const version = { | ||
major: 1, | ||
minor: 0, | ||
patch: 0, | ||
prerelease: [], | ||
build: [], | ||
}; | ||
const range = [[{ | ||
operator: "=" as unknown as Operator, | ||
major: 1, | ||
minor: 0, | ||
patch: 0, | ||
prerelease: [], | ||
build: [], | ||
}]]; | ||
assertEquals(greaterThanRange(version, range), false); | ||
}); | ||
|
||
// BUG `!=` operator type does not exist in semver and should be removed. | ||
// TODO remove this test once `!=` operator is removed. | ||
Deno.test("greaterThanRange() handles not equals operator", () => { | ||
const version = { | ||
major: 1, | ||
minor: 0, | ||
patch: 0, | ||
prerelease: [], | ||
build: [], | ||
}; | ||
const range = [[{ | ||
operator: "!=" as unknown as Operator, | ||
major: 1, | ||
minor: 0, | ||
patch: 0, | ||
prerelease: [], | ||
build: [], | ||
}]]; | ||
assertEquals(greaterThanRange(version, range), true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this result is correct I also just realized I'd suggest we should skip this particular test case for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of skipping, we probably should add the test and remove it when handling the problem/bug. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then can you add a TODO comment above the test title, which says that this is a bug, not an intentional behavior? |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
// Copyright 2018-2025 the Deno authors. MIT license. | ||
// Copyright Isaac Z. Schlueter and npm contributors. All rights reserved. ISC license. | ||
|
||
import { assert, assertFalse } from "@std/assert"; | ||
import { assert, assertEquals, assertFalse } from "@std/assert"; | ||
import { | ||
format, | ||
formatRange, | ||
lessThanRange, | ||
type Operator, | ||
parse, | ||
parseRange, | ||
} from "./mod.ts"; | ||
|
@@ -169,3 +170,22 @@ Deno.test("lessThanRange() checks if the SemVer is less than the range", async ( | |
}); | ||
} | ||
}); | ||
|
||
Deno.test("lessThanRange() handles not equals operator", () => { | ||
const version = { | ||
major: 1, | ||
minor: 0, | ||
patch: 0, | ||
prerelease: [], | ||
build: [], | ||
}; | ||
const range = [[{ | ||
operator: "!=" as unknown as Operator, | ||
major: 1, | ||
minor: 0, | ||
patch: 0, | ||
prerelease: [], | ||
build: [], | ||
}]]; | ||
assertEquals(lessThanRange(version, range), true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This result feels wrong to me. I'd suggest skipping this test case for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should not skip test cases if they yield unexpected results but fix them instead. What would the proper result be? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The range There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to create a PR to remove the |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -666,3 +666,24 @@ Deno.test("parseRange() throws on invalid range", () => { | |
'Cannot parse version range: range "blerg" is invalid', | ||
); | ||
}); | ||
|
||
Deno.test("parseRange() handles wildcards", () => { | ||
assertEquals(parseRange("<1.*"), [ | ||
[{ operator: "<", major: 1, minor: 0, patch: 0 }], | ||
]); | ||
assertEquals(parseRange("<1.*.0"), [ | ||
[{ operator: "<", major: 1, minor: NaN, patch: 0 }], | ||
]); | ||
Comment on lines
+671
to
+676
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The difference of these 2 results seem strange to me. Is this intentionally in this way? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems indeed wrong. Imo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took a closer look at this, |
||
assertEquals(parseRange("<1.*.*"), [ | ||
[{ operator: "<", major: 1, minor: 0, patch: 0 }], | ||
]); | ||
assertEquals(parseRange(">=1.*.0"), [ | ||
[{ operator: ">=", major: 1, minor: NaN, patch: 0 }], | ||
]); | ||
assertEquals(parseRange(">=1.*.*"), [ | ||
[{ operator: ">=", major: 1, minor: 0, patch: 0 }], | ||
]); | ||
assertEquals(parseRange(">=1.0.*"), [ | ||
[{ operator: ">=", major: 1, minor: 0, patch: 0 }], | ||
]); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2018-2025 the Deno authors. MIT license. | ||
|
||
import { assertEquals } from "@std/assert"; | ||
import { tryParseRange } from "./try_parse_range.ts"; | ||
import type { Range } from "./types.ts"; | ||
|
||
Deno.test("tryParseRange()", () => { | ||
const actual = tryParseRange(">=1.2.3 <1.2.4"); | ||
const expected: Range = [ | ||
[ | ||
{ | ||
operator: ">=", | ||
major: 1, | ||
minor: 2, | ||
patch: 3, | ||
prerelease: [], | ||
build: [], | ||
}, | ||
{ | ||
operator: "<", | ||
major: 1, | ||
minor: 2, | ||
patch: 4, | ||
prerelease: [], | ||
build: [], | ||
}, | ||
], | ||
]; | ||
assertEquals(actual, expected); | ||
}); | ||
|
||
Deno.test("tryParseRange() handles invalid range", () => { | ||
assertEquals(tryParseRange("blerg"), undefined); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case looks comparing invalid semvers. I don't think this is an intentional behavior, but an undefined behavior. I'd suggest we should remove this test case.