Skip to content

Commit

Permalink
fixed expectation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
seankross committed Apr 8, 2016
1 parent 3221082 commit fcf65c1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Description: Use the R console as an interactive learning
environment. Users receive immediate feedback as they are guided through
self-paced lessons in data science and R programming.
URL: http://swirlstats.com
Version: 2.4.0
Version: 2.4.0.9002
License: MIT + file LICENSE
Authors@R: c(
person("Sean", "Kross", email = "[email protected]", role = c("aut", "cre")),
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ importFrom(stringr,str_split)
importFrom(stringr,str_split_fixed)
importFrom(stringr,str_trim)
importFrom(testthat,equals)
importFrom(testthat,expectation)
importFrom(testthat,is_a)
importFrom(testthat,is_equivalent_to)
importFrom(testthat,is_identical_to)
Expand Down
28 changes: 22 additions & 6 deletions R/answerTests.R
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ uses_func <- function(expected, label = NULL, ...){
function(expr){
uses <- (is.call(expr) || is.expression(expr)) &&
expected %in% flatten(expr)
expectation(identical(uses, TRUE),
expectation_old(identical(uses, TRUE),
str_c("does not use ", label))
}
}
Expand All @@ -446,12 +446,28 @@ in_range <- function(range, label=NULL){
isOK <- is.numeric(number) &&
isTRUE(number >= range[1]) &&
isTRUE(number <= range[2])
expectation(identical(isOK, TRUE),
expectation_old(identical(isOK, TRUE),
str_c("is not between ", range[1], " and ", range[2]))
}
}





# This version of expectation() has been graciously borrowed
# from version 0.11.0 of the testthat package by
# Hadley Wickham and others at RStudio. The expectation API
# was broken in later versions of testthat and we know the
# old version works for our purposes.
expectation_old <- function(passed, failure_msg,
success_msg = "unknown",
srcref = NULL) {
structure(
list(
passed = passed,
error = FALSE,
skipped = FALSE,
failure_msg = failure_msg,
success_msg = success_msg,
srcref = srcref
),
class = "expectation"
)
}
2 changes: 1 addition & 1 deletion R/swirl.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#' @export
#' @importFrom stringr str_c str_trim str_split str_length
#' @importFrom stringr str_detect str_locate fixed str_split_fixed
#' @importFrom testthat expectation equals is_equivalent_to
#' @importFrom testthat equals is_equivalent_to
#' @importFrom testthat is_identical_to is_a matches
#' @import utils
#' @importFrom methods is
Expand Down
6 changes: 5 additions & 1 deletion tests/testthat/test-encoding.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ context("encoding")
library(stringi)

test_that("Trying to parse the test-encoding.yaml", {
locale <- Sys.getlocale()
if(grepl("[L|l]atin", locale)){
testthat::skip("Locale is Latin")
}

test_parse <- function(file) {
class(file) <- get_content_class(file)
parse_content(file)
Expand All @@ -20,6 +25,5 @@ test_that("Trying to parse the test-encoding.yaml", {
)
} else {
expect_equal(stri_escape_unicode(test_phrase), stri_escape_unicode("中文測試"))

}
})

0 comments on commit fcf65c1

Please sign in to comment.