1context("extract_lang")
2
3f <- function(x) {
4  a <- 1:10
5  for (i in seq_along(a)) {
6    print(i)
7  }
8}
9
10test_that("extract_lang issues warning if nothing found", {
11
12  expect_warning(extract_lang(body(f), comp_lang, quote(j)),
13    "pkgload is incompatible")
14})
15
16test_that("extract_lang and comp_lang finds full statements", {
17
18  expect_equal(extract_lang(body(f), comp_lang, quote(a <- 1:10)),
19    quote(a <- 1:10))
20})
21
22test_that("extract_lang and comp_lang find child calls", {
23
24  expect_equal(extract_lang(body(f), comp_lang, quote(seq_along(a))),
25    quote(seq_along(a)))
26})
27
28test_that("extract_lang and comp_lang finds partial statements", {
29
30  expect_equal(extract_lang(body(f), comp_lang, quote(a <- NULL), 1:2),
31    quote(a <- 1:10))
32})
33
34test_that("extract_lang and comp_lang finds partial statements from for conditionals", {
35
36  expect_equal(extract_lang(body(f), comp_lang, quote(for (i in seq_along(a)) NULL), 1:3),
37    quote(for (i in seq_along(a)) { print(i) }))
38})
39
40test_that("modify_lang modifies properly", {
41  expect_equal(modify_lang(quote(a <- 1:10), function(x) if (comp_lang(x, quote(a))) quote(b) else x),
42      quote(b <- 1:10))
43})
44