Skip to content

Commit

Permalink
Merge pull request #38 from eddelbuettel/feature/tinytest
Browse files Browse the repository at this point in the history
Feature/tinytest
  • Loading branch information
eddelbuettel committed Jun 22, 2019
2 parents a78f527 + 2eede1d commit 67fcf66
Show file tree
Hide file tree
Showing 40 changed files with 395 additions and 47 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -16,6 +16,7 @@ install:
- ./run.sh install_aptget r-cran-rcpp
- sudo apt-get install -y gcc-4.9 g++-4.9
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9
- ./run.sh install_r tinytest

script:
- ./run.sh run_tests
Expand Down
44 changes: 44 additions & 0 deletions ChangeLog
@@ -1,3 +1,47 @@
2019-06-22 Dirk Eddelbuettel <edd@debian.org>

* inst/tinytest/test_misc.R: Added, based on tests/strings.R
* inst/tinytest/test_strings.R: Added, based on tests/strings.R
* inst/tinytest/strings.toml: Moved from tests/tables.toml
* inst/tinytest/test_tables.R: Added, based on tests/tables.R
* inst/tinytest/tables.toml: Moved from tests/tables.toml
* inst/tinytest/test_examples.R: Added, based on tests/tomlExamples.R
* inst/tinytest/toml_example-v0.4.0.toml: Moved from
tests/toml_example-v0.4.0.toml
* inst/tinytest/toml_example.toml: Moved from tests/toml_example.toml
* inst/tinytest/toml_hard_example.toml: Moved from
tests/toml_hard_example.toml

* tests/*.Rout.save: Moved old test results to local/old_tests/

2019-06-21 Dirk Eddelbuettel <edd@debian.org>

* .travis.yml (install): Install tinytest

* inst/tinytest/test_bool_datetime.R: Added, based on
tests/bool_datetime.R
* inst/tinytest/bool_datetime.toml: Moved from
tests/bool_datetime.toml
* inst/tinytest/test_float.R: Added, based on inst/tinytest/float.R
* inst/tinytest/float.toml: Moved from tests/float.toml
* inst/tinytest/test_integer.R: Added, based on tests/integer.R
* inst/tinytest/integer.toml: Moved from tests/integer.toml

2019-06-20 Dirk Eddelbuettel <edd@debian.org>

* inst/tinytest/test_arrays.R: Moved from tests/arrays.R
* inst/tinytest/arrays.toml: Moved from tests/arrays.toml

2019-06-19 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION: Added Suggests: tinytest
* tests/tinytest.R: Added

* inst/tinytest/test_dates_times.R: Added, based on
tests/dates_and_times.R
* inst/tinytest/dates_times.toml: Moved from
tests/dates_and times.toml

2018-10-31 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Version, Date): Release 0.1.5
Expand Down
1 change: 1 addition & 0 deletions DESCRIPTION
Expand Up @@ -16,4 +16,5 @@ URL: http://dirk.eddelbuettel.com/code/rcpp.toml.html
Imports: Rcpp (>= 0.11.5)
Depends: R (>= 3.3.0)
LinkingTo: Rcpp
Suggests: tinytest
License: GPL (>= 2)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions inst/tinytest/test_arrays.R
@@ -0,0 +1,33 @@

library(RcppTOML)

toml <- parseToml("arrays.toml")

expect_equal(names(toml), c("array", "fruit", "products"))
expect_equal(names(toml$array), paste0("key", 1:6))

expect_equal(toml$array$key1, 1:3)
expect_equal(class(toml$array$key1), "integer")

expect_equal(toml$array$key2, c("red", "yellow", "green"))

expect_equal(toml$array$key3[[1]], 1:2)
expect_equal(toml$array$key3[[2]], 3:5)

expect_equal(toml$array$key4[[1]], 1:2)
expect_equal(toml$array$key4[[2]], letters[1:3])

expect_equal(toml$array$key5, 1:3)

expect_equal(toml$array$key6, 1:2)

expect_equal(toml$fruit[[1]]$name, "apple")
expect_equal(toml$fruit[[1]]$physical, list(color="red", shape="round"))
expect_equal(toml$fruit[[1]]$variety, list(list(name="red delicious"),
list(name="granny smith")))
expect_equal(toml$fruit[[2]]$name, "banana")
expect_equal(toml$fruit[[2]]$variety, list(list(name="plantain")))

expect_equal(toml$products[[1]], list(name="Hammer", sku=738594937L))
expect_equal(toml$products[[2]], list())
expect_equal(toml$products[[3]], list(color="gray", name="Nail", sku=284758393L))
16 changes: 16 additions & 0 deletions inst/tinytest/test_bool_datetime.R
@@ -0,0 +1,16 @@

library(RcppTOML)

toml <- parseToml("bool_datetime.toml")

expect_equal(names(toml), c("boolean", "datetime"))

expect_true(toml$boolean$True)
expect_false(toml$boolean$False)

ref1 <- as.POSIXct("1979-05-27 07:32:00", tz="UTC", usetz=TRUE)
ref2 <- as.POSIXct("1979-05-27 07:32:00.999999", tz="UTC", usetz=TRUE)

expect_equal(toml$datetime$key1, ref1)
expect_equal(toml$datetime$key2, ref1)
expect_equal(toml$datetime$key3, ref2)
31 changes: 31 additions & 0 deletions inst/tinytest/test_dates_times.R
@@ -0,0 +1,31 @@

library(RcppTOML)

## v0.5 brings more date and time supprt
toml <- parseToml("dates_and_times.toml")

## reference results
pt1 <- as.POSIXct("1979-05-27 07:32:00", tz="UTC", usetz=TRUE)
pt2 <- as.POSIXct("1979-05-27 07:32:00.999999", tz="UTC", usetz=TRUE)
pt3 <- as.POSIXct("1979-05-27 00:32:00.999999", tz="UTC", usetz=TRUE)

expect_equal(toml$odt1, pt1)
expect_true(inherits(toml$odt1, "POSIXct"))

expect_equal(toml$odt2, pt1)
expect_true(inherits(toml$odt2, "POSIXct"))

expect_equal(toml$odt3, pt2)
expect_true(inherits(toml$odt3, "POSIXct"))

expect_equal(toml$odt4, pt1)
expect_true(inherits(toml$odt4, "POSIXct"))

expect_equal(toml$ldt1, pt1)
expect_true(inherits(toml$ldt1, "POSIXct"))

expect_equal(toml$ldt2, pt3)
expect_true(inherits(toml$ldt1, "POSIXct"))

expect_equal(class(toml$ld1), "Date")
expect_equal(toml$ld1, as.Date("1979-05-27"))
144 changes: 144 additions & 0 deletions inst/tinytest/test_examples.R
@@ -0,0 +1,144 @@

library(RcppTOML)

## basic toml-lang::tests/example.toml
toml <- parseToml("toml_example.toml")

expect_true(setequal(names(toml), c("title", "owner", "database", "servers",
"clients", "products")))

expect_equal(toml$title, "TOML Example")

expect_true(setequal(names(toml$owner), c("name", "organization", "bio", "dob")))
expect_equal(toml$owner$name, "Tom Preston-Werner")
expect_equal(toml$owner$organization, "GitHub")
expect_equal(toml$owner$bio, "GitHub Cofounder & CEO\\nLikes tater tots and beer.")
expect_equal(toml$owner$dob, as.POSIXct("1979-05-27 07:32:00", tz="UTC", usetz=TRUE))

expect_true(setequal(names(toml$database), c("server", "ports", "connection_max", "enabled")))
expect_equal(toml$database$server, "192.168.1.1")
expect_equal(toml$database$ports, c(8001L, 8001L, 8002L))
expect_equal(toml$database$connection_max, 5000L)
expect_equal(toml$database$enabled, TRUE)

expect_true(setequal(names(toml$servers), c("alpha", "beta")))
expect_true(setequal(names(toml$servers$alpha), c("ip", "dc")))
expect_equal(toml$servers$alpha$ip, "10.0.0.1")
expect_equal(toml$servers$alpha$dc, "eqdc10")
expect_true(setequal(names(toml$servers$beta), c("ip", "dc", "country")))
expect_equal(toml$servers$beta$ip, "10.0.0.2")
expect_equal(toml$servers$beta$dc, "eqdc10")
expect_equal(toml$servers$beta$country, "中国")

expect_true(setequal(names(toml$clients), c("data", "hosts")))
expect_true(setequal(toml$clients$data, list(c("gamma", "delta"), c(1L, 2L))))
expect_true(setequal(toml$clients$hosts, c("alpha", "omega")))

expect_true(setequal(toml$products[[1]], list(name="Hammer", sku=738594937L)))
expect_true(setequal(toml$products[[2]], list(color="gray", name="Nail", sku=284758393L)))



## harder toml-lang::tests/hard_example.toml
toml <- parseToml("toml_hard_example.toml")

expect_equal(names(toml), "the")

expect_true(setequal(names(toml$the), c("test_string", "hard")))
expect_equal(toml$the$test_string, "You'll hate me after this - #")

expect_true(setequal(names(toml$the$hard), c("test_array", "test_array2", "another_test_string",
"harder_test_string", "bit#")))
expect_equal(toml$the$hard$test_array, c("] ", " # "))
expect_equal(toml$the$hard$test_array2, c("Test #11 ]proved that", "Experiment #9 was a success"))
expect_equal(toml$the$hard$another_test_string, " Same thing, but with a string #")
expect_equal(toml$the$hard$harder_test_string, " And when \\\"'s are in the string, along with # \\\"")
expect_equal(toml$the$hard$`bit#`$`what?`, "You don't think some user won't do that?")
expect_equal(toml$the$hard$`bit#`$multi_line_array, "]")


## example toml-lang::examples/example-v0.4.0.toml
##
## note that we edited line 56 which cannot be parsed by cpptoml
##
## also note that there is some redunancy as we had used these tests for the first
## iteration in tests/ which are now tests files here
toml <- parseToml("toml_example-v0.4.0.toml")

expect_true(setequal(names(toml), c("table", "string", "integer", "float",
"boolean", "datetime", "array", "products",
"fruit", "x")))

expect_equal(toml$table$key, "value")
expect_equal(toml$table$subtable$key, "another value")
expect_equal(toml$table$inline$name, list(first="Tom", last="Preston-Werner"))
expect_equal(toml$table$inline$point, list(x=1L, y=2L))

expect_equal(toml$x$y$y$z$w, NULL)

expect_equal(toml$string$basic$basic,
"I'm a string. \\\"You can quote me\\\". Name\tJose\\nLocation\tSF.")
expect_equal(toml$string$multiline$key1, "One\\nTwo")
expect_equal(toml$string$multiline$key2, "One\\nTwo")
expect_equal(toml$string$multiline$key3, "One\\nTwo")
expect_equal(toml$string$multiline$continued$key1, "The quick brown fox jumps over the lazy dog.")
expect_equal(toml$string$multiline$continued$key2, "The quick brown fox jumps over the lazy dog.")
expect_equal(toml$string$multiline$continued$key3, "The quick brown fox jumps over the lazy dog.")
expect_equal(toml$string$literal$winpath, "C:\\\\Users\\\\nodejs\\\\templates")
expect_equal(toml$string$literal$winpath2, "\\\\\\\\ServerX\\\\admin$\\\\system32\\\\")
expect_equal(toml$string$literal$quoted, "Tom \\\"Dubs\\\" Preston-Werner")
expect_equal(toml$string$literal$regex, "<\\\\i\\\\c*\\\\s*>")
expect_equal(toml$string$literal$multiline$regex2, "I [dw]on't need \\\\d{2} apples")
expect_equal(toml$string$literal$multiline$lines,
paste0("The first newline is\\ntrimmed in raw strings.\\n",
" All other whitespace\\n is preserved.\\n"))

expect_equal(names(toml$integer), c("key1", "key2", "key3", "key4", "underscores"))
expect_equal(toml$integer$key1, 99L)
expect_equal(toml$integer$key2, 42L)
expect_equal(toml$integer$key3, 0L)
expect_equal(toml$integer$key4, -17L)
expect_equal(toml$integer$underscores$key1, 1000L)
expect_equal(toml$integer$underscores$key2, 5349221L)
expect_equal(toml$integer$underscores$key3, 12345L)

expect_equal(names(toml$float), c("both", "exponent", "fractional", "underscores"))
expect_equal(toml$float$both$key, 6.626e-34)
expect_equal(toml$float$exponent$key1, 5e22)
expect_equal(toml$float$exponent$key2, 1e+06)
expect_equal(toml$float$exponent$key3, -0.02)
expect_equal(toml$float$fractional$key1, 1)
expect_equal(toml$float$fractional$key2, 3.1415)
expect_equal(toml$float$fractional$key3, -0.01)
expect_equal(toml$float$underscores$key1, 9224617.445991228313)


expect_true(toml$boolean$True)
expect_false(toml$boolean$False)

ref1 <- as.POSIXct("1979-05-27 07:32:00", tz="UTC", usetz=TRUE)
ref2 <- as.POSIXct("1979-05-27 07:32:00.999999", tz="UTC", usetz=TRUE)
expect_equal(toml$datetime$key1, ref1)
expect_equal(toml$datetime$key2, ref1)
expect_equal(toml$datetime$key3, ref2)


expect_equal(names(toml$array), paste0("key", 1:6))
expect_equal(toml$array$key1, 1:3)
expect_equal(class(toml$array$key1), "integer")
expect_equal(toml$array$key2, c("red", "yellow", "green"))
expect_equal(toml$array$key3[[1]], 1:2)
expect_equal(toml$array$key3[[2]], 3:5)
expect_equal(toml$array$key4[[1]], 1:2)
expect_equal(toml$array$key4[[2]], letters[1:3])
expect_equal(toml$array$key5, 1:3)
expect_equal(toml$array$key6, 1:2)
expect_equal(toml$products[[1]], list(name="Hammer", sku=738594937L))
expect_equal(toml$products[[2]], list())
expect_equal(toml$products[[3]], list(color="gray", name="Nail", sku=284758393L))
expect_equal(toml$fruit[[1]]$name, "apple")
expect_equal(toml$fruit[[1]]$physical, list(color="red", shape="round"))
expect_equal(toml$fruit[[1]]$variety, list(list(name="red delicious"),
list(name="granny smith")))
expect_equal(toml$fruit[[2]]$name, "banana")
expect_equal(toml$fruit[[2]]$variety, list(list(name="plantain")))
19 changes: 19 additions & 0 deletions inst/tinytest/test_float.R
@@ -0,0 +1,19 @@

library(RcppTOML)

toml <- parseToml("float.toml")

expect_equal(names(toml), c("float"))
expect_equal(names(toml$float), c("both", "exponent", "fractional", "underscores"))

expect_equal(toml$float$both$key, 6.626e-34)

expect_equal(toml$float$exponent$key1, 5e22)
expect_equal(toml$float$exponent$key2, 1e+06)
expect_equal(toml$float$exponent$key3, -0.02)

expect_equal(toml$float$fractional$key1, 1)
expect_equal(toml$float$fractional$key2, 3.1415)
expect_equal(toml$float$fractional$key3, -0.01)

expect_equal(toml$float$underscores$key1, 9224617.445991228313)
16 changes: 16 additions & 0 deletions inst/tinytest/test_integer.R
@@ -0,0 +1,16 @@

library(RcppTOML)

toml <- parseToml("integer.toml")

expect_equal(names(toml), c("integer"))
expect_equal(names(toml$integer), c("key1", "key2", "key3", "key4", "underscores"))

expect_equal(toml$integer$key1, 99L)
expect_equal(toml$integer$key2, 42L)
expect_equal(toml$integer$key3, 0L)
expect_equal(toml$integer$key4, -17L)

expect_equal(toml$integer$underscores$key1, 1000L)
expect_equal(toml$integer$underscores$key2, 5349221L)
expect_equal(toml$integer$underscores$key3, 12345L)
28 changes: 28 additions & 0 deletions inst/tinytest/test_misc.R
@@ -0,0 +1,28 @@

toml <- RcppTOML::parseToml("
title = \"TOML Example\"
[owner]
name = \"Tom Preston-Werner\"
dob = 1979-05-27T07:32:00-08:00 # First class dates
[database]
server = \"192.168.1.1\"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true
", fromFile=FALSE)

expect_true(setequal(names(toml), c("title", "owner", "database")))

expect_true(setequal(names(toml$owner), c("name", "dob")))
expect_equal(toml$owner$name, "Tom Preston-Werner")
expect_equal(toml$owner$dob, as.POSIXct("1979-05-27 15:32:00", tz="UTC", usetz=TRUE))

expect_true(setequal(names(toml$database), c("server", "ports", "connection_max", "enabled")))
expect_equal(toml$database$server, "192.168.1.1")
expect_equal(toml$database$ports, c(8001L, 8001L, 8002L))
expect_equal(toml$database$connection_max, 5000L)
expect_equal(toml$database$enabled, TRUE)
29 changes: 29 additions & 0 deletions inst/tinytest/test_strings.R
@@ -0,0 +1,29 @@

library(RcppTOML)

toml <- parseToml("strings.toml")

expect_equal(names(toml), "string")
expect_true(setequal(names(toml$string), c("basic", "literal", "multiline")))

expect_equal(names(toml$string$basic), "basic")
expect_equal(toml$string$basic$basic, "I'm a string. \\\"You can quote me\\\". Name\tJose\\nLocation\tSF.")

expect_true(setequal(names(toml$string$multiline), c("key1", "key2", "key3", "continued")))
expect_equal(toml$string$multiline$key1, "One\\nTwo")
expect_equal(toml$string$multiline$key2, "One\\nTwo")
expect_equal(toml$string$multiline$key3, "One\\nTwo")
expect_true(setequal(names(toml$string$multiline$continued), c("key1", "key2", "key3")))
expect_equal(toml$string$multiline$continued$key1, "The quick brown fox jumps over the lazy dog.")
expect_equal(toml$string$multiline$continued$key2, "The quick brown fox jumps over the lazy dog.")
expect_equal(toml$string$multiline$continued$key3, "The quick brown fox jumps over the lazy dog.")


expect_true(setequal(names(toml$string$literal), c("winpath", "winpath2", "quoted", "regex", "multiline")))
expect_equal(toml$string$literal$winpath, "C:\\\\Users\\\\nodejs\\\\templates")
expect_equal(toml$string$literal$winpath2, "\\\\\\\\ServerX\\\\admin$\\\\system32\\\\")
expect_equal(toml$string$literal$quoted, "Tom \\\"Dubs\\\" Preston-Werner")
expect_equal(toml$string$literal$regex, "<\\\\i\\\\c*\\\\s*>")
expect_true(setequal(names(toml$string$literal$multiline), c("regex2", "lines")))
expect_equal(toml$string$literal$multiline$regex2, "I [dw]on't need \\\\d{2} apples")
expect_equal(toml$string$literal$multiline$lines, "The first newline is\\ntrimmed in raw strings.\\n All other whitespace\\n is preserved.\\n")

0 comments on commit 67fcf66

Please sign in to comment.