From 2fb5b1ddb7af4a68a5d50b9a46c8ed1e18b6a85d Mon Sep 17 00:00:00 2001 From: xFrednet Date: Thu, 24 Oct 2024 15:06:25 +0200 Subject: [PATCH] Test: Add comments and add `unreachable()` --- src/rt/core/builtin.cc | 5 +++++ tests/exprs/ifs.vpy | 16 ++++++++++------ tests/exprs/while.vpy | 24 ++++++++++++------------ 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/rt/core/builtin.cc b/src/rt/core/builtin.cc index 4810b02..5dae61d 100644 --- a/src/rt/core/builtin.cc +++ b/src/rt/core/builtin.cc @@ -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) diff --git a/tests/exprs/ifs.vpy b/tests/exprs/ifs.vpy index 236dd24..41add39 100644 --- a/tests/exprs/ifs.vpy +++ b/tests/exprs/ifs.vpy @@ -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 diff --git a/tests/exprs/while.vpy b/tests/exprs/while.vpy index de922c7..968a1a0 100644 --- a/tests/exprs/while.vpy +++ b/tests/exprs/while.vpy @@ -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()