summaryrefslogtreecommitdiff
path: root/main/tests/test_gdscript.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main/tests/test_gdscript.cpp')
-rw-r--r--main/tests/test_gdscript.cpp58
1 files changed, 33 insertions, 25 deletions
diff --git a/main/tests/test_gdscript.cpp b/main/tests/test_gdscript.cpp
index 60f9568fbd..b2b2c22bf9 100644
--- a/main/tests/test_gdscript.cpp
+++ b/main/tests/test_gdscript.cpp
@@ -127,6 +127,7 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
case GDScriptParser::OperatorNode::OP_PARENT_CALL:
txt += ".";
+ FALLTHROUGH;
case GDScriptParser::OperatorNode::OP_CALL: {
ERR_FAIL_COND_V(c_node->arguments.size() < 1, "");
@@ -283,24 +284,27 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
case GDScriptParser::OperatorNode::OP_BIT_XOR: {
txt = _parser_expr(c_node->arguments[0]) + "^" + _parser_expr(c_node->arguments[1]);
} break;
- default: {}
+ default: {
+ }
}
} break;
+ case GDScriptParser::Node::TYPE_CAST: {
+ const GDScriptParser::CastNode *cast_node = static_cast<const GDScriptParser::CastNode *>(p_expr);
+ txt = _parser_expr(cast_node->source_node) + " as " + cast_node->cast_type.to_string();
+
+ } break;
case GDScriptParser::Node::TYPE_NEWLINE: {
//skippie
} break;
default: {
- String error = "Parser bug at " + itos(p_expr->line) + ", invalid expression type: " + itos(p_expr->type);
- ERR_EXPLAIN(error);
- ERR_FAIL_V("");
+ ERR_FAIL_V_MSG("", "Parser bug at " + itos(p_expr->line) + ", invalid expression type: " + itos(p_expr->type));
}
}
return txt;
- //return "("+txt+")";
}
static void _parser_show_block(const GDScriptParser::BlockNode *p_block, int p_indent) {
@@ -360,9 +364,6 @@ static void _parser_show_block(const GDScriptParser::BlockNode *p_block, int p_i
case GDScriptParser::ControlFlowNode::CF_MATCH: {
// FIXME: Implement
} break;
- case GDScriptParser::ControlFlowNode::CF_SWITCH: {
-
- } break;
case GDScriptParser::ControlFlowNode::CF_CONTINUE: {
_print_indent(p_indent, "continue");
@@ -566,7 +567,7 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
case GDScriptFunction::OPCODE_OPERATOR: {
int op = code[ip + 1];
- txt += "op ";
+ txt += " op ";
String opname = Variant::get_operator_name(Variant::Operator(op));
@@ -670,6 +671,17 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
incr += 2;
} break;
+ case GDScriptFunction::OPCODE_CAST_TO_SCRIPT: {
+
+ txt += " cast ";
+ txt += DADDR(3);
+ txt += "=";
+ txt += DADDR(1);
+ txt += " as ";
+ txt += DADDR(2);
+ incr += 4;
+
+ } break;
case GDScriptFunction::OPCODE_CONSTRUCT: {
Variant::Type t = Variant::Type(code[ip + 1]);
@@ -895,8 +907,7 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
if (incr == 0) {
- ERR_EXPLAIN("unhandled opcode: " + itos(code[ip]));
- ERR_BREAK(incr == 0);
+ ERR_BREAK_MSG(true, "Unhandled opcode: " + itos(code[ip]));
}
ip += incr;
@@ -911,18 +922,17 @@ MainLoop *test(TestType p_type) {
List<String> cmdlargs = OS::get_singleton()->get_cmdline_args();
if (cmdlargs.empty()) {
- //try editor!
return NULL;
}
String test = cmdlargs.back()->get();
+ if (!test.ends_with(".gd") && !test.ends_with(".gdc")) {
+ print_line("This test expects a path to a GDScript file as its last parameter. Got: " + test);
+ return NULL;
+ }
FileAccess *fa = FileAccess::open(test, FileAccess::READ);
-
- if (!fa) {
- ERR_EXPLAIN("Could not open file: " + test);
- ERR_FAIL_V(NULL);
- }
+ ERR_FAIL_COND_V_MSG(!fa, NULL, "Could not open file: " + test);
Vector<uint8_t> buf;
int flen = fa->get_len();
@@ -956,7 +966,7 @@ MainLoop *test(TestType p_type) {
if (tk.get_token() == GDScriptTokenizer::TK_IDENTIFIER)
text = "'" + tk.get_token_identifier() + "' (identifier)";
else if (tk.get_token() == GDScriptTokenizer::TK_CONSTANT) {
- Variant c = tk.get_token_constant();
+ const Variant &c = tk.get_token_constant();
if (c.get_type() == Variant::STRING)
text = "\"" + String(c) + "\"";
else
@@ -1016,19 +1026,17 @@ MainLoop *test(TestType p_type) {
return NULL;
}
- GDScript *script = memnew(GDScript);
+ Ref<GDScript> gds;
+ gds.instance();
GDScriptCompiler gdc;
- err = gdc.compile(&parser, script);
+ err = gdc.compile(&parser, gds.ptr());
if (err) {
print_line("Compile Error:\n" + itos(gdc.get_error_line()) + ":" + itos(gdc.get_error_column()) + ":" + gdc.get_error());
- memdelete(script);
return NULL;
}
- Ref<GDScript> gds = Ref<GDScript>(script);
-
Ref<GDScript> current = gds;
while (current.is_valid()) {
@@ -1041,10 +1049,10 @@ MainLoop *test(TestType p_type) {
} else if (p_type == TEST_BYTECODE) {
- Vector<uint8_t> buf = GDScriptTokenizerBuffer::parse_code_string(code);
+ Vector<uint8_t> buf2 = GDScriptTokenizerBuffer::parse_code_string(code);
String dst = test.get_basename() + ".gdc";
FileAccess *fw = FileAccess::open(dst, FileAccess::WRITE);
- fw->store_buffer(buf.ptr(), buf.size());
+ fw->store_buffer(buf2.ptr(), buf2.size());
memdelete(fw);
}