Skip to content

Commit

Permalink
Move UTF-8 tests to another file to conceal them from platforms that …
Browse files Browse the repository at this point in the history
…cannot parse them
  • Loading branch information
Neal Richardson committed Apr 14, 2015
1 parent 544198d commit 7f74971
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 32 deletions.
35 changes: 3 additions & 32 deletions pkg/tests/testthat/test-encoding.R
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
context("UTF-8 Encoding")

if (run.integration.tests) {
test_that("encoding + JSON reads correctly", {
s <- iconv("aided_follow_grid:ElCorteInglés", to="UTF-8")
expect_identical(Encoding(s), "UTF-8")
expect_true(grepl("Inglés", s))
sj <- toJSON(s)
expect_true(grepl("Inglés", sj))
s2 <- fromJSON(sj)
expect_identical(s2, s)
expect_identical(fromJSON("utf-test.json"), "Budějovický Budvar")
})

with(fake.HTTP, {
ds <- loadDataset("test ds")
test_that("Reading UTF in tests", {
expect_identical(description(ds$mymrset), "Budějovický Budvar")
})
})

with(test.authentication, {
with(test.dataset(df), {
test_that("Properly encoded UTF is sent and received", {
s <- iconv("aided_follow_grid:ElCorteInglés", to="UTF-8")
name(ds$v1) <- s
expect_identical(name(ds$v1), s)
expect_identical(name(refresh(ds)$v1), s)
s2 <- "Budějovický Budvar"
name(ds$v2) <- s2
expect_identical(name(ds$v2), s2)
expect_identical(name(refresh(ds)$v2), s2)
})
})
})
## Move the actual tests to a different file so that non-Unicode
## environments won't fail to parse (even if not running these tests)
source("utftesting.R", local=TRUE)
}
34 changes: 34 additions & 0 deletions pkg/tests/testthat/utftesting.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
test_that("encoding + JSON reads correctly", {
s <- iconv("aided_follow_grid:ElCorteInglés", to="UTF-8")
expect_identical(Encoding(s), "UTF-8")
expect_true(grepl("Inglés", s))
sj <- toJSON(s)
expect_true(grepl("Inglés", sj))
s2 <- fromJSON(sj)
expect_identical(s2, s)
expect_identical(fromJSON("utf-test.json"), "Budějovický Budvar")
})

with(fake.HTTP, {
ds <- loadDataset("test ds")
test_that("Reading UTF in tests", {
expect_identical(description(ds$mymrset), "Budějovický Budvar")
})
})

with(test.authentication, {
with(test.dataset(df), {
test_that("Properly encoded UTF is sent and received", {
s <- iconv("aided_follow_grid:ElCorteInglés", to="UTF-8")
name(ds$v1) <- s
expect_identical(name(ds$v1), s)
expect_identical(name(refresh(ds)$v1), s)
s2 <- "Budějovický Budvar"
name(ds$v2) <- s2
expect_identical(name(ds$v2), s2)
expect_identical(name(refresh(ds)$v2), s2)
})
})
})

(

0 comments on commit 7f74971

Please sign in to comment.