@@ -76,6 +76,7 @@ testthat::test_that("handles the code included in curly brackets", {
7676 code <- " {1 + 1;a <- 5}"
7777
7878 testthat :: expect_identical(
79+ # TODO: to be fixed
7980 get_code(eval_code(qenv(), code ), names = " a" ),
8081 " a <- 5"
8182 )
@@ -87,7 +88,7 @@ testthat::test_that("handles the code of length > 1 when at least one is enclose
8788
8889 testthat :: expect_identical(
8990 get_code(q , names = " a" ),
90- " a <- 5"
91+ " a<- 5"
9192 )
9293})
9394
@@ -212,7 +213,7 @@ testthat::test_that("detects every assign calls even if not evaluated, if there
212213 q <- eval_code(qenv(), code )
213214 testthat :: expect_identical(
214215 get_code(q , names = " b" ),
215- c( " b <- 2 " , " eval(expression({ \n b <- b + 2 \n })) " )
216+ code [ 2 : 3 ]
216217 )
217218})
218219
@@ -295,16 +296,11 @@ testthat::test_that("extracts the code for assign() where \"x\" is a literal str
295296 q <- eval_code(qenv(), code )
296297 testthat :: expect_identical(
297298 get_code(q , names = " b" ),
298- c( " assign( \" b \" , 5)" , " b <- b + 2 " )
299+ code [c( 2 , 5 )]
299300 )
300301 testthat :: expect_identical(
301302 get_code(q , names = " c" ),
302- c(
303- " assign(\" b\" , 5)" ,
304- " assign(value = 7, x = \" c\" )" ,
305- " b <- b + 2" ,
306- " c <- b"
307- )
303+ code [c(2 , 3 , 5 , 6 )]
308304 )
309305 testthat :: expect_identical(
310306 get_code(q , names = " d" ),
@@ -355,11 +351,11 @@ testthat::test_that("detects function usage of the assignment operator", {
355351
356352 testthat :: expect_identical(
357353 get_code(q , names = " y" ),
358- c( code [ 1 ], " y <- x " )
354+ code
359355 )
360356 testthat :: expect_identical(
361357 get_code(q2 , names = " y" ),
362- " y <- x <- 2 "
358+ code2
363359 )
364360})
365361
@@ -390,7 +386,7 @@ testthat::test_that("@linksto makes a line being returned for an affected bindin
390386 q <- eval_code(qenv(), code )
391387 testthat :: expect_identical(
392388 get_code(q , names = " b" ),
393- c(" a <- 1 # @linksto b" , " b <- 2" )
389+ c(" a <- 1 # @linksto b" , " b <- 2" )
394390 )
395391})
396392
@@ -443,7 +439,7 @@ testthat::test_that(
443439 q <- eval_code(qenv(), code )
444440 testthat :: expect_identical(
445441 get_code(q , names = " classes" ),
446- c( " iris2 <- iris[1:5, ] " , code [ 2 : 4 ])
442+ code
447443 )
448444 }
449445)
@@ -467,11 +463,10 @@ testthat::test_that("comments fall into proper calls", {
467463 q <- qenv() | > eval_code(code )
468464 testthat :: expect_identical(
469465 get_code(q ),
470- c(
471- " a <- 1 # initial comment" ,
472- " b <- 2 # inline comment" ,
473- " c <- 3 # inbetween comment" ,
474- " d <- 4 # finishing comment"
466+ c(" # initial comment\n a <- 1" ,
467+ " b <- 2 # inline comment" ,
468+ " c <- 3\n # inbetween comment" ,
469+ " d <- 4\n # finishing comment"
475470 )
476471 )
477472})
@@ -493,11 +488,10 @@ testthat::test_that("comments get pasted when they fall into calls", {
493488 q <- qenv() | > eval_code(code )
494489 testthat :: expect_identical(
495490 get_code(q ),
496- c(
497- " a <- 1 # initial comment # A comment" ,
498- " b <- 2 # inline comment" ,
499- " c <- 3 # C comment # inbetween comment" ,
500- " d <- 4 # finishing comment"
491+ c(" # initial comment\n a <- 1 # A comment" ,
492+ " b <- 2 # inline comment" ,
493+ " c <- 3 # C comment\n # inbetween comment" ,
494+ " d <- 4\n # finishing comment"
501495 )
502496 )
503497})
@@ -516,7 +510,7 @@ testthat::test_that("ignores occurrence in a function definition", {
516510 )
517511 testthat :: expect_identical(
518512 get_code(q , names = " foo" ),
519- " foo <- function(b) { \n b <- b + 2 \n } "
513+ code [ 2 ]
520514 )
521515})
522516
@@ -528,11 +522,11 @@ testthat::test_that("ignores occurrence in a function definition that has functi
528522 q <- eval_code(qenv(), code )
529523 testthat :: expect_identical(
530524 get_code(q , names = " b" ),
531- " b <- 2 "
525+ code [ 1 ]
532526 )
533527 testthat :: expect_identical(
534528 get_code(q , names = " foo" ),
535- " foo <- function(b) { \n function(c) { \n b <- c + 2 \n } \n } "
529+ code [ 2 ]
536530 )
537531})
538532
@@ -550,7 +544,7 @@ testthat::test_that("ignores occurrence in a function definition if there is mul
550544 )
551545 testthat :: expect_identical(
552546 get_code(q , names = " foo" ),
553- " foo <- function(b) { \n function(c) { \n b <- c + 2 \n } \n } "
547+ code [ 2 ]
554548 )
555549})
556550
@@ -587,7 +581,7 @@ testthat::test_that("does not ignore occurrence in function body if object exsit
587581testthat :: test_that(" ignores occurrence in function definition without { curly brackets" , {
588582 code <- c(
589583 " b <- 2" ,
590- " foo <- function(b) b <- b + 2 "
584+ " foo <- function(b) b <- b + 2"
591585 )
592586 q <- eval_code(qenv(), code )
593587 testthat :: expect_identical(
@@ -610,7 +604,7 @@ testthat::test_that("detects occurrence of the function object", {
610604 q <- eval_code(qenv(), code )
611605 testthat :: expect_identical(
612606 get_code(q , names = " b" ),
613- c( " a <- 1 " , " b <- 2 " , " foo <- function(b) { \n b <- b + 2 \n } " , " b <- foo(a) " )
607+ code
614608 )
615609})
616610
@@ -623,7 +617,7 @@ testthat::test_that("detects occurrence of a function definition when a formal i
623617 q <- eval_code(qenv(), code )
624618 testthat :: expect_identical(
625619 get_code(q , names = " a" ),
626- c( " x <- 1 " , " foo <- function(foo = 1) \" text \" " , " a <- foo(x) " )
620+ code
627621 )
628622})
629623
@@ -640,10 +634,8 @@ testthat::test_that("detects occurrence of a function definition with a @linksto
640634 q <- eval_code(qenv(), code )
641635 testthat :: expect_identical(
642636 get_code(q , names = " x" ),
643- c(
644- " foo <- function() {\n env <- parent.frame()\n env$x <- 0\n }" ,
645- " foo() # @linksto x"
646- )
637+ c(" foo <- function() {\n env <- parent.frame()\n env$x <- 0\n }" ,
638+ " foo() # @linksto x" )
647639 )
648640})
649641# $ ---------------------------------------------------------------------------------------------------------------
@@ -696,11 +688,11 @@ testthat::test_that("understands @ usage and do not treat rhs of @ as objects (o
696688 q @ code <- code # we don't use eval_code so the code is not run
697689 testthat :: expect_identical(
698690 get_code(q , names = " x" ),
699- gsub( " ' " , " \" " , code [1 : 2 ], fixed = TRUE )
691+ code [1 : 2 ]
700692 )
701693 testthat :: expect_identical(
702694 get_code(q , names = " a" ),
703- gsub( " ' " , " \" " , code , fixed = TRUE )
695+ code
704696 )
705697})
706698
@@ -752,7 +744,7 @@ testthat::test_that("data() call is returned when data name is provided as a cha
752744 q <- eval_code(qenv(), code )
753745 testthat :: expect_identical(
754746 get_code(q , names = " z" ),
755- gsub( " ' " , " \" " , code [- 1 ], fixed = TRUE )
747+ code [- 1 ]
756748 )
757749})
758750
0 commit comments