|
1 | | -test_that("version() returns version based on $schema", { |
2 | | - p <- create_package() |
| 1 | +test_that("version() returns correct version for Data Package", { |
| 2 | + package <- create_package() |
3 | 3 |
|
4 | | - # Undefined |
5 | | - p$`$schema` <- NULL |
6 | | - expect_equal(version(p), "1.0") |
| 4 | + # Undefined $schema |
| 5 | + package$`$schema` <- NULL |
| 6 | + expect_equal(version(package), "1.0") |
7 | 7 |
|
8 | 8 | # Defined default |
9 | | - p$`$schema` <- "https://datapackage.org/profiles/1.0/datapackage.json" |
10 | | - expect_equal(version(p), "1.0") |
| 9 | + package$`$schema` <- "https://datapackage.org/profiles/1.0/datapackage.json" |
| 10 | + expect_equal(version(package), "1.0") |
11 | 11 |
|
12 | 12 | # 2.0 |
13 | | - p$`$schema` <- "https://datapackage.org/profiles/2.0/datapackage.json" |
14 | | - expect_equal(version(p), "2.0") |
| 13 | + package$`$schema` <- "https://datapackage.org/profiles/2.0/datapackage.json" |
| 14 | + expect_equal(version(package), "2.0") |
15 | 15 |
|
16 | 16 | # Future versions |
17 | | - p$`$schema` <- "https://datapackage.org/profiles/2.1/datapackage.json" |
18 | | - expect_equal(version(p), "2.1") |
19 | | - p$`$schema` <- "https://datapackage.org/profiles/2.2-rc.1/datapackage.json" |
20 | | - expect_equal(version(p), "2.2-rc.1") |
21 | | - p$`$schema` <- "https://datapackage.org/profiles/3.0/datapackage.json" |
22 | | - expect_equal(version(p), "3.0") |
| 17 | + package$`$schema` <- "https://datapackage.org/profiles/2.1/datapackage.json" |
| 18 | + expect_equal(version(package), "2.1") |
| 19 | + package$`$schema` <- "https://datapackage.org/profiles/2.2-rc.1/datapackage.json" |
| 20 | + expect_equal(version(package), "2.2-rc.1") |
| 21 | + package$`$schema` <- "https://datapackage.org/profiles/3.0/datapackage.json" |
| 22 | + expect_equal(version(package), "3.0") |
23 | 23 |
|
24 | 24 | # Custom extensions |
25 | | - p$`$schema` <- "https://spatial.datapackage.org/profiles/1.0/datapackage.json" |
26 | | - expect_equal(version(p), ">=2.0") |
27 | | - p$`$schema` <- "http://rs.tdwg.org/dwc-dp/1.0/dwc-dp-profile.json" |
28 | | - expect_equal(version(p), ">=2.0") |
| 25 | + package$`$schema` <- "https://custom.datapackage.org/package-profile.json" |
| 26 | + expect_equal(version(package), ">=2.0") |
| 27 | + package$`$schema` <- "https://rs.tdwg.org/dwc-dp/1.0/dwc-dp-profile.json" |
| 28 | + expect_equal(version(package), ">=2.0") |
| 29 | +}) |
| 30 | + |
| 31 | +test_that("version() returns correct version for Data Resource", { |
| 32 | + resource <- list( |
| 33 | + name = "custom_resource", |
| 34 | + path = "https://example.com/data.csv" |
| 35 | + ) |
| 36 | + |
| 37 | + # Undefined $schema |
| 38 | + resource$`$schema` <- NULL |
| 39 | + expect_equal(version(resource), "1.0") |
| 40 | + |
| 41 | + # Defined default |
| 42 | + resource$`$schema` <- "https://datapackage.org/profiles/1.0/dataresource.json" |
| 43 | + expect_equal(version(resource), "1.0") |
| 44 | + |
| 45 | + # 2.0 |
| 46 | + resource$`$schema` <- "https://datapackage.org/profiles/2.0/dataresource.json" |
| 47 | + expect_equal(version(resource), "2.0") |
| 48 | + |
| 49 | + # Future versions |
| 50 | + resource$`$schema` <- "https://datapackage.org/profiles/2.1/dataresource.json" |
| 51 | + expect_equal(version(resource), "2.1") |
| 52 | + resource$`$schema` <- "https://datapackage.org/profiles/2.2-rc.1/dataresource.json" |
| 53 | + expect_equal(version(resource), "2.2-rc.1") |
| 54 | + resource$`$schema` <- "https://datapackage.org/profiles/3.0/dataresource.json" |
| 55 | + expect_equal(version(resource), "3.0") |
| 56 | + |
| 57 | + # Custom extensions |
| 58 | + resource$`$schema` <- "https://custom.datapackage.org/resource-profile.json" |
| 59 | + expect_equal(version(resource), ">=2.0") |
| 60 | +}) |
| 61 | + |
| 62 | +test_that("version() returns correct version for Table Dialect", { |
| 63 | + # Entire dialect undefined => $schema is undefined => 1.0 |
| 64 | + dialect <- NULL |
| 65 | + expect_equal(version(dialect), "1.0") |
| 66 | + |
| 67 | + # Undefined $schema |
| 68 | + dialect <- list( |
| 69 | + delimiter = "," |
| 70 | + ) |
| 71 | + dialect$`$schema` <- NULL |
| 72 | + expect_equal(version(dialect), "1.0") |
| 73 | + |
| 74 | + # Defined default |
| 75 | + dialect$`$schema` <- "https://datapackage.org/profiles/1.0/tabledialect.json" |
| 76 | + expect_equal(version(dialect), "1.0") |
| 77 | + |
| 78 | + # 2.0 |
| 79 | + dialect$`$schema` <- "https://datapackage.org/profiles/2.0/tabledialect.json" |
| 80 | + expect_equal(version(dialect), "2.0") |
| 81 | + |
| 82 | + # Future versions |
| 83 | + dialect$`$schema` <- "https://datapackage.org/profiles/2.1/tabledialect.json" |
| 84 | + expect_equal(version(dialect), "2.1") |
| 85 | + dialect$`$schema` <- "https://datapackage.org/profiles/2.2-rc.1/tabledialect.json" |
| 86 | + expect_equal(version(dialect), "2.2-rc.1") |
| 87 | + dialect$`$schema` <- "https://datapackage.org/profiles/3.0/tabledialect.json" |
| 88 | + expect_equal(version(dialect), "3.0") |
| 89 | + |
| 90 | + # Custom extensions |
| 91 | + dialect$`$schema` <- "https://custom.datapackage.org/dialect-profile.json" |
| 92 | + expect_equal(version(dialect), ">=2.0") |
| 93 | +}) |
| 94 | + |
| 95 | +test_that("version() returns correct version for Table Schema", { |
| 96 | + schema <- list( |
| 97 | + fields = list() |
| 98 | + ) |
| 99 | + |
| 100 | + # Undefined $schema |
| 101 | + schema$`$schema` <- NULL |
| 102 | + expect_equal(version(schema), "1.0") |
| 103 | + |
| 104 | + # Defined default |
| 105 | + schema$`$schema` <- "https://datapackage.org/profiles/1.0/tableschema.json" |
| 106 | + expect_equal(version(schema), "1.0") |
| 107 | + |
| 108 | + # 2.0 |
| 109 | + schema$`$schema` <- "https://datapackage.org/profiles/2.0/tableschema.json" |
| 110 | + expect_equal(version(schema), "2.0") |
| 111 | + |
| 112 | + # Future versions |
| 113 | + schema$`$schema` <- "https://datapackage.org/profiles/2.1/tableschema.json" |
| 114 | + expect_equal(version(schema), "2.1") |
| 115 | + schema$`$schema` <- "https://datapackage.org/profiles/2.2-rc.1/tableschema.json" |
| 116 | + expect_equal(version(schema), "2.2-rc.1") |
| 117 | + schema$`$schema` <- "https://datapackage.org/profiles/3.0/tableschema.json" |
| 118 | + expect_equal(version(schema), "3.0") |
| 119 | + |
| 120 | + # Custom extensions |
| 121 | + schema$`$schema` <- "https://custom.datapackage.org/schema-profile.json" |
| 122 | + expect_equal(version(schema), ">=2.0") |
29 | 123 | }) |
30 | 124 |
|
31 | 125 | test_that("version() returns >=2.0 for invalid $schema", { |
32 | | - p <- create_package() |
33 | | - p$`$schema` <- list() |
34 | | - expect_equal(version(p), ">=2.0") |
35 | | - p$`$schema` <- 3.0 |
36 | | - expect_equal(version(p), ">=2.0") |
| 126 | + x <- list() |
| 127 | + x$`$schema` <- list() |
| 128 | + expect_equal(version(x), ">=2.0") |
| 129 | + x$`$schema` <- 3.0 |
| 130 | + expect_equal(version(x), ">=2.0") |
37 | 131 | }) |
38 | 132 |
|
39 | | -test_that("version() returns correct version for example packages", { |
| 133 | +test_that("version() returns correct version for example package properties", { |
40 | 134 | p_1.0 <- example_package(version = "1.0") |
| 135 | + |
| 136 | + # Data Package |
41 | 137 | expect_equal(version(p_1.0), "1.0") |
| 138 | + # Data Resource |
| 139 | + expect_equal(version(p_1.0$resources[[1]]), "1.0") |
| 140 | + # Data Dialect (undefined for deployments) |
| 141 | + expect_equal(version(p_1.0$resources[[1]]$dialect), "1.0") |
| 142 | + # Table Dialect (defined for observations) |
| 143 | + expect_equal(version(p_1.0$resources[[2]]$dialect), "1.0") |
| 144 | + # Table Schema |
| 145 | + expect_equal(version(p_1.0$resources[[1]]$schema), "1.0") |
| 146 | + |
42 | 147 | p_2.0 <- example_package(version = "2.0") |
| 148 | + |
| 149 | + # Data Package |
43 | 150 | expect_equal(version(p_2.0), "2.0") |
| 151 | + # Data Resource |
| 152 | + expect_equal(version(p_2.0$resources[[1]]), "2.0") |
| 153 | + # Data Dialect (undefined for deployments) |
| 154 | + expect_equal(version(p_2.0$resources[[1]]$dialect), "1.0") |
| 155 | + # Table Dialect (defined for observations) |
| 156 | + expect_equal(version(p_2.0$resources[[2]]$dialect), "2.0") |
| 157 | + # Table Schema |
| 158 | + expect_equal(version(p_2.0$resources[[1]]$schema), "2.0") |
44 | 159 | }) |
0 commit comments