Skip to content

Commit

Permalink
Add some extra tests (#146)
Browse files Browse the repository at this point in the history
* Extra `if` test

* Add anti call, subset, subset2 tests

* Add anti arithmetic operator test

* Add anti `$`, `@`, `::`, and `:::` tests

* Add R side of these tests
  • Loading branch information
DavisVaughan authored Sep 17, 2024
1 parent f0679b9 commit 2097fa5
Show file tree
Hide file tree
Showing 9 changed files with 352 additions and 0 deletions.
78 changes: 78 additions & 0 deletions bindings/r/tests/testthat/_snaps/calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,84 @@
f(,y=)

# not a call, subset, or subset2

Code
node_children_print(node)
Output
S-Expression
(identifier [(1, 0), (1, 1)])
Text
f
S-Expression
(parenthesized_expression [(2, 0), (2, 3)]
open: "(" [(2, 0), (2, 1)]
body: (identifier [(2, 1), (2, 2)])
close: ")" [(2, 2), (2, 3)]
)
Text
(x)
S-Expression
(identifier [(4, 0), (4, 3)])
Text
foo
S-Expression
(ERROR [(5, 0), (5, 1)]
(ERROR [(5, 0), (5, 1)])
)
Text
[
S-Expression
(identifier [(5, 1), (5, 4)])
Text
bar
S-Expression
(ERROR [(5, 4), (5, 5)]
(ERROR [(5, 4), (5, 5)])
)
Text
]
S-Expression
(identifier [(7, 0), (7, 3)])
Text
foo
S-Expression
(ERROR [(8, 0), (8, 2)]
(ERROR [(8, 0), (8, 2)])
)
Text
[[
S-Expression
(identifier [(8, 2), (8, 3)])
Text
x
S-Expression
(ERROR [(8, 3), (8, 5)]
(ERROR [(8, 3), (8, 5)])
)
Text
]]

# braces

Code
Expand Down
25 changes: 25 additions & 0 deletions bindings/r/tests/testthat/_snaps/control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@
d
}
S-Expression
(if_statement [(9, 0), (14, 1)]
"if" [(9, 0), (9, 2)]
open: "(" [(9, 3), (9, 4)]
condition: (binary_operator [(10, 2), (11, 3)]
lhs: (identifier [(10, 2), (10, 3)])
operator: "<" [(10, 4), (10, 5)]
rhs: (identifier [(11, 2), (11, 3)])
)
close: ")" [(12, 0), (12, 1)]
consequence: (braced_expression [(12, 2), (14, 1)]
open: "{" [(12, 2), (12, 3)]
body: (identifier [(13, 2), (13, 3)])
close: "}" [(14, 0), (14, 1)]
)
)
Text
if (
x <
y
) {
z
}

# if else

Expand Down
92 changes: 92 additions & 0 deletions bindings/r/tests/testthat/_snaps/miscellaneous.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,98 @@

# dollar, at, namespace, namespace internal with newline before operator

Code
node_children_print(node)
Output
S-Expression
(comment [(1, 0), (1, 74)])
Text
# Newlines are not allowed before the operator, so none of these are valid
S-Expression
(identifier [(2, 0), (2, 1)])
Text
x
S-Expression
(ERROR [(3, 0), (3, 1)]
"$" [(3, 0), (3, 1)]
)
Text
$
S-Expression
(identifier [(3, 1), (3, 2)])
Text
y
S-Expression
(identifier [(5, 0), (5, 1)])
Text
x
S-Expression
(ERROR [(6, 0), (6, 1)]
"@" [(6, 0), (6, 1)]
)
Text
@
S-Expression
(identifier [(6, 1), (6, 2)])
Text
y
S-Expression
(identifier [(8, 0), (8, 1)])
Text
x
S-Expression
(ERROR [(9, 0), (9, 2)]
"::" [(9, 0), (9, 2)]
)
Text
::
S-Expression
(identifier [(9, 2), (9, 3)])
Text
y
S-Expression
(identifier [(11, 0), (11, 1)])
Text
x
S-Expression
(ERROR [(12, 0), (12, 3)]
":::" [(12, 0), (12, 3)]
)
Text
:::
S-Expression
(identifier [(12, 3), (12, 4)])
Text
y

# complex expressions

Code
Expand Down
21 changes: 21 additions & 0 deletions bindings/r/tests/testthat/_snaps/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,27 @@
b

# not an arithmetic operator

Code
node_children_print(node)
Output
S-Expression
(identifier [(1, 0), (1, 1)])
Text
a
S-Expression
(unary_operator [(2, 2), (2, 5)]
operator: "+" [(2, 2), (2, 3)]
rhs: (identifier [(2, 4), (2, 5)])
)
Text
+ b

# unary

Code
Expand Down
12 changes: 12 additions & 0 deletions bindings/r/tests/testthat/references/calls.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ f("x"=,)
f(... = ,)
f(,y=)

# ------------------------------------------------------------------------------
# not a call, subset, or subset2

f
(x)

foo
[bar]

foo
[[x]]

# ------------------------------------------------------------------------------
# braces

Expand Down
7 changes: 7 additions & 0 deletions bindings/r/tests/testthat/references/control-flow.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ if (a.b) {
d
}

if (
x <
y
) {
z
}

# ------------------------------------------------------------------------------
# if else

Expand Down
16 changes: 16 additions & 0 deletions bindings/r/tests/testthat/references/miscellaneous.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ foo@if
foo::if
foo:::if

# ------------------------------------------------------------------------------
# dollar, at, namespace, namespace internal with newline before operator

# Newlines are not allowed before the operator, so none of these are valid
x
$y

x
@y

x
::y

x
:::y

# ------------------------------------------------------------------------------
# complex expressions

Expand Down
6 changes: 6 additions & 0 deletions bindings/r/tests/testthat/references/operators.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ a +
a *
b

# ------------------------------------------------------------------------------
# not an arithmetic operator

a
+ b

# ------------------------------------------------------------------------------
# unary

Expand Down
Loading

0 comments on commit 2097fa5

Please sign in to comment.