Skip to content

Commit

Permalink
Test: Add comments and add unreachable()
Browse files Browse the repository at this point in the history
  • Loading branch information
xFrednet committed Oct 24, 2024
1 parent eccdaeb commit 2fb5b1d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/rt/core/builtin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ namespace rt::core

return std::nullopt;
});

add_builtin("unreachable", [](auto, auto, auto) {
ui::error("this method should never be called");
return std::nullopt;
});
}

void init_builtins(ui::UI* ui)
Expand Down
16 changes: 10 additions & 6 deletions tests/exprs/ifs.vpy
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,34 @@ a["self"] = a
f = {}
f.a = a

# Check if with else (This should be true)
if a == f.a:
b = f.a
c = {}
# Check empty lines in blocks:

drop b
drop c
else:
# Check parsing nested if's
if f.b == None:
e = {}
drop e
unreachable()

else:
d = {}
drop d
unreachable()

# Check identifier as the condition
cond = f.a != a
if cond:
dummy = "created"
unreachable()

# Check function call as the condition
def check():
c = False
# Check return condition result
return c == True
if check():
this = "is false"
unreachable()

drop a
drop f
24 changes: 12 additions & 12 deletions tests/exprs/while.vpy
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ obj = lst
while obj != null:
obj = obj.next

# Identifiers
# Check identifiers in the condition
cond = False
while cond == True:
never = "mind"
unreachable()
while cond:
never = "mind"
unreachable()

# Fields
# Check field access in the condition
x = {}
x.bool = False
while x.bool == True:
never = "mind"
unreachable()
while x.bool:
never = "mind"
unreachable()

# Function
# Check function calls in the condition
def bool(self):
return False
while bool({}) == True:
never = "mind"
unreachable()
while bool({}):
never = "mind"
unreachable()

# Method condition
# Check method calls in the condition
x.bool = bool
while x.bool() == True:
never = "mind"
unreachable()
while x.bool():
never = "mind"
unreachable()

0 comments on commit 2fb5b1d

Please sign in to comment.