Skip to content

Commit

Permalink
Adds tests for rstudio#84, rstudio#91, rstudio#94.
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettgman committed Mar 16, 2020
1 parent 0c92811 commit 3baa4d9
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/testthat/test_detect_mistakes.R
Original file line number Diff line number Diff line change
Expand Up @@ -670,3 +670,44 @@ test_that("detect_mistakes handles weird cases", {
)

})


test_that("detect_mistakes checks the call first", {

user <- quote(0 + sqrt(log(2)))
solution <- quote(sqrt(log(2)))
expect_equal(
detect_mistakes(user, solution)
,
wrong_value(this = "0 + sqrt(log(2))", that = quote(sqrt(log(2))))
# missing_argument(this_call = quote(sum()), that = quote(3))
)

})

test_that("detect_mistakes does not throw error for unused argument", {

a <- function(x) x
user <- quote(a(1, y = 2))
solution <- quote(a(1))
expect_equal(
detect_mistakes(user, solution)
,
surplus_argument(this_call = quote(a()), this = quote(2), this_name = "y")
)

})

test_that("detect_mistakes does not throw error for multiple matches of argument", {

a <- function(x, ya = 1, yb = 2) x
user <- quote(a(1, y = 2))
solution <- quote(a(1, ya = 2))
expect_equal(
detect_mistakes(user, solution)
,
missing_argument(this_call = quote(a()), that = quote(2), that_name = "ya")
)

})

0 comments on commit 3baa4d9

Please sign in to comment.