{
  1
}

{ 1 }

# ------------------------------------------------------------------------
# Empty `{}`

{}
{} # comment

# Dangling comment forces it to expand
{
  # comment
}

# Dangling comment forces it to expand
{ # comment
}

({})

# Some people use `{}` as an alternative to `NULL`
switch(x, a = {}, b = 2, c = {}, d = 4)

# ------------------------------------------------------------------------
# Empty `{}` - function definition

# Motivating case
function() {}

stub <- function() {}

list(
  a = function() {},
  b = function() {}
)

# Even when parameters break, we don't expand the `{}`
function(a_really_long_argument, another_really_long_argument, another_longgg) {}

function() {} # comment

function() # comment
  {}

function()
  # comment
  {}

# ------------------------------------------------------------------------
# Empty `{}` - loops

# Want all these to be consistent
for (x in xs) {}
while (waiting()) {}
repeat {}

for (x in xs) {} # comment
while (waiting()) {} # comment
repeat {} # comment

for (x in xs) # comment
  {}
while (waiting()) # comment
  {}
repeat # comment
  {}

for (x in xs)
  # comment
  {}
while (waiting())
  # comment
  {}
repeat
  # comment
  {}

# ------------------------------------------------------------------------
# Empty `{}` - if statement

# These are a bit weird, but we deal with it for consistency reasons
if (a) {}
if (a) {} else {}

if (a) {} # comment

if (a) # comment
  {}

if (a)
  # comment
  {}

{
  if (a) {}
  else {}
}

{
  if (a) {} # comment1
  else {} # comment2
}

{
  if (a) {}
  # comment
  else {}
}

# Autobracing kicks in around `2` and spans multiple lines,
# while the `{}` is left uncollapsed. It's weird, but it
# is supposed to be so the user fixes it, because this is
# almost certainly a programming mistake.
if (a) {} else 2
if (a) 2 else {}

# ------------------------------------------------------------------------
# Curly-curly

fn({{ var }})
fn({{ var }}, x, {{ var }})

# Part of more complex expression. Assume `fn()` enquos.
fn(mean({{ var }}))
fn({{ var }} + 1)

fn({{ var_that_is_extremely_long_and_eventually_forces_a_line_break_once_we_eventually_get_to_the_end }})

fn({{ # Leading of `var`
  var
}})

# Comprehensive comment test
fn(
# C1
{ # C2 (lifted up)
# C3 (lifted up)
{ # C4 (leads var)
  # C5 (leads var)
  var
  # C6
} # C7 (this line, but after folded 2nd `}`)
# C8 (after both `}}`)
} # C9 (same line as C8)
# C10
)

# Not curly-curly, not a symbol
fn({{ 1 }})
fn({{ (var) }})

# Not curly-curly, not inside an argument
{{ var }}
function(a = {{ var }}) {}

# Not curly-curly, 2 inner expressions
fn({{
  1
  2
}})

# Not curly-curly, 2 outer expressions
fn({
  { foo }
  bar
})

# Not curly-curly, 0 inner expressions
fn({{ }})

# Not curly-curly, 0 inner expressions (important, even with dangling comment!)
fn({{
  # dangling
}})
