From 995f46289869699230b4240bc7d6bc665b373c1e Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Fri, 28 Jan 2022 19:21:50 -0300 Subject: [PATCH] indents(r): add tests --- tests/indent/r/comment.R | 2 ++ tests/indent/r/cond.R | 12 ++++++++++++ tests/indent/r/func.R | 12 ++++++++++++ tests/indent/r/loop.R | 17 +++++++++++++++++ tests/indent/r/pipe.R | 7 +++++++ 5 files changed, 50 insertions(+) create mode 100644 tests/indent/r/comment.R create mode 100644 tests/indent/r/cond.R create mode 100644 tests/indent/r/func.R create mode 100644 tests/indent/r/loop.R create mode 100644 tests/indent/r/pipe.R diff --git a/tests/indent/r/comment.R b/tests/indent/r/comment.R new file mode 100644 index 000000000..4396e1785 --- /dev/null +++ b/tests/indent/r/comment.R @@ -0,0 +1,2 @@ +# some +# comment diff --git a/tests/indent/r/cond.R b/tests/indent/r/cond.R new file mode 100644 index 000000000..865192915 --- /dev/null +++ b/tests/indent/r/cond.R @@ -0,0 +1,12 @@ +x <- 10 + +if (x > 3) { + x <- 3 +} else if (x < 3) { + x <- -3 +} else { + if (x > 0) { + x <- 1 + } + x <- 0 +} diff --git a/tests/indent/r/func.R b/tests/indent/r/func.R new file mode 100644 index 000000000..bc184dfb7 --- /dev/null +++ b/tests/indent/r/func.R @@ -0,0 +1,12 @@ +foo <- function(x) { + bar <- function(a, b, c) { + return(a + b + c) + } + return( + bar( + x, + 1, + 2 + ) + ) +} diff --git a/tests/indent/r/loop.R b/tests/indent/r/loop.R new file mode 100644 index 000000000..610bf6a7f --- /dev/null +++ b/tests/indent/r/loop.R @@ -0,0 +1,17 @@ +x <- 1 + +while (x < 10) { + x <- x + 1 + break +} + +for (i in 1:3) { + x <- x + 1 +} + +repeat { + x <- x + 1 + if (x > 100) { + break + } +} diff --git a/tests/indent/r/pipe.R b/tests/indent/r/pipe.R new file mode 100644 index 000000000..2eef84218 --- /dev/null +++ b/tests/indent/r/pipe.R @@ -0,0 +1,7 @@ +mtcars |> + head( + n = 6L + ) |> + subset( + cyl > 3 + )