Skip to content

[Feature Request]: Support code dependency on a single expression with multiple assignments #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
averissimo opened this issue Apr 30, 2025 · 0 comments
Open
3 tasks done

Comments

@averissimo
Copy link
Contributor

Feature description

Such as var1 <- var2 <- 2

pkgload::load_all("../teal.code")
#> ℹ Loading teal.code
code <- "var1 <- var2 <- 1"
td <- eval_code(qenv(), code)
get_code(td, names = "var1")
#> [1] "var1 <- var2 <- 1"
get_code(td, names = "var2")
#> Warning: Object(s) not found in code: var2.
#> [1] ""

Created on 2025-04-30 with reprex v2.1.1

See test suite below for test-driven development

testthat::describe("detects multiple assignments in single line", {
  testthat::it("<-", {
    # testthat::skip("Not implemented")
    code <- "var1 <- var2 <- 1"
    td <- eval_code(qenv(), code)

    testthat::expect_identical(get_code(td, names = "var1"), code)
    testthat::expect_identical(get_code(td, names = "var2"), code)
  })

  testthat::it("->", {
    code <- "1 -> var1 -> var2"
    td <- eval_code(qenv(), code)

    testthat::expect_identical(
      get_code(td, names = "var1"),
      as.character(parse(text = code, keep.source = TRUE))
    )

    testthat::expect_identical(get_code(td, names = "var1"), code)
    testthat::expect_identical(get_code(td, names = "var2"), code)
  })

  testthat::it("<- and ->", {
    code <- "var1 <- 1 -> var2"
    td <- eval_code(qenv(), code)

    testthat::expect_identical(get_code(td, names = "var1"), code)
    testthat::expect_identical(get_code(td, names = "var2"), code)
  })
})

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant