tests/testthat/test-gtr.r

context("gtr")

gtr_tests <-   list(
  list('~1.2.2', '1.3.0'),
  list('~0.6.1-1', '0.7.1-1'),
  list('1.0.0 - 2.0.0', '2.0.1'),
  list('1.0.0', '1.0.1-beta1'),
  list('1.0.0', '2.0.0'),
  list('<=2.0.0', '2.1.1'),
  list('<=2.0.0', '3.2.9'),
  list('<2.0.0', '2.0.0'),
  list('0.1.20 || 1.2.4', '1.2.5'),
  list('2.x.x', '3.0.0'),
  list('1.2.x', '1.3.0'),
  list('1.2.x || 2.x', '3.0.0'),
  list('2.*.*', '5.0.1'),
  list('1.2.*', '1.3.3'),
  list('1.2.* || 2.*', '4.0.0'),
  list('2', '3.0.0'),
  list('2.3', '2.4.2'),
  list('~2.4', '2.5.0'), ## >=2.4.0 <2.5.0
  list('~2.4', '2.5.5'),
  list('~>3.2.1', '3.3.0'), ## >=3.2.1 <3.3.0
  list('~1', '2.2.3'), ## >=1.0.0 <2.0.0
  list('~>1', '2.2.4'),
  list('~> 1', '3.2.3'),
  list('~1.0', '1.1.2'), ## >=1.0.0 <1.1.0
  list('~ 1.0', '1.1.0'),
  list('<1.2', '1.2.0'),
  list('< 1.2', '1.2.1'),
  list('1', '2.0.0beta', TRUE),
  list('~v0.5.4-pre', '0.6.0'),
  list('~v0.5.4-pre', '0.6.1-pre'),
  list('=0.7.x', '0.8.0'),
  list('=0.7.x', '0.8.0-asdf'),
  list('<=0.7.x', '0.7.0'),
  list('~1.2.2', '1.3.0'),
  list('1.0.0 - 2.0.0', '2.2.3'),
  list('1.0.0', '1.0.1'),
  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('2.x.x', '3.1.3'),
  list('1.2.x', '1.3.3'),
  list('1.2.x || 2.x', '3.1.3'),
  list('2.*.*', '3.1.3'),
  list('1.2.*', '1.3.3'),
  list('1.2.* || 2.*', '3.1.3'),
  list('2', '3.1.2'),
  list('2.3', '2.4.1'),
  list('~2.4', '2.5.0'), ## >=2.4.0 <2.5.0
  list('~>3.2.1', '3.3.2'), ## >=3.2.1 <3.3.0
  list('~1', '2.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.0.0beta', TRUE),
  list('<1', '1.0.0beta', TRUE),
  list('< 1', '1.0.0beta', TRUE),
  list('=0.7.x', '0.8.2'),
  list('<=0.7.x', '0.7.2')
)

test_that("gtr", {

  sapply(gtr_tests, function(args) {
    range <- args[[1]]
    version <- args[[2]]
    loose <- if (length(args) == 3) args[[3]] else FALSE
    expect_true(gtr(version, range, loose),
                info = paste(args, collapse = ","))
  })

})

context("gtr negative")

gtr2_tests <-   list(
    list('~0.6.1-1', '0.6.1-1'),
    list('1.0.0 - 2.0.0', '1.2.3'),
    list('1.0.0 - 2.0.0', '0.9.9'),
    list('1.0.0', '1.0.0'),
    list('>=*', '0.2.4'),
    list('', '1.0.0', TRUE),
    list('*', '1.2.3'),
    list('*', 'v1.2.3-foo'),
    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'),
    list('>=0.1.97', '0.1.97'),
    list('0.1.20 || 1.2.4', '1.2.4'),
    list('0.1.20 || >1.2.4', '1.2.4'),
    list('0.1.20 || 1.2.4', '1.2.3'),
    list('0.1.20 || 1.2.4', '0.1.20'),
    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.* || 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', '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('>0.2.3 >0.2.4 <=0.2.5', '0.2.5'),
    list('>=0.2.3 <=0.2.4', '0.2.4'),
    list('1.0.0 - 2.0.0', '2.0.0'),
    list('^1', '0.0.0-0'),
    list('^3.0.0', '2.0.0'),
    list('^1.0.0 || ~2.0.1', '2.0.0'),
    list('^0.1.0 || ~3.0.1 || 5.0.0', '3.2.0'),
    list('^0.1.0 || ~3.0.1 || 5.0.0', '1.0.0beta', TRUE),
    list('^0.1.0 || ~3.0.1 || 5.0.0', '5.0.0-0', TRUE),
    list('^0.1.0 || ~3.0.1 || >4 <=5.0.0', '3.5.0')
)

test_that("gtr negative", {

  sapply(gtr2_tests, function(args) {
    range <- args[[1]]
    version <- args[[2]]
    loose <- if (length(args) == 3) args[[3]] else FALSE
    expect_false(gtr(version, range, loose),
                 info = paste(args, collapse = ", "))
  })

})
metacran/semver documentation built on May 22, 2019, 7:48 p.m.