context("Positive ranges")
tests <- list(
list('1.0.0 - 2.0.0', '1.2.3'),
list('1.0.0', '1.0.0'),
list('>=*', '0.2.4'),
list('', '1.0.0'),
list('*', '1.2.3'),
list('*', 'v1.2.3-foo', TRUE),
list('>=1.0.0', '1.0.0'),
list('>=1.0.0', '1.0.1'),
list('>=1.0.0', '1.1.0'),
list('>1.0.0', '1.0.1'),
list('>1.0.0', '1.1.0'),
list('<=2.0.0', '2.0.0'),
list('<=2.0.0', '1.9999.9999'),
list('<=2.0.0', '0.2.9'),
list('<2.0.0', '1.9999.9999'),
list('<2.0.0', '0.2.9'),
list('>= 1.0.0', '1.0.0'),
list('>= 1.0.0', '1.0.1'),
list('>= 1.0.0', '1.1.0'),
list('> 1.0.0', '1.0.1'),
list('> 1.0.0', '1.1.0'),
list('<= 2.0.0', '2.0.0'),
list('<= 2.0.0', '1.9999.9999'),
list('<= 2.0.0', '0.2.9'),
list('< 2.0.0', '1.9999.9999'),
list('<\t2.0.0', '0.2.9'),
list('>=0.1.97', 'v0.1.97', TRUE),
list('>=0.1.97', '0.1.97'),
list('0.1.20 || 1.2.4', '1.2.4'),
list('>=0.2.3 || <0.0.1', '0.0.0'),
list('>=0.2.3 || <0.0.1', '0.2.3'),
list('>=0.2.3 || <0.0.1', '0.2.4'),
list('||', '1.3.4'),
list('2.x.x', '2.1.3'),
list('1.2.x', '1.2.3'),
list('1.2.x || 2.x', '2.1.3'),
list('1.2.x || 2.x', '1.2.3'),
list('x', '1.2.3'),
list('2.*.*', '2.1.3'),
list('1.2.*', '1.2.3'),
list('1.2.* || 2.*', '2.1.3'),
list('1.2.* || 2.*', '1.2.3'),
list('*', '1.2.3'),
list('2', '2.1.2'),
list('2.3', '2.3.1'),
list('~2.4', '2.4.0'), ## >=2.4.0 <2.5.0
list('~2.4', '2.4.5'),
list('~>3.2.1', '3.2.2'), ## >=3.2.1 <3.3.0,
list('~1', '1.2.3'), ## >=1.0.0 <2.0.0
list('~>1', '1.2.3'),
list('~> 1', '1.2.3'),
list('~1.0', '1.0.2'), ## >=1.0.0 <1.1.0,
list('~ 1.0', '1.0.2'),
list('~ 1.0.3', '1.0.12'),
list('>=1', '1.0.0'),
list('>= 1', '1.0.0'),
list('<1.2', '1.1.1'),
list('< 1.2', '1.1.1'),
list('1', '1.0.0beta', TRUE),
list('~v0.5.4-pre', '0.5.5'),
list('~v0.5.4-pre', '0.5.4'),
list('=0.7.x', '0.7.2'),
list('>=0.7.x', '0.7.2'),
list('=0.7.x', '0.7.0-asdf'),
list('>=0.7.x', '0.7.0-asdf'),
list('<=0.7.x', '0.6.2'),
list('~1.2.1 >=1.2.3', '1.2.3'),
list('~1.2.1 =1.2.3', '1.2.3'),
list('~1.2.1 1.2.3', '1.2.3'),
list('~1.2.1 >=1.2.3 1.2.3', '1.2.3'),
list('~1.2.1 1.2.3 >=1.2.3', '1.2.3'),
list('~1.2.1 1.2.3', '1.2.3'),
list('>=1.2.1 1.2.3', '1.2.3'),
list('1.2.3 >=1.2.1', '1.2.3'),
list('>=1.2.3 >=1.2.1', '1.2.3'),
list('>=1.2.1 >=1.2.3', '1.2.3'),
list('<=1.2.3', '1.2.3-beta'),
list('>1.2', '1.3.0-beta'),
list('>=1.2', '1.2.8'),
list('^1.2.3', '1.8.1'),
list('^1.2.3', '1.2.3-beta'),
list('^0.1.2', '0.1.2'),
list('^0.1', '0.1.2'),
list('^1.2', '1.4.2'),
list('^1.2 ^1', '1.4.2'),
list('^1.2', '1.2.0-pre'),
list('^1.2.3', '1.2.3-pre')
)
test_that("positive ranges", {
sapply(tests, function(args) {
args[1:2] <- args[2:1]
expect_true(do.call(satisfies, args),
info = paste(args, collapse = ", "))
})
})
context("Negative ranges")
ntests <- list(
list('1.0.0 - 2.0.0', '2.2.3'),
list('1.0.0', '1.0.1'),
list('>=1.0.0', '0.0.0'),
list('>=1.0.0', '0.0.1'),
list('>=1.0.0', '0.1.0'),
list('>1.0.0', '0.0.1'),
list('>1.0.0', '0.1.0'),
list('<=2.0.0', '3.0.0'),
list('<=2.0.0', '2.9999.9999'),
list('<=2.0.0', '2.2.9'),
list('<2.0.0', '2.9999.9999'),
list('<2.0.0', '2.2.9'),
list('>=0.1.97', 'v0.1.93', TRUE),
list('>=0.1.97', '0.1.93'),
list('0.1.20 || 1.2.4', '1.2.3'),
list('>=0.2.3 || <0.0.1', '0.0.3'),
list('>=0.2.3 || <0.0.1', '0.2.2'),
list('2.x.x', '1.1.3'),
list('2.x.x', '3.1.3'),
list('1.2.x', '1.3.3'),
list('1.2.x || 2.x', '3.1.3'),
list('1.2.x || 2.x', '1.1.3'),
list('2.*.*', '1.1.3'),
list('2.*.*', '3.1.3'),
list('1.2.*', '1.3.3'),
list('1.2.* || 2.*', '3.1.3'),
list('1.2.* || 2.*', '1.1.3'),
list('2', '1.1.2'),
list('2.3', '2.4.1'),
list('~2.4', '2.5.0'), ## >=2.4.0 <2.5.0
list('~2.4', '2.3.9'),
list('~>3.2.1', '3.3.2'), ## >=3.2.1 <3.3.0
list('~>3.2.1', '3.2.0'), ## >=3.2.1 <3.3.0
list('~1', '0.2.3'), ## >=1.0.0 <2.0.0
list('~>1', '2.2.3'),
list('~1.0', '1.1.0'), ## >=1.0.0 <1.1.0
list('<1', '1.0.0'),
list('>=1.2', '1.1.1'),
list('1', '2.0.0beta', TRUE),
list('~v0.5.4-beta', '0.5.4-alpha'),
list('<1', '1.0.0beta', TRUE),
list('< 1', '1.0.0beta', TRUE),
list('=0.7.x', '0.8.2'),
list('>=0.7.x', '0.6.2'),
list('<=0.7.x', '0.7.2'),
list('<1.2.3', '1.2.3-beta'),
list('=1.2.3', '1.2.3-beta'),
list('>1.2', '1.2.8'),
list('^1.2.3', '2.0.0-alpha'),
list('^1.2.3', '1.2.2'),
list('^1.2', '1.1.9'),
## invalid ranges never satisfied!
list('blerg', '1.2.3'),
list('git+https:##user:password0123@github.com/foo', '123.0.0', TRUE),
list('^1.2.3', '2.0.0-pre')
)
test_that("negative ranges", {
sapply(ntests, function(args) {
args[1:2] <- args[2:1]
expect_false(do.call(satisfies, args),
info = paste(args, collapse = ", "))
})
})
context("Valid ranges")
vtests <- list(
list('1.0.0 - 2.0.0', '>=1.0.0 <=2.0.0'),
list('1.0.0', '1.0.0'),
list('>=*', '>=0.0.0-0'),
list('', '*'),
list('*', '*'),
list('>=1.0.0', '>=1.0.0'),
list('>1.0.0', '>1.0.0'),
list('<=2.0.0', '<=2.0.0'),
list('1', '>=1.0.0-0 <2.0.0-0'),
list('<=2.0.0', '<=2.0.0'),
list('<=2.0.0', '<=2.0.0'),
list('<2.0.0', '<2.0.0-0'),
list('<2.0.0', '<2.0.0-0'),
list('>= 1.0.0', '>=1.0.0'),
list('>= 1.0.0', '>=1.0.0'),
list('>= 1.0.0', '>=1.0.0'),
list('> 1.0.0', '>1.0.0'),
list('> 1.0.0', '>1.0.0'),
list('<= 2.0.0', '<=2.0.0'),
list('<= 2.0.0', '<=2.0.0'),
list('<= 2.0.0', '<=2.0.0'),
list('< 2.0.0', '<2.0.0-0'),
list('< 2.0.0', '<2.0.0-0'),
list('>=0.1.97', '>=0.1.97'),
list('>=0.1.97', '>=0.1.97'),
list('0.1.20 || 1.2.4', '0.1.20||1.2.4'),
list('>=0.2.3 || <0.0.1', '>=0.2.3||<0.0.1-0'),
list('>=0.2.3 || <0.0.1', '>=0.2.3||<0.0.1-0'),
list('>=0.2.3 || <0.0.1', '>=0.2.3||<0.0.1-0'),
list('||', '||'),
list('2.x.x', '>=2.0.0-0 <3.0.0-0'),
list('1.2.x', '>=1.2.0-0 <1.3.0-0'),
list('1.2.x || 2.x', '>=1.2.0-0 <1.3.0-0||>=2.0.0-0 <3.0.0-0'),
list('1.2.x || 2.x', '>=1.2.0-0 <1.3.0-0||>=2.0.0-0 <3.0.0-0'),
list('x', '*'),
list('2.*.*', '>=2.0.0-0 <3.0.0-0'),
list('1.2.*', '>=1.2.0-0 <1.3.0-0'),
list('1.2.* || 2.*', '>=1.2.0-0 <1.3.0-0||>=2.0.0-0 <3.0.0-0'),
list('*', '*'),
list('2', '>=2.0.0-0 <3.0.0-0'),
list('2.3', '>=2.3.0-0 <2.4.0-0'),
list('~2.4', '>=2.4.0-0 <2.5.0-0'),
list('~2.4', '>=2.4.0-0 <2.5.0-0'),
list('~>3.2.1', '>=3.2.1-0 <3.3.0-0'),
list('~1', '>=1.0.0-0 <2.0.0-0'),
list('~>1', '>=1.0.0-0 <2.0.0-0'),
list('~> 1', '>=1.0.0-0 <2.0.0-0'),
list('~1.0', '>=1.0.0-0 <1.1.0-0'),
list('~ 1.0', '>=1.0.0-0 <1.1.0-0'),
list('^0', '>=0.0.0-0 <1.0.0-0'),
list('^ 1', '>=1.0.0-0 <2.0.0-0'),
list('^0.1', '>=0.1.0-0 <0.2.0-0'),
list('^1.0', '>=1.0.0-0 <2.0.0-0'),
list('^1.2', '>=1.2.0-0 <2.0.0-0'),
list('^0.0.1', '0.0.1'),
list('^0.0.1-beta', '0.0.1-beta'),
list('^0.1.2', '0.1.2'),
list('^1.2.3', '>=1.2.3-0 <2.0.0-0'),
list('^1.2.3-beta.4', '>=1.2.3-beta.4 <2.0.0-0'),
list('<1', '<1.0.0-0'),
list('< 1', '<1.0.0-0'),
list('>=1', '>=1.0.0-0'),
list('>= 1', '>=1.0.0-0'),
list('<1.2', '<1.2.0-0'),
list('< 1.2', '<1.2.0-0'),
list('1', '>=1.0.0-0 <2.0.0-0'),
list('>01.02.03', '>1.2.3', TRUE),
list('>01.02.03', NULL),
list('~1.2.3beta', '>=1.2.3-beta <1.3.0-0', TRUE),
list('~1.2.3beta', NULL),
list('^ 1.2 ^ 1', '>=1.2.0-0 <2.0.0-0 >=1.0.0-0 <2.0.0-0')
)
test_that("valid ranges", {
sapply(vtests, function(args) {
pre <- args[[1]]
wanted <- args[[2]]
loose <- if (length(args) == 3) args[[3]] else FALSE
expect_equal(valid_range(pre, loose), wanted,
info = paste(args, collapse = ", "))
})
})
lr_tests <- list(
list('>=01.02.03', '>=1.2.3'),
list('~1.02.03beta', '>=1.2.3-beta <1.3.0-0')
)
context("Strict vs loose ranges")
test_that("loose ranges", {
sapply(lr_tests, function(args) {
loose <- args[[1]]
comps <- args[[2]]
expect_error(range$new(loose), "Invalid")
expect_equal(range$new(loose, loose = TRUE)$range, comps)
})
})
context("Max satisfying")
test_that("max_satisfying", {
mtests <- list(
list(list('1.2.3', '1.2.4'), '1.2', '1.2.4'),
list(list('1.2.4', '1.2.3'), '1.2', '1.2.4'),
list(list('1.2.3', '1.2.4', '1.2.5', '1.2.6'), '~1.2.3', '1.2.6'),
list(list('1.1.0', '1.2.0', '1.2.1', '1.3.0', '2.0.0b1', '2.0.0b2',
'2.0.0b3', '2.0.0', '2.1.0'), '~2.0.0', '2.0.0', TRUE)
)
sapply(mtests, function(args) {
versions <- args[[1]]
range <- args[[2]]
expect <- args[[3]]
loose <- if (length(args) == 4) args[[4]] else FALSE
actual <- max_satisfying(versions, range, loose)
expect_equal(actual, expect, info = paste(args, collapse = ","))
})
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.