chore(client): add gdUnit4 test framework addon
Vendor gdUnit4 for Godot 4 client testing (D-030). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,246 @@
|
||||
# GdUnit generated TestSuite
|
||||
class_name GdDefaultValueDecoderTest
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/parse/GdDefaultValueDecoder.gd'
|
||||
|
||||
|
||||
var _tested_types := {}
|
||||
|
||||
|
||||
func after() -> void:
|
||||
# we verify we have covered all variant types
|
||||
for type_id in TYPE_MAX:
|
||||
if type_id == TYPE_OBJECT:
|
||||
continue
|
||||
@warning_ignore("unsafe_method_access")
|
||||
assert_that(_tested_types.get(type_id))\
|
||||
.override_failure_message("Missing Variant type '%s'" % GdObjects.type_as_string(type_id))\
|
||||
.is_not_null()
|
||||
|
||||
|
||||
func test_decode_Primitives(variant_type: int, value: Variant, expected: String, _test_parameters := [
|
||||
[TYPE_NIL, null, "null"],
|
||||
[TYPE_BOOL, true, "true"],
|
||||
[TYPE_BOOL, false, "false"],
|
||||
[TYPE_INT, -100, "-100"],
|
||||
[TYPE_INT, 0, "0"],
|
||||
[TYPE_INT, 100, "100"],
|
||||
[TYPE_FLOAT, -100.123, "-100.123000"],
|
||||
[TYPE_FLOAT, 0.00, "0.000000"],
|
||||
[TYPE_FLOAT, 100, "100.000000"],
|
||||
[TYPE_FLOAT, 100.123, "100.123000"],
|
||||
[TYPE_STRING, "hello", '"hello"'],
|
||||
[TYPE_STRING, "", '""'],
|
||||
[TYPE_STRING_NAME, StringName("hello"), 'StringName("hello")'],
|
||||
[TYPE_STRING_NAME, StringName(""), 'StringName()'],
|
||||
]) -> void:
|
||||
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_Vectors(variant_type: int, value: Variant, expected: String, _test_parameters := [
|
||||
[TYPE_VECTOR2, Vector2(), "Vector2()"],
|
||||
[TYPE_VECTOR2, Vector2(1,2), "Vector2" + str(Vector2(1, 2))],
|
||||
[TYPE_VECTOR2I, Vector2i(), "Vector2i()"],
|
||||
[TYPE_VECTOR2I, Vector2i(1,2), "Vector2i(1, 2)"],
|
||||
[TYPE_VECTOR3, Vector3(), "Vector3()"],
|
||||
[TYPE_VECTOR3, Vector3(1,2,3), "Vector3" +str(Vector3(1, 2, 3))],
|
||||
[TYPE_VECTOR3I, Vector3i(), "Vector3i()"],
|
||||
[TYPE_VECTOR3I, Vector3i(1,2,3), "Vector3i(1, 2, 3)"],
|
||||
[TYPE_VECTOR4, Vector4(), "Vector4()"],
|
||||
[TYPE_VECTOR4, Vector4(1,2,3,4), "Vector4" + str(Vector4(1, 2, 3, 4))],
|
||||
[TYPE_VECTOR4I, Vector4i(), "Vector4i()"],
|
||||
[TYPE_VECTOR4I, Vector4i(1,2,3,4), "Vector4i(1, 2, 3, 4)"],
|
||||
]) -> void:
|
||||
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_Rect2(variant_type: int, value: Variant, expected: String, _test_parameters := [
|
||||
[TYPE_RECT2, Rect2(), "Rect2()"],
|
||||
[TYPE_RECT2, Rect2(1,2, 10,20), "Rect2(Vector2"+str(Vector2(1, 2))+", Vector2"+str(Vector2(10, 20))+")"],
|
||||
[TYPE_RECT2I, Rect2i(), "Rect2i()"],
|
||||
[TYPE_RECT2I, Rect2i(1,2, 10,20), "Rect2i(Vector2i(1, 2), Vector2i(10, 20))"],
|
||||
]) -> void:
|
||||
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_Transforms(variant_type: int, value: Variant, expected: String, _test_parameters := [
|
||||
[TYPE_TRANSFORM2D, Transform2D(),
|
||||
"Transform2D()"],
|
||||
[TYPE_TRANSFORM2D, Transform2D(2.0, Vector2(1,2)),
|
||||
"Transform2D(Vector2(-0.416147, 0.909297), Vector2(-0.909297, -0.416147), Vector2"+str(Vector2(1, 2))+")"],
|
||||
[TYPE_TRANSFORM2D, Transform2D(2.0, Vector2(1,2), 2.0, Vector2(3,4)),
|
||||
"Transform2D(Vector2(-0.416147, 0.909297), Vector2(1.513605, -1.307287), Vector2"+str(Vector2(3, 4))+")"],
|
||||
[TYPE_TRANSFORM2D, Transform2D(Vector2(1,2), Vector2(3,4), Vector2.ONE),
|
||||
"Transform2D(Vector2"+str(Vector2(1, 2))+", Vector2"+str(Vector2(3, 4))+", Vector2"+str(Vector2(1, 1))+")"],
|
||||
[TYPE_TRANSFORM3D, Transform3D(),
|
||||
"Transform3D()"],
|
||||
[TYPE_TRANSFORM3D, Transform3D(Basis.FLIP_X, Vector3.ONE),
|
||||
"Transform3D(Vector3"+str(Vector3(-1, 0, 0))+", Vector3"+str(Vector3(0, 1, 0))
|
||||
+", Vector3"+str(Vector3(0, 0, 1))+", Vector3"+str(Vector3(1, 1, 1))+")"],
|
||||
[TYPE_TRANSFORM3D, Transform3D(Vector3(1,2,3), Vector3(4,5,6), Vector3(7,8,9), Vector3.ONE),
|
||||
"Transform3D(Vector3"+str(Vector3(1, 2, 3))+", Vector3"+str(Vector3(4, 5, 6))
|
||||
+", Vector3"+str(Vector3(7, 8, 9))+", Vector3"+str(Vector3(1, 1, 1))+")"],
|
||||
[TYPE_PROJECTION, Projection(), "Projection(Vector4%s, Vector4%s, Vector4%s, Vector4%s)"
|
||||
% [Vector4(1, 0, 0, 0), Vector4(0, 1, 0, 0), Vector4(0, 0, 1, 0), Vector4(0, 0, 0, 1)]],
|
||||
[TYPE_PROJECTION, Projection(Vector4.ONE, Vector4.ONE*2, Vector4.ONE*3, Vector4.ZERO),
|
||||
"Projection(Vector4%s, Vector4%s, Vector4%s, Vector4%s)" %
|
||||
[Vector4.ONE, Vector4.ONE*2, Vector4.ONE*3, Vector4.ZERO]]
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_Plane(variant_type: int, value: Plane, expected: String, _test_parameters := [
|
||||
[TYPE_PLANE, Plane(), "Plane()"],
|
||||
[TYPE_PLANE, Plane(1,2,3,4), "Plane(1, 2, 3, 4)"],
|
||||
[TYPE_PLANE, Plane(Vector3.ONE, Vector3.ZERO), "Plane(1, 1, 1, 0)"],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_Quaternion(variant_type: int, value: Quaternion, expected: String, _test_parameters := [
|
||||
[TYPE_QUATERNION, Quaternion(), "Quaternion()"],
|
||||
[TYPE_QUATERNION, Quaternion(1,2,3,4), "Quaternion(1, 2, 3, 4)"],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_AABB(variant_type: int, value: AABB, expected: String, _test_parameters := [
|
||||
[TYPE_AABB, AABB(), "AABB()"],
|
||||
[TYPE_AABB, AABB(Vector3.ONE, Vector3(10,20,30)), "AABB(Vector3"+str(Vector3(1, 1, 1))+", Vector3"+str(Vector3(10, 20, 30))+")"],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_Basis(variant_type: int, value: Basis, expected: String, _test_parameters := [
|
||||
[TYPE_BASIS, Basis(), "Basis()"],
|
||||
[TYPE_BASIS, Basis(Vector3(0.1,0.2,0.3).normalized(), .1),
|
||||
"Basis(Vector3(0.995361, 0.080758, -0.052293), Vector3(-0.079331, 0.996432, 0.028823), Vector3(0.054434, -0.024541, 0.998216))"],
|
||||
[TYPE_BASIS, Basis(Vector3.ONE, Vector3.ONE*2, Vector3.ONE*3),
|
||||
"Basis(Vector3"+str(Vector3(1, 1, 1))+", Vector3"+str(Vector3(2, 2, 2))+", Vector3"+str(Vector3(3, 3, 3))+")"],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_Color(variant_type: int, value: Color, expected: String, _test_parameters := [
|
||||
[TYPE_COLOR, Color(), "Color()"],
|
||||
[TYPE_COLOR, Color.RED, "Color"+str(Color(1, 0, 0, 1))],
|
||||
[TYPE_COLOR, Color(1,.2,.5,.5), "Color"+str(Color(1, 0.2, 0.5, 0.5))],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_NodePath(variant_type: int, value: NodePath, expected: String, _test_parameters := [
|
||||
[TYPE_NODE_PATH, NodePath(), 'NodePath()'],
|
||||
[TYPE_NODE_PATH, NodePath("/foo/bar"), 'NodePath("/foo/bar")'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_RID(variant_type: int, value: RID, expected: String, _test_parameters := [
|
||||
[TYPE_RID, RID(), 'RID()'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func _test_decode_Object(variant_type: int, value: Node, expected: String, _test_parameters := [
|
||||
[TYPE_OBJECT, Node.new(), 'Node.new()'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_Callable(variant_type: int, value: Callable, expected: String, _test_parameters := [
|
||||
[TYPE_CALLABLE, Callable(), 'Callable()'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_Signal(variant_type: int, value: Signal, expected: String, _test_parameters := [
|
||||
[TYPE_SIGNAL, Signal(), 'Signal()'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_Dictionary(variant_type: int, value: Dictionary, expected: String, _test_parameters := [
|
||||
[TYPE_DICTIONARY, {}, '{}'],
|
||||
[TYPE_DICTIONARY, Dictionary(), '{}'],
|
||||
[TYPE_DICTIONARY, {1:2, 2:3}, '{ 1: 2, 2: 3 }'],
|
||||
[TYPE_DICTIONARY, {"aa":2, "bb":"cc"}, '{ "aa": 2, "bb": "cc" }'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_Array(variant_type: int, value: Array, expected: String, _test_parameters := [
|
||||
[TYPE_ARRAY, [], '[]'],
|
||||
[TYPE_ARRAY, Array(), '[]'],
|
||||
[TYPE_ARRAY, [1,2,3], '[1, 2, 3]'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
func test_decode_typedArrays(variant_type: int, value: Variant, expected: String, _test_parameters := [
|
||||
[TYPE_PACKED_BYTE_ARRAY, PackedByteArray(),
|
||||
'PackedByteArray()'],
|
||||
[TYPE_PACKED_BYTE_ARRAY, PackedByteArray([1, 2, 3]),
|
||||
'PackedByteArray([1, 2, 3])'],
|
||||
[TYPE_PACKED_COLOR_ARRAY, PackedColorArray(),
|
||||
'PackedColorArray()'],
|
||||
[TYPE_PACKED_COLOR_ARRAY, PackedColorArray([Color.RED, Color.BLUE]),
|
||||
'PackedColorArray([Color'+str(Color(1, 0, 0, 1))+', Color'+str(Color(0, 0, 1, 1))+'])'],
|
||||
[TYPE_PACKED_FLOAT32_ARRAY, PackedFloat32Array(),
|
||||
'PackedFloat32Array()'],
|
||||
[TYPE_PACKED_FLOAT32_ARRAY, PackedFloat32Array([1.2, 2.3]),
|
||||
'PackedFloat32Array([1.20000004768372, 2.29999995231628])'],
|
||||
[TYPE_PACKED_FLOAT64_ARRAY, PackedFloat64Array(),
|
||||
'PackedFloat64Array()'],
|
||||
[TYPE_PACKED_FLOAT64_ARRAY, PackedFloat64Array([1.2, 2.3]),
|
||||
'PackedFloat64Array([1.2, 2.3])'],
|
||||
[TYPE_PACKED_INT32_ARRAY, PackedInt32Array(),
|
||||
'PackedInt32Array()'],
|
||||
[TYPE_PACKED_INT32_ARRAY, PackedInt32Array([1, 2]),
|
||||
'PackedInt32Array([1, 2])'],
|
||||
[TYPE_PACKED_INT64_ARRAY, PackedInt64Array(),
|
||||
'PackedInt64Array()'],
|
||||
[TYPE_PACKED_INT64_ARRAY, PackedInt64Array([1, 2]),
|
||||
'PackedInt64Array([1, 2])'],
|
||||
[TYPE_PACKED_STRING_ARRAY, PackedStringArray(),
|
||||
'PackedStringArray()'],
|
||||
[TYPE_PACKED_STRING_ARRAY, PackedStringArray(["aa", "bb"]),
|
||||
'PackedStringArray(["aa", "bb"])'],
|
||||
[TYPE_PACKED_VECTOR2_ARRAY, PackedVector2Array(),
|
||||
'PackedVector2Array()'],
|
||||
[TYPE_PACKED_VECTOR2_ARRAY, PackedVector2Array([Vector2.ONE, Vector2.ONE*2]),
|
||||
'PackedVector2Array([Vector2'+str(Vector2.ONE)+', Vector2'+str(Vector2.ONE*2)+'])'],
|
||||
[TYPE_PACKED_VECTOR3_ARRAY, PackedVector3Array(),
|
||||
'PackedVector3Array()'],
|
||||
[TYPE_PACKED_VECTOR3_ARRAY, PackedVector3Array([Vector3.ONE, Vector3.ONE*2]),
|
||||
'PackedVector3Array([Vector3'+str(Vector3.ONE)+', Vector3'+str(Vector3.ONE*2)+'])'],
|
||||
[TYPE_PACKED_VECTOR4_ARRAY, PackedVector4Array(),
|
||||
'PackedVector4Array()'],
|
||||
[TYPE_PACKED_VECTOR4_ARRAY, PackedVector4Array([Vector4.ONE, Vector4.ONE*2]),
|
||||
'PackedVector4Array([Vector4'+str(Vector4.ONE)+', Vector4'+str(Vector4.ONE*2)+'])']
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
@@ -0,0 +1 @@
|
||||
uid://63mvutq5fu8b
|
||||
@@ -0,0 +1,125 @@
|
||||
# GdUnit generated TestSuite
|
||||
class_name GdFunctionArgumentTest
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/parse/GdFunctionArgument.gd'
|
||||
|
||||
|
||||
func test__parse_argument_as_array_typ1() -> void:
|
||||
var test_parameters := """[
|
||||
[1, "flowchart TD\nid>This is a flag shaped node]"],
|
||||
[
|
||||
2,
|
||||
"flowchart TD\nid(((This is a\tdouble circle node)))"
|
||||
],
|
||||
[3,
|
||||
"flowchart TD\nid((This is a circular node))"],
|
||||
[
|
||||
4, "flowchart TD\nid>This is a flag shaped node]"
|
||||
],
|
||||
[5, "flowchart TD\nid{'This is a rhombus node'}"],
|
||||
[6, 'flowchart TD\nid((This is a circular node))'],
|
||||
[7, 'flowchart TD\nid>This is a flag shaped node]'], [8, 'flowchart TD\nid{"This is a rhombus node"}'],
|
||||
[9, \"\"\"
|
||||
flowchart TD
|
||||
id{"This is a rhombus node"}
|
||||
\"\"\"]
|
||||
]"""
|
||||
|
||||
var fa := GdFunctionArgument.new("test_parameters", TYPE_STRING, test_parameters)
|
||||
assert_array(fa.parameter_sets()).contains_exactly([
|
||||
"""[1, "flowchart TDid>This is a flag shaped node]"]""",
|
||||
"""[2, "flowchart TDid(((This is a\tdouble circle node)))"]""",
|
||||
"""[3, "flowchart TDid((This is a circular node))"]""",
|
||||
"""[4, "flowchart TDid>This is a flag shaped node]"]""",
|
||||
"""[5, "flowchart TDid{'This is a rhombus node'}"]""",
|
||||
"""[6, 'flowchart TDid((This is a circular node))']""",
|
||||
"""[7, 'flowchart TDid>This is a flag shaped node]']""",
|
||||
"""[8, 'flowchart TDid{"This is a rhombus node"}']""",
|
||||
"""[9, \"\"\"flowchart TDid{"This is a rhombus node"}\"\"\"]"""
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
func test__parse_argument_as_array_typ2() -> void:
|
||||
var test_parameters := """[
|
||||
["test_a", null, "LOG", {}],
|
||||
[
|
||||
"test_b",
|
||||
Node2D,
|
||||
null,
|
||||
{Node2D: "ER,ROR"}
|
||||
],
|
||||
[
|
||||
"test_c",
|
||||
Node2D,
|
||||
"LOG",
|
||||
{Node2D: "LOG"}
|
||||
]
|
||||
]"""
|
||||
var fa := GdFunctionArgument.new("test_parameters", TYPE_STRING, test_parameters)
|
||||
assert_array(fa.parameter_sets()).contains_exactly([
|
||||
"""["test_a", null, "LOG", {}]""",
|
||||
"""["test_b", Node2D, null, {Node2D: "ER,ROR"}]""",
|
||||
"""["test_c", Node2D, "LOG", {Node2D: "LOG"}]"""
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
func test__parse_argument_as_array_bad_formatted() -> void:
|
||||
var test_parameters := """[
|
||||
["test_a", null, "LOG", {}],
|
||||
[
|
||||
"test_b",
|
||||
Node2D,
|
||||
null,
|
||||
{Node2D: "ER,ROR"}
|
||||
],
|
||||
[
|
||||
"test_c",
|
||||
Node2D,
|
||||
"LOG",
|
||||
{Node2D: "LOG 1"}
|
||||
]
|
||||
|
||||
]"""
|
||||
var fa := GdFunctionArgument.new("test_parameters", TYPE_STRING, test_parameters)
|
||||
assert_array(fa.parameter_sets()).contains_exactly([
|
||||
"""["test_a", null, "LOG", {}]""",
|
||||
"""["test_b", Node2D, null, {Node2D: "ER,ROR"}]""",
|
||||
"""["test_c", Node2D, "LOG", {Node2D: "LOG 1"}]"""
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
func test_parse_argument_as_array_ends_with_additional_comma() -> void:
|
||||
var test_parameters := """
|
||||
[
|
||||
[true, 'bool'],
|
||||
[42, 'int'],
|
||||
['foo', 'String'],
|
||||
]"""
|
||||
var fa := GdFunctionArgument.new("test_parameters", TYPE_STRING, test_parameters)
|
||||
assert_array(fa.parameter_sets()).contains_exactly([
|
||||
"""[true, 'bool']""",
|
||||
"""[42, 'int']""",
|
||||
"""['foo', 'String']"""
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
func test__parse_argument_as_reference() -> void:
|
||||
var test_parameters := "_test_args()"
|
||||
|
||||
var fa := GdFunctionArgument.new("test_parameters", TYPE_STRING, test_parameters)
|
||||
assert_array(fa.parameter_sets()).is_empty()
|
||||
|
||||
|
||||
func test_parse_parameter_set_with_const_data_in_array() -> void:
|
||||
var test_parameters := "[_data1, _data2]"
|
||||
|
||||
var fa := GdFunctionArgument.new("test_parameters", TYPE_STRING, test_parameters)
|
||||
assert_array(fa.parameter_sets()).contains_exactly(["_data1", "_data2"])
|
||||
@@ -0,0 +1 @@
|
||||
uid://ra66tiyw0ni4
|
||||
@@ -0,0 +1,149 @@
|
||||
# GdUnit generated TestSuite
|
||||
class_name GdFunctionDescriptorTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/parse/GdFunctionDescriptor.gd'
|
||||
|
||||
|
||||
# helper to get method descriptor
|
||||
func get_method_description(clazz_name :String, method_name :String) -> Dictionary:
|
||||
var method_list :Array = ClassDB.class_get_method_list(clazz_name)
|
||||
for method_descriptor :Dictionary in method_list:
|
||||
if method_descriptor["name"] == method_name:
|
||||
return method_descriptor
|
||||
return Dictionary()
|
||||
|
||||
|
||||
func test_extract_from_func_without_return_type() -> void:
|
||||
# void add_sibling(sibling: Node, force_readable_name: bool = false)
|
||||
var method_descriptor := get_method_description("Node", "add_sibling")
|
||||
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
|
||||
assert_str(fd.name()).is_equal("add_sibling")
|
||||
assert_bool(fd.is_virtual()).is_false()
|
||||
assert_bool(fd.is_static()).is_false()
|
||||
assert_bool(fd.is_engine()).is_true()
|
||||
assert_bool(fd.is_vararg()).is_false()
|
||||
assert_int(fd.return_type()).is_equal(GdObjects.TYPE_VOID)
|
||||
assert_array(fd.args()).contains_exactly([
|
||||
GdFunctionArgument.new("sibling", GdObjects.TYPE_NODE),
|
||||
GdFunctionArgument.new("force_readable_name", TYPE_BOOL, false)
|
||||
])
|
||||
|
||||
|
||||
func test_extract_from_func_with_return_type() -> void:
|
||||
# Node find_child(pattern: String, recursive: bool = true, owned: bool = true) const
|
||||
var method_descriptor := get_method_description("Node", "find_child")
|
||||
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
|
||||
assert_str(fd.name()).is_equal("find_child")
|
||||
assert_bool(fd.is_virtual()).is_false()
|
||||
assert_bool(fd.is_static()).is_false()
|
||||
assert_bool(fd.is_engine()).is_true()
|
||||
assert_bool(fd.is_vararg()).is_false()
|
||||
assert_int(fd.return_type()).is_equal(TYPE_OBJECT)
|
||||
assert_array(fd.args()).contains_exactly([
|
||||
GdFunctionArgument.new("pattern", TYPE_STRING),
|
||||
GdFunctionArgument.new("recursive", TYPE_BOOL, true),
|
||||
GdFunctionArgument.new("owned", TYPE_BOOL, true),
|
||||
])
|
||||
|
||||
|
||||
func test_extract_from_func_with_vararg() -> void:
|
||||
# Error emit_signal(signal: StringName, ...) vararg
|
||||
var method_descriptor := get_method_description("Node", "emit_signal")
|
||||
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
|
||||
assert_str(fd.name()).is_equal("emit_signal")
|
||||
assert_bool(fd.is_virtual()).is_false()
|
||||
assert_bool(fd.is_static()).is_false()
|
||||
assert_bool(fd.is_engine()).is_true()
|
||||
assert_bool(fd.is_vararg()).is_true()
|
||||
assert_int(fd.return_type()).is_equal(GdObjects.TYPE_ENUM)
|
||||
assert_array(fd.args()).contains_exactly([GdFunctionArgument.new("signal", TYPE_STRING_NAME)])
|
||||
assert_array(fd.varargs()).contains_exactly([
|
||||
GdFunctionArgument.new("varargs", GdObjects.TYPE_VARARG, '')
|
||||
])
|
||||
|
||||
|
||||
func test_extract_from_descriptor_is_virtual_func() -> void:
|
||||
var method_descriptor := get_method_description("Node", "_enter_tree")
|
||||
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
|
||||
assert_str(fd.name()).is_equal("_enter_tree")
|
||||
assert_bool(fd.is_virtual()).is_true()
|
||||
assert_bool(fd.is_static()).is_false()
|
||||
assert_bool(fd.is_engine()).is_true()
|
||||
assert_bool(fd.is_vararg()).is_false()
|
||||
assert_int(fd.return_type()).is_equal(GdObjects.TYPE_VOID)
|
||||
assert_array(fd.args()).is_empty()
|
||||
|
||||
|
||||
func test_extract_from_descriptor_is_virtual_func_full_check() -> void:
|
||||
var methods := ClassDB.class_get_method_list("Node")
|
||||
var expected_virtual_functions := [
|
||||
"_process",
|
||||
"_physics_process",
|
||||
"_enter_tree",
|
||||
"_exit_tree",
|
||||
"_ready",
|
||||
"_get_configuration_warnings",
|
||||
"_get_accessibility_configuration_warnings",
|
||||
"_input",
|
||||
"_shortcut_input",
|
||||
"_unhandled_input",
|
||||
"_unhandled_key_input",
|
||||
"_get_focused_accessibility_element",
|
||||
"_init",
|
||||
"_to_string",
|
||||
"_notification",
|
||||
"_set",
|
||||
"_get",
|
||||
"_get_property_list",
|
||||
"_validate_property",
|
||||
"_property_can_revert",
|
||||
"_property_get_revert",
|
||||
"_iter_init",
|
||||
"_iter_next",
|
||||
"_iter_get"
|
||||
]
|
||||
|
||||
var _count := 0
|
||||
for method_descriptor in methods:
|
||||
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
|
||||
|
||||
if fd.is_virtual():
|
||||
_count += 1
|
||||
assert_array(expected_virtual_functions).contains([fd.name()])
|
||||
assert_int(_count).is_equal(expected_virtual_functions.size())
|
||||
|
||||
|
||||
func test_extract_from_func_with_return_type_variant() -> void:
|
||||
var method_descriptor := get_method_description("Node", "get")
|
||||
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
|
||||
assert_str(fd.name()).is_equal("get")
|
||||
assert_bool(fd.is_virtual()).is_false()
|
||||
assert_bool(fd.is_static()).is_false()
|
||||
assert_bool(fd.is_engine()).is_true()
|
||||
assert_bool(fd.is_vararg()).is_false()
|
||||
assert_int(fd.return_type()).is_equal(GdObjects.TYPE_VARIANT)
|
||||
assert_array(fd.args()).contains_exactly([
|
||||
GdFunctionArgument.new("property", TYPE_STRING_NAME),
|
||||
])
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_extract_return_type(info: String, expected: int, descriptor: Dictionary, test_parameters := [
|
||||
['return_undefined', GdObjects.TYPE_VARIANT, { "name": "", "class_name": &"", "type": 0, "hint": 0, "hint_string": "", "usage": 131072 }],
|
||||
['return_variant', GdObjects.TYPE_VARIANT, { "name": "", "class_name": &"", "type": 0, "hint": 0, "hint_string": "", "usage": 131072 }],
|
||||
['return_int', TYPE_INT, { "name": "", "class_name": &"", "type": 2, "hint": 0, "hint_string": "", "usage": 0 }],
|
||||
['return_string', TYPE_STRING, { "name": "", "class_name": &"", "type": 4, "hint": 0, "hint_string": "", "usage": 0 }],
|
||||
['return_void', GdObjects.TYPE_VOID, { "name": "", "class_name": &"", "type": 0, "hint": 0, "hint_string": "", "usage": 6 }]
|
||||
]) -> void:
|
||||
var return_type := GdFunctionDescriptor._extract_return_type(descriptor)
|
||||
assert_that(return_type).is_equal(expected)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func example_signature(info: String, expected: int, test_parameters := [
|
||||
["aaa", 10],
|
||||
["bbb", 11],
|
||||
]) -> void:
|
||||
pass
|
||||
@@ -0,0 +1 @@
|
||||
uid://3t1wdu7pdy51
|
||||
@@ -0,0 +1,757 @@
|
||||
extends GdUnitTestSuite
|
||||
|
||||
var _parser: GdScriptParser
|
||||
|
||||
const TYPE_VOID = GdObjects.TYPE_VOID
|
||||
const TYPE_VARIANT = GdObjects.TYPE_VARIANT
|
||||
const TYPE_VARARG = GdObjects.TYPE_VARARG
|
||||
const TYPE_FUNC = GdObjects.TYPE_FUNC
|
||||
const TYPE_FUZZER = GdObjects.TYPE_FUZZER
|
||||
const TYPE_ENUM = GdObjects.TYPE_ENUM
|
||||
|
||||
|
||||
static func build_tmp_script(source_code: String) -> GDScript:
|
||||
var script := GDScript.new()
|
||||
script.source_code = source_code.dedent()
|
||||
script.resource_path = GdUnitFileAccess.temp_dir() + "/tmp_%d.gd" % script.get_instance_id()
|
||||
var file := FileAccess.open(script.resource_path, FileAccess.WRITE)
|
||||
file.store_string(script.source_code)
|
||||
file.close()
|
||||
|
||||
var unsafe_method_access: Variant = ProjectSettings.get_setting("debug/gdscript/warnings/unsafe_method_access")
|
||||
var unused_parameter: Variant = ProjectSettings.get_setting("debug/gdscript/warnings/unused_parameter")
|
||||
# disable and load the script
|
||||
ProjectSettings.set_setting("debug/gdscript/warnings/unsafe_method_access", 0)
|
||||
ProjectSettings.set_setting("debug/gdscript/warnings/unused_parameter", 0)
|
||||
var error := script.reload()
|
||||
ProjectSettings.set_setting("debug/gdscript/warnings/unsafe_method_access", unsafe_method_access)
|
||||
ProjectSettings.set_setting("debug/gdscript/warnings/unused_parameter", unused_parameter)
|
||||
if error:
|
||||
push_error("Can't load temp script '%s', error: %s" % [source_code, error_string(error)])
|
||||
return null
|
||||
return script
|
||||
|
||||
|
||||
func before() -> void:
|
||||
_parser = GdScriptParser.new()
|
||||
|
||||
|
||||
func after() -> void:
|
||||
clean_temp_dir()
|
||||
|
||||
|
||||
func test_parse_function_arguments() -> void:
|
||||
assert_array(_parser._parse_function_arguments("func foo():")) \
|
||||
.has_size(0)
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func foo() -> String:\n")) \
|
||||
.has_size(0)
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1, arg2, name):")) \
|
||||
.has_size(3)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_VARIANT, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "name", "type" : TYPE_VARIANT, "value" : GdFunctionArgument.UNDEFINED},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments('func foo(arg1 :int, arg2 :bool, name :String = "abc"):')) \
|
||||
.has_size(3)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_INT, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_BOOL, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "name", "type" : TYPE_STRING, "value" : '"abc"'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments('func bar(arg1 :int, arg2 :int = 23, name :String = "test") -> String:')) \
|
||||
.has_size(3)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_INT, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_INT, "value" : "23"},
|
||||
{"name" : "name", "type" : TYPE_STRING, "value" : '"test"'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1, arg2=value(1,2,3), name:=foo()):")) \
|
||||
.has_size(3)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_VARIANT, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : "value(1,2,3)"},
|
||||
{"name" : "name", "type" : TYPE_VARIANT, "value" : "foo()"},
|
||||
])
|
||||
|
||||
# enum as prefix in value name
|
||||
assert_array(_parser._parse_function_arguments("func get_value( type := ENUM_A) -> int:"))\
|
||||
.has_size(1)\
|
||||
.contains([
|
||||
{"name" : "type", "type" : TYPE_VARIANT, "value" : "ENUM_A"},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func create_timer(timeout :float) -> Timer:")) \
|
||||
.has_size(1)\
|
||||
.contains([
|
||||
{"name" : "timeout", "type" : TYPE_FLOAT, "value" : GdFunctionArgument.UNDEFINED},
|
||||
])
|
||||
|
||||
# array argument
|
||||
assert_array(_parser._parse_function_arguments("func foo(a :int, b :int, parameters = [[1, 2], [3, 4], [5, 6]]):")) \
|
||||
.has_size(3)\
|
||||
.contains([
|
||||
{"name" : "a", "type" : TYPE_INT, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "b", "type" : TYPE_INT, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "parameters", "type" : TYPE_VARIANT, "value" : "[[1, 2], [3, 4], [5, 6]]"},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func test_values(a:Vector2, b:Vector2, expected:Vector2, test_parameters:=[[Vector2.ONE,Vector2.ONE,Vector2(1,1)]]):"))\
|
||||
.has_size(4)\
|
||||
.contains([
|
||||
{"name" : "a", "type" : TYPE_VECTOR2, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "b", "type" : TYPE_VECTOR2, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "expected", "type" : TYPE_VECTOR2, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "test_parameters", "type" : TYPE_VARIANT, "value" : "[[Vector2.ONE,Vector2.ONE,Vector2(1,1)]]"},
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_with_super_constructor() -> void:
|
||||
assert_array(_parser._parse_function_arguments('func foo().foo("abc"):')).is_empty()
|
||||
assert_array(_parser._parse_function_arguments('func foo(arg1 = "arg").foo("abc", arg1):'))\
|
||||
.has_size(1)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_VARIANT, "value" : '"arg"'},
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_string() -> void:
|
||||
assert_array(_parser._parse_function_arguments('func foo(arg1 :String, arg2="default"):')) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : '"default"'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments('func foo(arg1 :String, arg2 :="default"):')) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : '"default"'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments('func foo(arg1 :String, arg2 :String ="default"):')) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_STRING, "value" : '"default"'},
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_boolean() -> void:
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2=false):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : 'false'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2 :=false):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : 'false'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2 :bool=false):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_BOOL, "value" : 'false'},
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_float() -> void:
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2=3.14):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : '3.14'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2 :=3.14):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : '3.14'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2 :float=3.14):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_FLOAT, "value" : '3.14'},
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_array() -> void:
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2 :Array=[]):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_ARRAY, "value" : '[]'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2 :Array=Array()):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_ARRAY, "value" : 'Array()'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2 :Array=[1, 2, 3]):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_ARRAY, "value" : '[1, 2, 3]'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2 :=[1, 2, 3]):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : '[1, 2, 3]'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2=[]):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : '[]'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2 :Array=[1, 2, 3], arg3 := false):")) \
|
||||
.has_size(3)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_ARRAY, "value" : '[1, 2, 3]'},
|
||||
{"name" : "arg3", "type" : TYPE_VARIANT, "value" : 'false'},
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_color() -> void:
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2=Color.RED):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : 'Color.RED'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2 :=Color.RED):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : 'Color.RED'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func foo(arg1 :String, arg2 :Color=Color.RED):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_COLOR, "value" : 'Color.RED'},
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_vector() -> void:
|
||||
assert_array(_parser._parse_function_arguments("func bar(arg1 :String, arg2 =Vector3.FORWARD):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : 'Vector3.FORWARD'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func bar(arg1 :String, arg2 :=Vector3.FORWARD):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : 'Vector3.FORWARD'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func bar(arg1 :String, arg2 :Vector3=Vector3.FORWARD):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VECTOR3, "value" : 'Vector3.FORWARD'},
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_AABB() -> void:
|
||||
assert_array(_parser._parse_function_arguments("func bar(arg1 :String, arg2 := AABB()):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : 'AABB()'},
|
||||
])
|
||||
|
||||
assert_array(_parser._parse_function_arguments("func bar(arg1 :String, arg2 :AABB=AABB()):")) \
|
||||
.has_size(2)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_AABB, "value" : 'AABB()'},
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_types() -> void:
|
||||
assert_array(_parser._parse_function_arguments("func bar(arg1 :String, arg2 := Vector3.FORWARD, aabb := AABB()):")) \
|
||||
.has_size(3)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_STRING, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_VARIANT, "value" : 'Vector3.FORWARD'},
|
||||
{"name" : "aabb", "type" : TYPE_VARIANT, "value" : 'AABB()'},
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_fuzzers() -> void:
|
||||
assert_array(_parser._parse_function_arguments("func test_foo(fuzzer_a = fuzz_a(), fuzzer_b := fuzz_b(), fuzzer_c :Fuzzer = fuzz_c(), fuzzer_iterations = 234, fuzzer_seed = 100):")) \
|
||||
.has_size(5)\
|
||||
.contains([
|
||||
{"name" : "fuzzer_a", "type" : TYPE_FUZZER, "value" : 'fuzz_a()'},
|
||||
{"name" : "fuzzer_b", "type" : TYPE_FUZZER, "value" : 'fuzz_b()'},
|
||||
{"name" : "fuzzer_c", "type" : TYPE_FUZZER, "value" : 'fuzz_c()'},
|
||||
{"name" : "fuzzer_iterations", "type" : TYPE_VARIANT, "value" : '234'},
|
||||
{"name" : "fuzzer_seed", "type" : TYPE_VARIANT, "value" : '100'},
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_typed_dict() -> void:
|
||||
assert_array(_parser._parse_function_arguments('func generate(arg1: Dictionary[String,Variant], arg2 :Dictionary = {"a":1, "b":2}, arg3 := {}) -> void:'))\
|
||||
.has_size(3)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_DICTIONARY, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_DICTIONARY, "value" : '{"a":1, "b":2}'},
|
||||
{"name" : "arg3", "type" : TYPE_VARIANT, "value" : '{}'},
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_variant() -> void:
|
||||
# remove this line and complete your test
|
||||
var args := _parser._parse_function_arguments('func generate(
|
||||
ucids: Array[int],
|
||||
position: Vector2i,
|
||||
size: Vector2i,
|
||||
style: int,
|
||||
text: Variant = "",
|
||||
button_name := "",
|
||||
type_in := 0,
|
||||
caption := "",
|
||||
show_everywhere := false')
|
||||
|
||||
assert_array(args)\
|
||||
.has_size(9)\
|
||||
.contains([
|
||||
{"name" : "ucids", "type" : TYPE_ARRAY, "value" : GdFunctionArgument.UNDEFINED, },
|
||||
{"name" : "position", "type" : TYPE_VECTOR2I, "value" : GdFunctionArgument.UNDEFINED, },
|
||||
{"name" : "size", "type" : TYPE_VECTOR2I, "value" : GdFunctionArgument.UNDEFINED },
|
||||
{"name" : "style", "type" : TYPE_INT, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "text", "type" : TYPE_VARIANT, "value" : '""'},
|
||||
{"name" : "button_name", "type" : TYPE_VARIANT, "value" : '""'},
|
||||
{"name" : "type_in", "type" : TYPE_VARIANT, "value" : '0'},
|
||||
{"name" : "caption", "type" : TYPE_VARIANT, "value" : '""'},
|
||||
{"name" : "show_everywhere", "type" : TYPE_VARIANT, "value" : 'false'},
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_variadic() -> void:
|
||||
var args := _parser._parse_function_arguments('func call(...args: Array) -> Variant:')
|
||||
assert_array(args)\
|
||||
.has_size(1)\
|
||||
.contains([
|
||||
{"name" : "args", "type" : TYPE_VARARG, "value" : GdFunctionArgument.UNDEFINED}
|
||||
])
|
||||
|
||||
var script := GDScript.new()
|
||||
script.source_code = """
|
||||
@warning_ignore("unused_parameter")
|
||||
func custom(name: String, ...varargs: Array) -> int:
|
||||
return 0
|
||||
""".dedent()
|
||||
script.reload()
|
||||
|
||||
# Try to enrich function arguments should not affect the argumens on variadic argument
|
||||
var fds := _parser.get_function_descriptors(script, ["custom"])
|
||||
_parser._enrich_function_descriptor(script, fds)
|
||||
|
||||
|
||||
func test_parse_arguments_typed_array() -> void:
|
||||
# remove this line and complete your test
|
||||
assert_array(_parser._parse_function_arguments("func generate(arg1: Array, arg2: Array = [1,2,3], arg3: Array[int] = [4,5,6], arg4 := []) -> void:"))\
|
||||
.has_size(4)\
|
||||
.contains([
|
||||
{"name" : "arg1", "type" : TYPE_ARRAY, "value" : GdFunctionArgument.UNDEFINED},
|
||||
{"name" : "arg2", "type" : TYPE_ARRAY, "value" : '[1,2,3]'},
|
||||
{"name" : "arg3", "type" : TYPE_ARRAY, "value" : '[4,5,6]'},
|
||||
{"name" : "arg4", "type" : TYPE_VARIANT, "value" : '[]'},
|
||||
])
|
||||
|
||||
|
||||
class TestObject:
|
||||
var x: int
|
||||
|
||||
|
||||
func test_parse_func_name() -> void:
|
||||
assert_str(_parser.parse_func_name("func foo():")).is_equal("foo")
|
||||
assert_str(_parser.parse_func_name("static func foo():")).is_equal("foo")
|
||||
assert_str(_parser.parse_func_name("func a() -> String:")).is_equal("a")
|
||||
# function name contains tokens e.g func or class
|
||||
assert_str(_parser.parse_func_name("func foo_func_class():")).is_equal("foo_func_class")
|
||||
# unicode characters in the name
|
||||
assert_str(_parser.parse_func_name("func test_日本語() -> void:")).is_equal("test_日本語")
|
||||
# should fail
|
||||
assert_str(_parser.parse_func_name("#func foo():")).is_empty()
|
||||
assert_str(_parser.parse_func_name("var x")).is_empty()
|
||||
|
||||
func test_load_source_code_inner_class_AtmosphereData() -> void:
|
||||
var base_class := AdvancedTestClass.new()
|
||||
@warning_ignore("unsafe_cast")
|
||||
var rows := _parser._load_inner_class(base_class.get_script() as GDScript, "AtmosphereData")
|
||||
var file_content := resource_as_string("res://addons/gdUnit4/test/core/resources/AtmosphereData.txt")
|
||||
assert_that(rows).is_equal(file_content)
|
||||
|
||||
|
||||
func test_load_source_code_inner_class_SoundData() -> void:
|
||||
var base_class := AdvancedTestClass.new()
|
||||
@warning_ignore("unsafe_cast")
|
||||
var rows := _parser._load_inner_class(base_class.get_script() as GDScript, "SoundData")
|
||||
var file_content := resource_as_string("res://addons/gdUnit4/test/core/resources/SoundData.txt")
|
||||
assert_that(rows).is_equal(file_content)
|
||||
|
||||
|
||||
func test_load_source_code_inner_class_Area4D() -> void:
|
||||
var base_class := AdvancedTestClass.new()
|
||||
@warning_ignore("unsafe_cast")
|
||||
var rows := _parser._load_inner_class(base_class.get_script() as GDScript, "Area4D")
|
||||
var file_content := resource_as_string("res://addons/gdUnit4/test/core/resources/Area4D.txt")
|
||||
assert_that(rows).is_equal(file_content)
|
||||
|
||||
|
||||
func test_extract_function_signature() -> void:
|
||||
var script :GDScript = load("res://addons/gdUnit4/test/mocker/resources/ClassWithCustomFormattings.gd")
|
||||
var rows := script.source_code.split("\n")
|
||||
|
||||
assert_that(_parser.extract_func_signature(rows, 12))\
|
||||
.is_equal("""
|
||||
func a1(set_name:String, path:String="", load_on_init:bool=false,
|
||||
set_auto_save:bool=false, set_network_sync:bool=false
|
||||
) -> void:""".dedent().trim_prefix("\n"))
|
||||
assert_that(_parser.extract_func_signature(rows, 19))\
|
||||
.is_equal("""
|
||||
func a2(set_name:String, path:String="", load_on_init:bool=false,
|
||||
set_auto_save:bool=false, set_network_sync:bool=false
|
||||
) -> void:""".dedent().trim_prefix("\n"))
|
||||
assert_that(_parser.extract_func_signature(rows, 26))\
|
||||
.is_equal("""
|
||||
func a3(set_name:String, path:String="", load_on_init:bool=false,
|
||||
set_auto_save:bool=false, set_network_sync:bool=false
|
||||
) -> void:""".dedent().trim_prefix("\n"))
|
||||
assert_that(_parser.extract_func_signature(rows, 33))\
|
||||
.is_equal("""
|
||||
func a4(set_name:String,
|
||||
path:String="",
|
||||
load_on_init:bool=false,
|
||||
set_auto_save:bool=false,
|
||||
set_network_sync:bool=false
|
||||
) -> void:""".dedent().trim_prefix("\n"))
|
||||
assert_that(_parser.extract_func_signature(rows, 43))\
|
||||
.is_equal("""
|
||||
func a5(
|
||||
value : Array,
|
||||
expected : String,
|
||||
test_parameters : Array = [
|
||||
[ ["a"], "a" ],
|
||||
[ ["a", "very", "long", "argument"], "a very long argument" ],
|
||||
]
|
||||
) -> void:""".dedent().trim_prefix("\n"))
|
||||
|
||||
|
||||
func test_strip_leading_spaces() -> void:
|
||||
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces("")).is_empty()
|
||||
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces(" ")).is_empty()
|
||||
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces(" ")).is_empty()
|
||||
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces(" ")).is_equal(" ")
|
||||
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces("var x=")).is_equal("var x=")
|
||||
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces("class foo")).is_equal("class foo")
|
||||
|
||||
|
||||
func test_parse_func_description() -> void:
|
||||
var script := build_tmp_script("""
|
||||
|
||||
@warning_ignore("untyped_declaration")
|
||||
func foo0():
|
||||
pass
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
static func foo1(arg1: int, arg2: bool =false) -> String:
|
||||
return ""
|
||||
|
||||
@warning_ignore("untyped_declaration", "unused_parameter")
|
||||
static func foo2(arg1: int, arg2: bool =true):
|
||||
pass
|
||||
""")
|
||||
var fds := _parser.get_function_descriptors(script)
|
||||
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor.create("foo0", script.resource_path, 4, GdObjects.TYPE_VOID))
|
||||
|
||||
# static function
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor.create_static("foo1", script.resource_path, 8, TYPE_STRING, [
|
||||
GdFunctionArgument.new("arg1", TYPE_INT),
|
||||
GdFunctionArgument.new("arg2", TYPE_BOOL, false)
|
||||
]))
|
||||
|
||||
# static function without return type
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor.create_static("foo2", script.resource_path, 12, GdObjects.TYPE_VOID, [
|
||||
GdFunctionArgument.new("arg1", TYPE_INT),
|
||||
GdFunctionArgument.new("arg2", TYPE_BOOL, true)
|
||||
]))
|
||||
|
||||
|
||||
func test_get_function_descriptors_return_type_enum() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd")
|
||||
var fds := _parser.get_function_descriptors(script, ["get_enum"])
|
||||
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("get_enum", script.resource_path, 15, GdObjects.TYPE_ENUM)
|
||||
.with_return_class("ClassWithEnumReturnTypes.TEST_ENUM")
|
||||
)
|
||||
|
||||
|
||||
func test_parse_func_description_return_type_internal_class_enum() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd")
|
||||
var fds := _parser.get_function_descriptors(script, ["get_inner_class_enum"])
|
||||
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("get_inner_class_enum", script.resource_path, 25, GdObjects.TYPE_ENUM)
|
||||
.with_return_class("ClassWithEnumReturnTypes.InnerClass.TEST_ENUM")
|
||||
)
|
||||
|
||||
|
||||
func test_parse_func_description_return_type_external_class_enum() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd")
|
||||
var fds := _parser.get_function_descriptors(script, ["get_external_class_enum"])
|
||||
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("get_external_class_enum", script.resource_path, 20, GdObjects.TYPE_ENUM)
|
||||
.with_return_class("CustomEnums.TEST_ENUM")
|
||||
)
|
||||
|
||||
|
||||
func test_parse_class_inherits() -> void:
|
||||
var clazz_path := GdObjects.extract_class_path(CustomClassExtendsCustomClass)
|
||||
var clazz_name := GdObjects.extract_class_name_from_class_path(clazz_path)
|
||||
var result := _parser.parse(clazz_name, clazz_path)
|
||||
assert_result(result).is_success()
|
||||
|
||||
# verify class extraction
|
||||
var clazz_desccriptor :GdClassDescriptor = result.value()
|
||||
assert_object(clazz_desccriptor).is_not_null()
|
||||
assert_str(clazz_desccriptor.name()).is_equal("CustomClassExtendsCustomClass")
|
||||
assert_bool(clazz_desccriptor.is_inner_class()).is_false()
|
||||
assert_array(clazz_desccriptor.functions())\
|
||||
.contains_exactly([
|
||||
GdFunctionDescriptor.create("foo2", "res://addons/gdUnit4/test/mocker/resources/CustomClassExtendsCustomClass.gd", 6, GdObjects.TYPE_VARIANT),
|
||||
GdFunctionDescriptor.create("bar2", "res://addons/gdUnit4/test/mocker/resources/CustomClassExtendsCustomClass.gd", 9, TYPE_STRING),
|
||||
GdFunctionDescriptor.create("foo", "res://addons/gdUnit4/test/mocker/resources/CustomResourceTestClass.gd", 4, TYPE_STRING),
|
||||
GdFunctionDescriptor.create("foo_void", "res://addons/gdUnit4/test/mocker/resources/CustomResourceTestClass.gd", 10, GdObjects.TYPE_VOID),
|
||||
GdFunctionDescriptor.create("bar", "res://addons/gdUnit4/test/mocker/resources/CustomResourceTestClass.gd", 13, TYPE_STRING, [
|
||||
GdFunctionArgument.new("arg1", TYPE_INT),
|
||||
GdFunctionArgument.new("arg2", TYPE_INT, 23),
|
||||
GdFunctionArgument.new("name", TYPE_STRING, "test"),
|
||||
]),
|
||||
GdFunctionDescriptor.create("foo5", "res://addons/gdUnit4/test/mocker/resources/CustomResourceTestClass.gd", 17, GdObjects.TYPE_VOID),
|
||||
])
|
||||
|
||||
|
||||
func test_get_class_name_pascal_case() -> void:
|
||||
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithClassName.gd") as GDScript))\
|
||||
.is_equal("PascalCaseWithClassName")
|
||||
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithoutClassName.gd") as GDScript))\
|
||||
.is_equal("PascalCaseWithoutClassName")
|
||||
|
||||
|
||||
func test_get_class_name_snake_case() -> void:
|
||||
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_with_class_name.gd") as GDScript))\
|
||||
.is_equal("SnakeCaseWithClassName")
|
||||
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_without_class_name.gd") as GDScript))\
|
||||
.is_equal("SnakeCaseWithoutClassName")
|
||||
|
||||
|
||||
func test_get_class_with_extends_in_same_line() -> void:
|
||||
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/extends_on_same_line.gd") as GDScript))\
|
||||
.is_equal("ClassNameExtendsInSameLine")
|
||||
|
||||
|
||||
func test_is_func_end() -> void:
|
||||
assert_bool(_parser.is_func_end("")).is_false()
|
||||
assert_bool(_parser.is_func_end("func test_a():")).is_true()
|
||||
assert_bool(_parser.is_func_end("func test_a() -> void:")).is_true()
|
||||
assert_bool(_parser.is_func_end("func test_a(arg1) :")).is_true()
|
||||
assert_bool(_parser.is_func_end("func test_a(arg1 ): ")).is_true()
|
||||
assert_bool(_parser.is_func_end("func test_a(arg1 ): ")).is_true()
|
||||
assert_bool(_parser.is_func_end(" ):")).is_true()
|
||||
assert_bool(_parser.is_func_end(" ):")).is_true()
|
||||
assert_bool(_parser.is_func_end(" -> void:")).is_true()
|
||||
assert_bool(_parser.is_func_end(" ) -> void :")).is_true()
|
||||
assert_bool(_parser.is_func_end("func test_a(arg1, arg2 = {1:2} ):")).is_true()
|
||||
|
||||
|
||||
func test_extract_func_signature_multiline() -> void:
|
||||
var source_code := """
|
||||
|
||||
func test_parameterized(a: int, b :int, c :int, expected :int, test_parameters = [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 11],
|
||||
[6, 7, 8, 21] ]):
|
||||
|
||||
assert_that(a+b+c).is_equal(expected)
|
||||
""".dedent().split("\n")
|
||||
|
||||
var fs := _parser.extract_func_signature(source_code, 0)
|
||||
|
||||
assert_that(fs).is_equal("""
|
||||
func test_parameterized(a: int, b :int, c :int, expected :int, test_parameters = [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 11],
|
||||
[6, 7, 8, 21] ]):"""
|
||||
.dedent()
|
||||
.trim_prefix("\n")
|
||||
)
|
||||
|
||||
|
||||
func test_parse_func_description_paramized_test() -> void:
|
||||
var script := build_tmp_script("""
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_parameterized(a: int, b: int, c: int, expected: int, test_parameters: Array = [[1,2,3,6],[3,4,5,11],[6,7,8,21]]) -> Variant:
|
||||
return null
|
||||
""")
|
||||
var fds := GdScriptParser.new().get_function_descriptors(script, ["test_parameterized"])
|
||||
|
||||
assert_that(fds[0]).is_equal(GdFunctionDescriptor.create("test_parameterized", script.resource_path, 3, GdObjects.TYPE_VARIANT, [
|
||||
GdFunctionArgument.new("a", TYPE_INT),
|
||||
GdFunctionArgument.new("b", TYPE_INT),
|
||||
GdFunctionArgument.new("c", TYPE_INT),
|
||||
GdFunctionArgument.new("expected", TYPE_INT),
|
||||
GdFunctionArgument.new("test_parameters", TYPE_ARRAY, "[[1,2,3,6],[3,4,5,11],[6,7,8,21]]"),
|
||||
]))
|
||||
|
||||
|
||||
func test_parse_func_description_paramized_test_with_comments() -> void:
|
||||
var source_code := """
|
||||
func test_parameterized(a: int, b :int, c :int, expected :int, test_parameters = [
|
||||
# before data set
|
||||
[1, 2, 3, 6], # after data set
|
||||
# between data sets
|
||||
[3, 4, 5, 11],
|
||||
[6, 7, 'string #ABCD', 21], # dataset with [comment] singn
|
||||
[6, 7, "string #ABCD", 21] # dataset with "#comment" singn
|
||||
#eof
|
||||
]):
|
||||
pass
|
||||
""".dedent().split("\n")
|
||||
|
||||
var fs := _parser.extract_func_signature(source_code, 0)
|
||||
|
||||
assert_that(fs).is_equal("""
|
||||
func test_parameterized(a: int, b :int, c :int, expected :int, test_parameters = [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 11],
|
||||
[6, 7, 'string #ABCD', 21],
|
||||
[6, 7, "string #ABCD", 21]
|
||||
]):"""
|
||||
.dedent()
|
||||
.trim_prefix("\n")
|
||||
)
|
||||
|
||||
|
||||
func test_parse_func_descriptor_with_fuzzers() -> void:
|
||||
# using a mixure of typed and untyped default values
|
||||
var script := build_tmp_script("""
|
||||
func fuzz_a() -> Fuzzer:
|
||||
return Fuzzers.rangef(0, 10)
|
||||
|
||||
func fuzz_b() -> Fuzzer:
|
||||
return Fuzzers.rangef(0, 10)
|
||||
|
||||
func fuzz_c() -> Fuzzer:
|
||||
return Fuzzers.rangef(0, 10)
|
||||
|
||||
@warning_ignore("untyped_declaration", "unused_parameter", "inferred_declaration")
|
||||
func test_foo(fuzzer_a = fuzz_a(), fuzzer_b := fuzz_b(),
|
||||
fuzzer_c :Fuzzer = fuzz_c(),
|
||||
fuzzer = Fuzzers.rangei(-23, 22),
|
||||
fuzzer_iterations = 234,
|
||||
fuzzer_seed := 100):
|
||||
pass
|
||||
""")
|
||||
var fds := _parser.get_function_descriptors(script, ["test_foo"])
|
||||
|
||||
assert_that(fds[0]).is_equal(GdFunctionDescriptor.create("test_foo", script.resource_path, 12, GdObjects.TYPE_VOID, [
|
||||
# all fuzzer must by type TYPE_FUZZER
|
||||
GdFunctionArgument.new("fuzzer_a", GdObjects.TYPE_FUZZER, "fuzz_a()"),
|
||||
GdFunctionArgument.new("fuzzer_b", GdObjects.TYPE_FUZZER, "fuzz_b()"),
|
||||
GdFunctionArgument.new("fuzzer_c", GdObjects.TYPE_FUZZER, "fuzz_c()"),
|
||||
GdFunctionArgument.new("fuzzer", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(-23, 22)"),
|
||||
# untyped arg is TYPE_VARIANT
|
||||
GdFunctionArgument.new("fuzzer_iterations", GdObjects.TYPE_VARIANT, 234),
|
||||
# typed is TYPE_INT
|
||||
GdFunctionArgument.new("fuzzer_seed", TYPE_INT, 100)
|
||||
]))
|
||||
|
||||
|
||||
func test_is_func_coroutine() -> void:
|
||||
var script := """
|
||||
extends RefCounted:
|
||||
func normal_function() -> void:
|
||||
print("normal")
|
||||
|
||||
|
||||
func await_function() -> void:
|
||||
print(await _await_function())
|
||||
|
||||
|
||||
func _await_function() -> String:
|
||||
await get_tree().process_frame
|
||||
return "test"
|
||||
|
||||
|
||||
func check_is_waiting() -> String:
|
||||
return is_await()
|
||||
|
||||
|
||||
func print_message() -> String:
|
||||
return "do await for timeout"
|
||||
"""
|
||||
|
||||
var rows := script.split("\n")
|
||||
assert_bool(_parser.is_func_coroutine(rows, 2)).is_false()
|
||||
assert_bool(_parser.is_func_coroutine(rows, 6)).is_true()
|
||||
assert_bool(_parser.is_func_coroutine(rows, 10)).is_true()
|
||||
assert_bool(_parser.is_func_coroutine(rows, 15)).is_false()
|
||||
assert_bool(_parser.is_func_coroutine(rows, 19)).is_false()
|
||||
|
||||
|
||||
func test_using_class_in_variable_name() -> void:
|
||||
var script := """
|
||||
extends RefCounted:
|
||||
func foo() -> void:
|
||||
var class1.a = "a"
|
||||
var class2 = "abc"
|
||||
|
||||
|
||||
func bar() -> void:
|
||||
print("bar")
|
||||
|
||||
"""
|
||||
|
||||
var rows := script.split("\n")
|
||||
assert_bool(_parser.is_func_coroutine(rows, 0)).is_false()
|
||||
assert_bool(_parser.is_func_coroutine(rows, 4)).is_false()
|
||||
@@ -0,0 +1 @@
|
||||
uid://c0sil8ve4et5c
|
||||
@@ -0,0 +1,506 @@
|
||||
extends GdUnitTestSuite
|
||||
|
||||
var _parser: GdScriptParser
|
||||
|
||||
|
||||
func before() -> void:
|
||||
_parser = GdScriptParser.new()
|
||||
|
||||
|
||||
func after() -> void:
|
||||
clean_temp_dir()
|
||||
|
||||
|
||||
func test_default_args_dictionary() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/container_build_in_types/ClassWithDictionaryDefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_dictionary_case1", script.resource_path, 5, TYPE_ARRAY, [
|
||||
GdFunctionArgument.new("dict", TYPE_DICTIONARY, {}),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_dictionary_case2", script.resource_path, 9, TYPE_ARRAY, [
|
||||
GdFunctionArgument.new("dict", TYPE_DICTIONARY, {}),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_dictionary_case3", script.resource_path, 13, TYPE_ARRAY, [
|
||||
GdFunctionArgument.new("dict", TYPE_DICTIONARY, {}),
|
||||
])
|
||||
)
|
||||
assert_that(fds[3])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_dictionary_case4", script.resource_path, 17, TYPE_ARRAY, [
|
||||
GdFunctionArgument.new("dict", TYPE_DICTIONARY, {"a":"value_a", "b":"value_b"}),
|
||||
])
|
||||
)
|
||||
assert_that(fds[4])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_dictionary_case5", script.resource_path, 21, TYPE_ARRAY, [
|
||||
GdFunctionArgument.new("dict", TYPE_DICTIONARY, {"a":"value_a", "b":"value_b"}),
|
||||
])
|
||||
)
|
||||
assert_that(fds[5])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_dictionary_case6", script.resource_path, 27, TYPE_ARRAY, [
|
||||
GdFunctionArgument.new("dict", TYPE_DICTIONARY, {"a":"value_a", "b":"value_b"}),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_array() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/container_build_in_types/ClassWithArrayDefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_array_case1", script.resource_path, 5, TYPE_ARRAY, [
|
||||
GdFunctionArgument.new("values", TYPE_ARRAY, []),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_array_case2", script.resource_path, 9, TYPE_ARRAY, [
|
||||
GdFunctionArgument.new("values", TYPE_ARRAY, []),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_array_case3", script.resource_path, 13, TYPE_ARRAY, [
|
||||
GdFunctionArgument.new("values", TYPE_ARRAY, []),
|
||||
])
|
||||
)
|
||||
assert_that(fds[3])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_array_case4", script.resource_path, 17, TYPE_ARRAY, [
|
||||
GdFunctionArgument.new("values", TYPE_ARRAY, [1, "3", [], {}]),
|
||||
])
|
||||
)
|
||||
assert_that(fds[4])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_array_case5", script.resource_path, 21, TYPE_ARRAY, [
|
||||
GdFunctionArgument.new("values", TYPE_ARRAY, [1, "3", [], {}]),
|
||||
])
|
||||
)
|
||||
assert_that(fds[5])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_array_case6", script.resource_path, 29, TYPE_ARRAY, [
|
||||
GdFunctionArgument.new("values", TYPE_ARRAY, [1, "3", [], {}]),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_callable() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/container_build_in_types/ClassWithCallableDefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_callable_case1", script.resource_path, 5, TYPE_CALLABLE, [
|
||||
GdFunctionArgument.new("cb", TYPE_CALLABLE),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_callable_case2", script.resource_path, 9, TYPE_CALLABLE, [
|
||||
GdFunctionArgument.new("cb", TYPE_CALLABLE, Callable()),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_callable_case3", script.resource_path, 13, TYPE_CALLABLE, [
|
||||
GdFunctionArgument.new("cb", TYPE_CALLABLE, Callable()),
|
||||
])
|
||||
)
|
||||
assert_that(fds[3])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_callable_case4", script.resource_path, 17, TYPE_CALLABLE, [
|
||||
GdFunctionArgument.new("cb", TYPE_CALLABLE, Callable(null, "method_foo")),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_variant() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/ClassWithVariantTypeDefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("add_button", script.resource_path, 4, GdObjects.TYPE_VOID, [
|
||||
GdFunctionArgument.new("ucids", TYPE_ARRAY, GdFunctionArgument.UNDEFINED, TYPE_INT),
|
||||
GdFunctionArgument.new("position", TYPE_VECTOR2I),
|
||||
GdFunctionArgument.new("size", TYPE_VECTOR2I),
|
||||
GdFunctionArgument.new("style", TYPE_INT),
|
||||
GdFunctionArgument.new("text", GdObjects.TYPE_VARIANT, ""),
|
||||
GdFunctionArgument.new("button_name", TYPE_STRING, ""),
|
||||
GdFunctionArgument.new("type_in", TYPE_INT, 0),
|
||||
GdFunctionArgument.new("caption", TYPE_STRING, ""),
|
||||
GdFunctionArgument.new("show_everywhere", TYPE_BOOL, false),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
# Basic build-in-types
|
||||
func test_default_args_basic_type_int() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/basic_build_in_types/ClassWithBasicTypeIntDefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_int_case1", script.resource_path, 5, TYPE_INT, [
|
||||
GdFunctionArgument.new("value", TYPE_INT),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_int_case2", script.resource_path, 9, TYPE_INT, [
|
||||
GdFunctionArgument.new("value", TYPE_INT, 42),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_int_case3", script.resource_path, 13, TYPE_INT, [
|
||||
GdFunctionArgument.new("value", TYPE_INT, 42),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_basic_type_float() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/basic_build_in_types/ClassWithBasicTypeFloatDefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_float_case1", script.resource_path, 5, TYPE_FLOAT, [
|
||||
GdFunctionArgument.new("value", TYPE_FLOAT),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_float_case2", script.resource_path, 9, TYPE_FLOAT, [
|
||||
GdFunctionArgument.new("value", TYPE_FLOAT, 42.1),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_float_case3", script.resource_path, 13, TYPE_FLOAT, [
|
||||
GdFunctionArgument.new("value", TYPE_FLOAT, 42.1),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_basic_type_bool() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/basic_build_in_types/ClassWithBasicTypeBoolDefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_bool_case1", script.resource_path, 5, TYPE_BOOL, [
|
||||
GdFunctionArgument.new("value", TYPE_BOOL),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_bool_case2", script.resource_path, 9, TYPE_BOOL, [
|
||||
GdFunctionArgument.new("value", TYPE_BOOL, true),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_bool_case3", script.resource_path, 13, TYPE_BOOL, [
|
||||
GdFunctionArgument.new("value", TYPE_BOOL, true),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_basic_type_string() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/basic_build_in_types/ClassWithBasicTypeStringDefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_string_case1", script.resource_path, 5, TYPE_STRING, [
|
||||
GdFunctionArgument.new("value", TYPE_STRING),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_string_case2", script.resource_path, 9, TYPE_STRING, [
|
||||
GdFunctionArgument.new("value", TYPE_STRING, "foo"),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_string_case3", script.resource_path, 13, TYPE_STRING, [
|
||||
GdFunctionArgument.new("value", TYPE_STRING, "foo"),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_basic_type_string_name() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/basic_build_in_types/ClassWithBasicTypeStringNameDefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_string_name_case1", script.resource_path, 5, TYPE_STRING_NAME, [
|
||||
GdFunctionArgument.new("value", TYPE_STRING_NAME),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_string_name_case2", script.resource_path, 9, TYPE_STRING_NAME, [
|
||||
GdFunctionArgument.new("value", TYPE_STRING_NAME, &"foo"),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_string_name_case3", script.resource_path, 13, TYPE_STRING_NAME, [
|
||||
GdFunctionArgument.new("value", TYPE_STRING_NAME, &"foo"),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_basic_type_node_path() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/basic_build_in_types/ClassWithBasicTypeNodePathDefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_node_path_case1", script.resource_path, 5, TYPE_NODE_PATH, [
|
||||
GdFunctionArgument.new("value", TYPE_NODE_PATH),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_node_path_case2", script.resource_path, 9, TYPE_NODE_PATH, [
|
||||
GdFunctionArgument.new("value", TYPE_NODE_PATH, NodePath("foo1")),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_node_path_case3", script.resource_path, 13, TYPE_NODE_PATH, [
|
||||
GdFunctionArgument.new("value", TYPE_NODE_PATH, NodePath("foo2")),
|
||||
])
|
||||
)
|
||||
assert_that(fds[3])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_node_path_case4", script.resource_path, 17, TYPE_NODE_PATH, [
|
||||
GdFunctionArgument.new("value", TYPE_NODE_PATH, NodePath("foo3")),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_basic_type_vector2() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/basic_build_in_types/ClassWithBasicTypeVector2DefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector2_case1", script.resource_path, 5, TYPE_VECTOR2, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR2),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector2_case2", script.resource_path, 9, TYPE_VECTOR2, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR2, Vector2.ONE),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector2_case3", script.resource_path, 13, TYPE_VECTOR2, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR2, Vector2.ONE),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_basic_type_vector2i() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/basic_build_in_types/ClassWithBasicTypeVector2iDefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector2i_case1", script.resource_path, 5, TYPE_VECTOR2I, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR2I),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector2i_case2", script.resource_path, 9, TYPE_VECTOR2I, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR2I, Vector2i.ONE),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector2i_case3", script.resource_path, 13, TYPE_VECTOR2I, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR2I, Vector2i.ONE),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_basic_type_vector3() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/basic_build_in_types/ClassWithBasicTypeVector3DefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector3_case1", script.resource_path, 5, TYPE_VECTOR3, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR3),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector3_case2", script.resource_path, 9, TYPE_VECTOR3, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR3, Vector3.ONE),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector3_case3", script.resource_path, 13, TYPE_VECTOR3, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR3, Vector3.ONE),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_basic_type_vector3i() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/basic_build_in_types/ClassWithBasicTypeVector3iDefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector3i_case1", script.resource_path, 5, TYPE_VECTOR3I, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR3I),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector3i_case2", script.resource_path, 9, TYPE_VECTOR3I, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR3I, Vector3i.ONE),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector3i_case3", script.resource_path, 13, TYPE_VECTOR3I, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR3I, Vector3i.ONE),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_basic_type_vector4() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/basic_build_in_types/ClassWithBasicTypeVector4DefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector4_case1", script.resource_path, 5, TYPE_VECTOR4, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR4),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector4_case2", script.resource_path, 9, TYPE_VECTOR4, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR4, Vector4.ONE),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector4_case3", script.resource_path, 13, TYPE_VECTOR4, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR4, Vector4.ONE),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_basic_type_vector4i() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/basic_build_in_types/ClassWithBasicTypeVector4iDefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector4i_case1", script.resource_path, 5, TYPE_VECTOR4I, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR4I),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector4i_case2", script.resource_path, 9, TYPE_VECTOR4I, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR4I, Vector4i.ONE),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_vector4i_case3", script.resource_path, 13, TYPE_VECTOR4I, [
|
||||
GdFunctionArgument.new("value", TYPE_VECTOR4I, Vector4i.ONE),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_basic_type_rect2() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/basic_build_in_types/ClassWithBasicTypeRect2DefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_rect2_case1", script.resource_path, 5, TYPE_RECT2, [
|
||||
GdFunctionArgument.new("value", TYPE_RECT2),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_rect2_case2", script.resource_path, 9, TYPE_RECT2, [
|
||||
GdFunctionArgument.new("value", TYPE_RECT2, Rect2()),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_rect2_case3", script.resource_path, 13, TYPE_RECT2, [
|
||||
GdFunctionArgument.new("value", TYPE_RECT2, Rect2()),
|
||||
])
|
||||
)
|
||||
assert_that(fds[3])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_rect2_case4", script.resource_path, 17, TYPE_RECT2, [
|
||||
GdFunctionArgument.new("value", TYPE_RECT2, Rect2(Vector2.ONE, Vector2.ZERO)),
|
||||
])
|
||||
)
|
||||
assert_that(fds[4])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_rect2_case5", script.resource_path, 21, TYPE_RECT2, [
|
||||
GdFunctionArgument.new("value", TYPE_RECT2, Rect2(Vector2(0, 1), Vector2(2, 3))),
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
func test_default_args_basic_type_transform2d() -> void:
|
||||
var script: GDScript = load("res://addons/gdUnit4/test/core/resources/parsing/functions/basic_build_in_types/ClassWithBasicTypeTransform2DDefaultArguments.gd")
|
||||
|
||||
var fds := _parser.get_function_descriptors(script, [])
|
||||
assert_that(fds[0])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_transform2d_case1", script.resource_path, 5, TYPE_TRANSFORM2D, [
|
||||
GdFunctionArgument.new("value", TYPE_TRANSFORM2D),
|
||||
])
|
||||
)
|
||||
assert_that(fds[1])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_transform2d_case2", script.resource_path, 9, TYPE_TRANSFORM2D, [
|
||||
GdFunctionArgument.new("value", TYPE_TRANSFORM2D, Transform2D()),
|
||||
])
|
||||
)
|
||||
assert_that(fds[2])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_transform2d_case3", script.resource_path, 13, TYPE_TRANSFORM2D, [
|
||||
GdFunctionArgument.new("value", TYPE_TRANSFORM2D, Transform2D()),
|
||||
])
|
||||
)
|
||||
assert_that(fds[3])\
|
||||
.is_equal(GdFunctionDescriptor
|
||||
.create("on_transform2d_case4", script.resource_path, 17, TYPE_TRANSFORM2D, [
|
||||
GdFunctionArgument.new("value", TYPE_TRANSFORM2D, Transform2D(1.2, Vector2.ONE)),
|
||||
])
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
uid://dgoa65fyuspny
|
||||
@@ -0,0 +1,72 @@
|
||||
# GdUnit generated TestSuite
|
||||
class_name GdUnitExpressionsTest
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/parse/GdUnitExpressionRunner.gd'
|
||||
|
||||
const TestFuzzers := preload("res://addons/gdUnit4/test/fuzzers/TestFuzzers.gd")
|
||||
|
||||
|
||||
func test_create_fuzzer_argument_default() -> void:
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(GDScript.new(), "Fuzzers.rangei(-10, 22)")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_object(fuzzer).is_instanceof(Fuzzer)
|
||||
assert_int(fuzzer.next_value()).is_between(-10, 22)
|
||||
|
||||
|
||||
func test_create_fuzzer_argument_with_constants() -> void:
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "Fuzzers.rangei(-10, MAX_VALUE)")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_object(fuzzer).is_instanceof(Fuzzer)
|
||||
assert_int(fuzzer.next_value()).is_between(-10, 22)
|
||||
|
||||
|
||||
func test_create_fuzzer_argument_with_custom_function() -> void:
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "get_fuzzer()")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_object(fuzzer).is_instanceof(Fuzzer)
|
||||
assert_int(fuzzer.next_value()).is_between(TestFuzzers.MIN_VALUE, TestFuzzers.MAX_VALUE)
|
||||
|
||||
|
||||
func test_create_fuzzer_do_fail() -> void:
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "non_fuzzer()")
|
||||
assert_that(fuzzer).is_null()
|
||||
|
||||
|
||||
func test_create_nested_fuzzer_do_fail() -> void:
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "NestedFuzzer.new()")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_bool(fuzzer is Fuzzer).is_true()
|
||||
assert_bool(fuzzer is TestFuzzers.NestedFuzzer).is_true()
|
||||
|
||||
|
||||
func test_create_external_fuzzer() -> void:
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(GDScript.new(), "TestExternalFuzzer.new()")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_bool(fuzzer is Fuzzer).is_true()
|
||||
assert_bool(fuzzer is TestExternalFuzzer).is_true()
|
||||
|
||||
|
||||
func test_create_multipe_fuzzers() -> void:
|
||||
var fuzzer_a := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "Fuzzers.rangei(-10, MAX_VALUE)")
|
||||
var fuzzer_b := GdUnitExpressionRunner.new().to_fuzzer(GDScript.new(), "Fuzzers.rangei(10, 20)")
|
||||
assert_that(fuzzer_a).is_not_null()
|
||||
assert_object(fuzzer_a).is_instanceof(IntFuzzer)
|
||||
var a :IntFuzzer = fuzzer_a
|
||||
assert_int(a._from).is_equal(-10)
|
||||
assert_int(a._to).is_equal(TestFuzzers.MAX_VALUE)
|
||||
assert_that(fuzzer_b).is_not_null()
|
||||
assert_object(fuzzer_b).is_instanceof(IntFuzzer)
|
||||
var b :IntFuzzer = fuzzer_b
|
||||
assert_int(b._from).is_equal(10)
|
||||
assert_int(b._to).is_equal(20)
|
||||
|
||||
|
||||
func test_create_fuzzer_with_args() -> void:
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "NestedFuzzerWithArgs.new(100, MAX_VALUE, Vector2.ONE)")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_bool(fuzzer is Fuzzer).is_true()
|
||||
assert_bool(fuzzer is TestFuzzers.NestedFuzzerWithArgs).is_true()
|
||||
@@ -0,0 +1 @@
|
||||
uid://k4263fcoatdk
|
||||
@@ -0,0 +1,217 @@
|
||||
# GdUnit generated TestSuite
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/parse/GdUnitTestParameterSetResolver.gd'
|
||||
const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")
|
||||
|
||||
var _test_param1 := 10
|
||||
var _test_param2 := 20
|
||||
|
||||
|
||||
func before() -> void:
|
||||
_test_param1 = 11
|
||||
|
||||
|
||||
func test_before() -> void:
|
||||
_test_param2 = 22
|
||||
|
||||
|
||||
func test_example_a(_a: int, _b: int, _test_parameters := [[1, 2], [3,4]]) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func test_example_b(_a: Vector2, _b: Vector2, _test_parameters := [
|
||||
[Vector2.ZERO, Vector2.ONE], [Vector2(1.1, 3.2), Vector2.DOWN]] ) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func test_example_c(_a: Object, _b: Object, _test_parameters := [
|
||||
[Resource.new(), Resource.new()],
|
||||
[Resource.new(), null]
|
||||
] ) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func test_resolve_parameters_static(_a: int, _b: int, _test_parameters := [
|
||||
[1, 10],
|
||||
[2, 20]
|
||||
]) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func test_resolve_parameters_at_runtime(_a: int, _b: int, _test_parameters := [
|
||||
[1, _test_param1],
|
||||
[2, _test_param2],
|
||||
[3, 30]
|
||||
]) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func test_parameterized_with_comments(_a: int, _b: int, _c: String, _expected: int, _test_parameters := [
|
||||
# before data set
|
||||
[1, 2, '3', 6], # after data set
|
||||
# between data sets
|
||||
[3, 4, '5', 11],
|
||||
[6, 7, 'string #ABCD', 21], # dataset with [comment] singn
|
||||
[6, 7, "string #ABCD", 21] # dataset with "comment" singn
|
||||
#eof
|
||||
]) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func build_param(value: float) -> Vector3:
|
||||
return Vector3(value, value, value)
|
||||
|
||||
|
||||
func test_example_d(_a: Vector3, _b: Vector3, _test_parameters:=[
|
||||
[build_param(1), build_param(3)],
|
||||
[Vector3.BACK, Vector3.UP]
|
||||
] ) -> void:
|
||||
pass
|
||||
|
||||
|
||||
class TestObj extends RefCounted:
|
||||
var _value: String
|
||||
|
||||
func _init(value: String) -> void:
|
||||
_value = value
|
||||
|
||||
func _to_string() -> String:
|
||||
return _value
|
||||
|
||||
|
||||
func test_example_e(_a: Object, _b: Object, _expected: String, _test_parameters:=[
|
||||
[TestObj.new("abc"), TestObj.new("def"), "abcdef"]]) -> void:
|
||||
pass
|
||||
|
||||
|
||||
# verify the used 'test_parameters' is completly resolved
|
||||
func test_load_parameter_sets() -> void:
|
||||
assert_array(load_parameter_sets("test_example_a")) \
|
||||
.is_equal([[1, 2], [3, 4]])
|
||||
|
||||
assert_array(load_parameter_sets("test_example_b")) \
|
||||
.is_equal([[Vector2.ZERO, Vector2.ONE], [Vector2(1.1, 3.2), Vector2.DOWN]])
|
||||
|
||||
assert_array(load_parameter_sets("test_example_c")) \
|
||||
.is_equal([[Resource.new(), Resource.new()], [Resource.new(), null]])
|
||||
|
||||
assert_array(load_parameter_sets("test_example_d")) \
|
||||
.is_equal([[Vector3(1, 1, 1), Vector3(3, 3, 3)], [Vector3.BACK, Vector3.UP]])
|
||||
|
||||
assert_array(load_parameter_sets("test_example_e")) \
|
||||
.is_equal([[TestObj.new("abc"), TestObj.new("def"), "abcdef"]])
|
||||
|
||||
|
||||
func test_load_parameter_sets_at_runtime() -> void:
|
||||
var params := load_parameter_sets("test_resolve_parameters_at_runtime")
|
||||
assert_that(params).is_not_null()
|
||||
# check the parameters resolved at runtime
|
||||
assert_array(params) \
|
||||
.is_equal([
|
||||
# the value `_test_param1` is changed from 10 to 11 on `before` stage
|
||||
[1, 11],
|
||||
# the value `_test_param2` is changed from 20 to 2 on `test_before` stage
|
||||
[2, 22],
|
||||
# the value is static initial `30`
|
||||
[3, 30]])
|
||||
|
||||
|
||||
func test_load_parameter_with_comments() -> void:
|
||||
var params := load_parameter_sets("test_parameterized_with_comments")
|
||||
assert_that(params).is_not_null()
|
||||
# check the parameters resolved at runtime
|
||||
assert_array(params) \
|
||||
.is_equal([
|
||||
[1, 2, '3', 6],
|
||||
[3, 4, '5', 11],
|
||||
[6, 7, 'string #ABCD', 21],
|
||||
[6, 7, "string #ABCD", 21]])
|
||||
|
||||
|
||||
func test_validate_test_parameter_set() -> void:
|
||||
var test_suite :GdUnitTestSuite = auto_free(GdUnitTestResourceLoader.load_test_suite("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteInvalidParameterizedTests.resource"))
|
||||
|
||||
assert_is_not_skipped(test_suite, "test_no_parameters")
|
||||
assert_is_not_skipped(test_suite, "test_parameterized_success", 0)
|
||||
assert_is_not_skipped(test_suite, "test_parameterized_success", 1)
|
||||
assert_is_not_skipped(test_suite, "test_parameterized_success", 2)
|
||||
assert_is_not_skipped(test_suite, "test_parameterized_failed", 0)
|
||||
assert_is_not_skipped(test_suite, "test_parameterized_failed", 1)
|
||||
assert_is_not_skipped(test_suite, "test_parameterized_failed", 2)
|
||||
assert_is_skipped(test_suite, "test_parameterized_to_less_args", 0).is_equal(
|
||||
"""
|
||||
The test data set at index (0) does not match the expected test arguments:
|
||||
test function: func test...(a: int,b: int,expected: int)
|
||||
test input values: [1, 2, 3, 6]
|
||||
""".dedent()
|
||||
)
|
||||
assert_is_skipped(test_suite, "test_parameterized_to_less_args", 1).is_equal(
|
||||
"""
|
||||
The test data set at index (1) does not match the expected test arguments:
|
||||
test function: func test...(a: int,b: int,expected: int)
|
||||
test input values: [3, 4, 5, 11]
|
||||
""".dedent()
|
||||
)
|
||||
assert_is_skipped(test_suite, "test_parameterized_to_many_args", 0).is_equal(
|
||||
"""
|
||||
The test data set at index (0) does not match the expected test arguments:
|
||||
test function: func test...(a: int,b: int,c: int,d: int,expected: int)
|
||||
test input values: [1, 2, 3, 6]
|
||||
""".dedent()
|
||||
)
|
||||
assert_is_skipped(test_suite, "test_parameterized_to_less_args", 0).is_equal(
|
||||
"""
|
||||
The test data set at index (0) does not match the expected test arguments:
|
||||
test function: func test...(a: int,b: int,expected: int)
|
||||
test input values: [1, 2, 3, 6]
|
||||
""".dedent()
|
||||
)
|
||||
# test_parameterized_invalid_struct
|
||||
assert_is_not_skipped(test_suite, "test_parameterized_invalid_struct", 0)
|
||||
assert_is_skipped(test_suite, "test_parameterized_invalid_struct", 1).is_equal(
|
||||
"""
|
||||
The test data set at index (1) does not match the expected test arguments:
|
||||
test function: func test...(a: int,b: int,expected: int)
|
||||
test input values: ["foo"]
|
||||
""".dedent()
|
||||
)
|
||||
assert_is_not_skipped(test_suite, "test_parameterized_invalid_struct", 2)
|
||||
# test_parameterized_invalid_args
|
||||
assert_is_not_skipped(test_suite, "test_parameterized_invalid_args", 0)
|
||||
assert_is_skipped(test_suite, "test_parameterized_invalid_args", 1).is_equal(
|
||||
"""
|
||||
The test data value does not match the expected input type!
|
||||
input value: '4', <String>
|
||||
expected argument: b: int
|
||||
""".dedent()
|
||||
)
|
||||
assert_is_not_skipped(test_suite, "test_parameterized_invalid_args", 2)
|
||||
|
||||
|
||||
func assert_is_not_skipped(test_suite: GdUnitTestSuite, test_case: String, index := -1) -> void:
|
||||
var test := GdUnitTools.find_test_case(test_suite, test_case, index)
|
||||
if test.is_parameterized():
|
||||
# to load parameter set and force validate
|
||||
test._resolve_test_parameters(index)
|
||||
assert_bool(test.is_skipped()).is_false()
|
||||
|
||||
|
||||
func assert_is_skipped(test_suite: GdUnitTestSuite, test_case: String, index := -1) -> GdUnitStringAssert:
|
||||
var test := GdUnitTools.find_test_case(test_suite, test_case, index)
|
||||
if test.is_parameterized():
|
||||
# to load parameter set and force validate
|
||||
test._resolve_test_parameters(index)
|
||||
assert_bool(test.is_skipped()).is_true()
|
||||
return assert_str(GdUnitTools.richtext_normalize(test.skip_info()))
|
||||
|
||||
|
||||
func load_parameter_sets(child_name: String) -> Array:
|
||||
var script: GDScript = self.get_script()
|
||||
var function_descriptors := GdScriptParser.new().get_function_descriptors(script, [child_name])
|
||||
var fd: GdFunctionDescriptor = function_descriptors.front()
|
||||
var result := GdUnitTestParameterSetResolver.new(fd).load_parameter_sets(self)
|
||||
if result.is_success():
|
||||
return result.value()
|
||||
return []
|
||||
@@ -0,0 +1 @@
|
||||
uid://bvgp0nmky3ba0
|
||||
Reference in New Issue
Block a user