-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added proper handling of tab characters (fixes #44) * Test update for tab linter + small doc update * Add link to line of R's source code responsible for tab indentation * Added a test function to remove redundant code * don't pass lines to fix_tab_indentations separately * Function which calculates tab width now ~2x as fast * Small fixes * Small rework * Properly handle multiline expressions ... and halved the time to correct tab indentations * Further tab indentation correction speed optimizations
- Loading branch information
Showing
8 changed files
with
146 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
context("get_source_expression") | ||
|
||
|
||
with_content_to_parse <- function(content, code) { | ||
f <- tempfile() | ||
on.exit(unlink(f)) | ||
writeLines(content, f) | ||
pc <- lapply(get_source_expressions(f)[["expressions"]], `[[`, "parsed_content") | ||
eval(substitute(code)) | ||
} | ||
|
||
|
||
test_that("tab positions have been corrected", { | ||
with_content_to_parse("1\n\t", | ||
expect_length(pc, 2L) | ||
) | ||
|
||
with_content_to_parse("TRUE", | ||
expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "TRUE", c("col1", "col2")], c(1L, 4L)) | ||
) | ||
|
||
with_content_to_parse("\tTRUE", | ||
expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "TRUE", c("col1", "col2")], c(2L, 5L)) | ||
) | ||
|
||
with_content_to_parse("\t\tTRUE", | ||
expect_equivalent(pc[[1]][pc[[1L]][["text"]] == "TRUE", c("col1", "col2")], c(3L, 6L)) | ||
) | ||
|
||
with_content_to_parse("x\t<-\tTRUE", { | ||
expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "x", c("col1", "col2")], c(1L, 1L)) | ||
expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "<-", c("col1", "col2")], c(3L, 4L)) | ||
expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "TRUE", c("col1", "col2")], c(6L, 9L)) | ||
}) | ||
|
||
with_content_to_parse("\tfunction\t(x)\t{\tprint(pc[\t,1])\t;\t}", { | ||
expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "function", c("col1", "col2")], c(2L, 9L)) | ||
expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "x", c("col1", "col2")], c(12L, 12L)) | ||
expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "print", c("col1", "col2")], c(17L, 21L)) | ||
expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == ";", c("col1", "col2")], c(32L, 32L)) | ||
expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "}", c("col1", "col2")], c(34L, 34L)) | ||
}) | ||
|
||
with_content_to_parse("# test tab\n\ns <- 'I have \\t a dog'\nrep(\ts, \t3)", { | ||
expect_equivalent( | ||
pc[[2L]][pc[[2L]][["text"]] == "'I have \\t a dog'", c("line1", "col1", "col2")], | ||
c(3L, 6L, 22L) | ||
) | ||
expect_equivalent( | ||
pc[[3L]][pc[[3L]][["text"]] == "3", c("line1", "col1", "col2")], | ||
c(4L, 10L, 10L) | ||
) | ||
}) | ||
|
||
with_content_to_parse("function(){\nTRUE\n\t}", { | ||
expect_equivalent( | ||
pc[[1L]][1L, c("line1", "col1", "line2", "col2")], | ||
c(1L, 1L, 3L, 2L), | ||
info = "expression that spans several lines" | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters