Adding log.gd
This commit is contained in:
parent
eb32d6614e
commit
4522259397
547 changed files with 46844 additions and 0 deletions
255
addons/gdUnit4/test/core/parse/GdDefaultValueDecoderTest.gd
Normal file
255
addons/gdUnit4/test/core/parse/GdDefaultValueDecoderTest.gd
Normal file
|
|
@ -0,0 +1,255 @@
|
|||
# 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():
|
||||
# we verify we have covered all variant types
|
||||
for type_id in TYPE_MAX:
|
||||
if type_id == TYPE_OBJECT:
|
||||
continue
|
||||
assert_that(_tested_types.get(type_id))\
|
||||
.override_failure_message("Missing Variant type '%s'" % GdObjects.type_as_string(type_id))\
|
||||
.is_not_null()
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Primitives(variant_type :int, value, 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
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Vectors(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_VECTOR2, Vector2(), "Vector2()"],
|
||||
[TYPE_VECTOR2, Vector2(1,2), "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(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(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
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Rect2(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_RECT2, Rect2(), "Rect2()"],
|
||||
[TYPE_RECT2, Rect2(1,2, 10,20), "Rect2(Vector2(1, 2), 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
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Transforms(variant_type :int, value, 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(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(3, 4))"],
|
||||
[TYPE_TRANSFORM2D, Transform2D(Vector2(1,2), Vector2(3,4), Vector2.ONE),
|
||||
"Transform2D(Vector2(1, 2), Vector2(3, 4), Vector2(1, 1))"],
|
||||
[TYPE_TRANSFORM3D, Transform3D(),
|
||||
"Transform3D()"],
|
||||
[TYPE_TRANSFORM3D, Transform3D(Basis.FLIP_X, Vector3.ONE),
|
||||
"Transform3D(Vector3(-1, 0, 0), Vector3(0, 1, 0), Vector3(0, 0, 1), Vector3(1, 1, 1))"],
|
||||
[TYPE_TRANSFORM3D, Transform3D(Vector3(1,2,3), Vector3(4,5,6), Vector3(7,8,9), Vector3.ONE),
|
||||
"Transform3D(Vector3(1, 2, 3), Vector3(4, 5, 6), Vector3(7, 8, 9), Vector3(1, 1, 1))"],
|
||||
[TYPE_PROJECTION, Projection(),
|
||||
"Projection(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(1, 1, 1, 1), Vector4(2, 2, 2, 2), Vector4(3, 3, 3, 3), Vector4(0, 0, 0, 0))"]
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Plane(variant_type :int, value, 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
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Quaternion(variant_type :int, value, 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
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_AABB(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_AABB, AABB(), "AABB()"],
|
||||
[TYPE_AABB, AABB(Vector3.ONE, Vector3(10,20,30)), "AABB(Vector3(1, 1, 1), Vector3(10, 20, 30))"],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Basis(variant_type :int, value, 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(1, 1, 1), Vector3(2, 2, 2), Vector3(3, 3, 3))"],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Color(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_COLOR, Color(), "Color()"],
|
||||
[TYPE_COLOR, Color.RED, "Color(1, 0, 0, 1)"],
|
||||
[TYPE_COLOR, Color(1,.2,.5,.5), "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
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_NodePath(variant_type :int, value, 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
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_RID(variant_type :int, value, 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
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func _test_decode_Object(variant_type :int, value, 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
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Callable(variant_type :int, value, 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
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Signal(variant_type :int, value, 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
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Dictionary(variant_type :int, value, 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
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Array(variant_type :int, value, 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
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_typedArrays(variant_type :int, value, 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(1, 0, 0, 1), 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(1, 1), Vector2(2, 2)])'],
|
||||
[TYPE_PACKED_VECTOR3_ARRAY, PackedVector3Array(),
|
||||
'PackedVector3Array()'],
|
||||
[TYPE_PACKED_VECTOR3_ARRAY, PackedVector3Array([Vector3.ONE, Vector3.ONE*2]),
|
||||
'PackedVector3Array([Vector3(1, 1, 1), Vector3(2, 2, 2)])'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
76
addons/gdUnit4/test/core/parse/GdFunctionArgumentTest.gd
Normal file
76
addons/gdUnit4/test/core/parse/GdFunctionArgumentTest.gd
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
# 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(GdFunctionArgument.ARG_PARAMETERIZED_TEST, 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(GdFunctionArgument.ARG_PARAMETERIZED_TEST, 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_reference() -> void:
|
||||
var test_parameters := "_test_args()"
|
||||
|
||||
var fa := GdFunctionArgument.new(GdFunctionArgument.ARG_PARAMETERIZED_TEST, TYPE_STRING, test_parameters)
|
||||
assert_array(fa.parameter_sets()).is_empty()
|
||||
146
addons/gdUnit4/test/core/parse/GdFunctionDescriptorTest.gd
Normal file
146
addons/gdUnit4/test/core/parse/GdFunctionDescriptorTest.gd
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
# 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 in method_list:
|
||||
if method_descriptor["name"] == method_name:
|
||||
return method_descriptor
|
||||
return Dictionary()
|
||||
|
||||
|
||||
func test_extract_from_func_without_return_type():
|
||||
# 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(TYPE_NIL)
|
||||
assert_array(fd.args()).contains_exactly([
|
||||
GdFunctionArgument.new("sibling_", GdObjects.TYPE_NODE),
|
||||
GdFunctionArgument.new("force_readable_name_", TYPE_BOOL, "false")
|
||||
])
|
||||
# void add_sibling(node: Node, child_node: Node, legible_unique_name: bool = false)
|
||||
assert_str(fd.typeless()).is_equal("func add_sibling(sibling_, force_readable_name_=false) -> void:")
|
||||
|
||||
|
||||
func test_extract_from_func_with_return_type():
|
||||
# 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"),
|
||||
])
|
||||
# Node find_child(mask: String, recursive: bool = true, owned: bool = true) const
|
||||
assert_str(fd.typeless()).is_equal("func find_child(pattern_, recursive_=true, owned_=true) -> Node:")
|
||||
|
||||
|
||||
func test_extract_from_func_with_vararg():
|
||||
# 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("vararg0_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg1_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg2_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg3_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg4_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg5_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg6_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg7_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg8_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg9_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE)
|
||||
])
|
||||
assert_str(fd.typeless()).is_equal("func emit_signal(signal_, vararg0_=\"__null__\", vararg1_=\"__null__\", vararg2_=\"__null__\", vararg3_=\"__null__\", vararg4_=\"__null__\", vararg5_=\"__null__\", vararg6_=\"__null__\", vararg7_=\"__null__\", vararg8_=\"__null__\", vararg9_=\"__null__\") -> Error:")
|
||||
|
||||
|
||||
func test_extract_from_descriptor_is_virtual_func():
|
||||
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(TYPE_NIL)
|
||||
assert_array(fd.args()).is_empty()
|
||||
# void _enter_tree() virtual
|
||||
assert_str(fd.typeless()).is_equal("func _enter_tree() -> void:")
|
||||
|
||||
|
||||
func test_extract_from_descriptor_is_virtual_func_full_check():
|
||||
var methods := ClassDB.class_get_method_list("Node")
|
||||
var expected_virtual_functions := [
|
||||
# Object virtuals
|
||||
"_get",
|
||||
"_get_property_list",
|
||||
"_init",
|
||||
"_notification",
|
||||
"_property_can_revert",
|
||||
"_property_get_revert",
|
||||
"_set",
|
||||
"_to_string",
|
||||
# Note virtuals
|
||||
"_enter_tree",
|
||||
"_exit_tree",
|
||||
"_get_configuration_warnings",
|
||||
"_input",
|
||||
"_physics_process",
|
||||
"_process",
|
||||
"_ready",
|
||||
"_shortcut_input",
|
||||
"_unhandled_input",
|
||||
"_unhandled_key_input"
|
||||
]
|
||||
# since Godot 4.2 there are more virtual functions
|
||||
if Engine.get_version_info().hex >= 0x40200:
|
||||
expected_virtual_functions.append("_validate_property")
|
||||
|
||||
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():
|
||||
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),
|
||||
])
|
||||
# Variant get(property: String) const
|
||||
assert_str(fd.typeless()).is_equal("func get(property_) -> Variant:")
|
||||
632
addons/gdUnit4/test/core/parse/GdScriptParserTest.gd
Normal file
632
addons/gdUnit4/test/core/parse/GdScriptParserTest.gd
Normal file
|
|
@ -0,0 +1,632 @@
|
|||
extends GdUnitTestSuite
|
||||
|
||||
var _parser: GdScriptParser
|
||||
|
||||
|
||||
func before():
|
||||
_parser = GdScriptParser.new()
|
||||
|
||||
|
||||
func test_parse_argument():
|
||||
# create example row whit different assignment types
|
||||
var row = "func test_foo(arg1 = 41, arg2 := 42, arg3 : int = 43)"
|
||||
assert_that(_parser.parse_argument(row, "arg1", 23)).is_equal(41)
|
||||
assert_that(_parser.parse_argument(row, "arg2", 23)).is_equal(42)
|
||||
assert_that(_parser.parse_argument(row, "arg3", 23)).is_equal(43)
|
||||
|
||||
|
||||
func test_parse_argument_default_value():
|
||||
# arg4 not exists expect to return the default value
|
||||
var row = "func test_foo(arg1 = 41, arg2 := 42, arg3 : int = 43)"
|
||||
assert_that(_parser.parse_argument(row, "arg4", 23)).is_equal(23)
|
||||
|
||||
|
||||
func test_parse_argument_has_no_arguments():
|
||||
assert_that(_parser.parse_argument("func test_foo()", "arg4", 23)).is_equal(23)
|
||||
|
||||
|
||||
func test_parse_argument_with_bad_formatting():
|
||||
var row = "func test_foo( arg1 = 41, arg2 : = 42, arg3 : int = 43 )"
|
||||
assert_that(_parser.parse_argument(row, "arg3", 23)).is_equal(43)
|
||||
|
||||
|
||||
func test_parse_argument_with_same_func_name():
|
||||
var row = "func test_arg1(arg1 = 41)"
|
||||
assert_that(_parser.parse_argument(row, "arg1", 23)).is_equal(41)
|
||||
|
||||
|
||||
func test_parse_argument_timeout():
|
||||
var DEFAULT_TIMEOUT = 1000
|
||||
assert_that(_parser.parse_argument("func test_foo()", "timeout", DEFAULT_TIMEOUT)).is_equal(DEFAULT_TIMEOUT)
|
||||
assert_that(_parser.parse_argument("func test_foo(timeout = 2000)", "timeout", DEFAULT_TIMEOUT)).is_equal(2000)
|
||||
assert_that(_parser.parse_argument("func test_foo(timeout: = 2000)", "timeout", DEFAULT_TIMEOUT)).is_equal(2000)
|
||||
assert_that(_parser.parse_argument("func test_foo(timeout:int = 2000)", "timeout", DEFAULT_TIMEOUT)).is_equal(2000)
|
||||
assert_that(_parser.parse_argument("func test_foo(arg1 = false, timeout=2000)", "timeout", DEFAULT_TIMEOUT)).is_equal(2000)
|
||||
|
||||
|
||||
func test_parse_arguments():
|
||||
assert_array(_parser.parse_arguments("func foo():")) \
|
||||
.has_size(0)
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo() -> String:\n")) \
|
||||
.has_size(0)
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1, arg2, name):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_NIL),
|
||||
GdFunctionArgument.new("arg2", TYPE_NIL),
|
||||
GdFunctionArgument.new("name", TYPE_NIL)])
|
||||
|
||||
assert_array(_parser.parse_arguments('func foo(arg1 :int, arg2 :bool, name :String = "abc"):')) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_INT),
|
||||
GdFunctionArgument.new("arg2", TYPE_BOOL),
|
||||
GdFunctionArgument.new("name", TYPE_STRING, '"abc"')])
|
||||
|
||||
assert_array(_parser.parse_arguments('func bar(arg1 :int, arg2 :int = 23, name :String = "test") -> String:')) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_INT),
|
||||
GdFunctionArgument.new("arg2", TYPE_INT, "23"),
|
||||
GdFunctionArgument.new("name", TYPE_STRING, '"test"')])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1, arg2=value(1,2,3), name:=foo()):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_NIL),
|
||||
GdFunctionArgument.new("arg2", GdObjects.TYPE_FUNC, "value(1,2,3)"),
|
||||
GdFunctionArgument.new("name", GdObjects.TYPE_FUNC, "foo()")])
|
||||
# enum as prefix in value name
|
||||
assert_array(_parser.parse_arguments("func get_value( type := ENUM_A) -> int:"))\
|
||||
.contains_exactly([GdFunctionArgument.new("type", TYPE_STRING, "ENUM_A")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func create_timer(timeout :float) -> Timer:")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("timeout", TYPE_FLOAT)])
|
||||
|
||||
# array argument
|
||||
assert_array(_parser.parse_arguments("func foo(a :int, b :int, parameters = [[1, 2], [3, 4], [5, 6]]):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("a", TYPE_INT),
|
||||
GdFunctionArgument.new("b", TYPE_INT),
|
||||
GdFunctionArgument.new("parameters", TYPE_ARRAY, "[[1, 2], [3, 4], [5, 6]]")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func test_values(a:Vector2, b:Vector2, expected:Vector2, test_parameters:=[[Vector2.ONE,Vector2.ONE,Vector2(1,1)]]):"))\
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("a", TYPE_VECTOR2),
|
||||
GdFunctionArgument.new("b", TYPE_VECTOR2),
|
||||
GdFunctionArgument.new("expected", TYPE_VECTOR2),
|
||||
GdFunctionArgument.new("test_parameters", TYPE_ARRAY, "[[Vector2.ONE,Vector2.ONE,Vector2(1,1)]]"),
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_with_super_constructor():
|
||||
assert_array(_parser.parse_arguments('func foo().foo("abc"):')).is_empty()
|
||||
assert_array(_parser.parse_arguments('func foo(arg1 = "arg").foo("abc", arg1):'))\
|
||||
.contains_exactly([GdFunctionArgument.new("arg1", TYPE_STRING, '"arg"')])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_String():
|
||||
assert_array(_parser.parse_arguments('func foo(arg1 :String, arg2="default"):')) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_STRING, '"default"')])
|
||||
|
||||
assert_array(_parser.parse_arguments('func foo(arg1 :String, arg2 :="default"):')) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_STRING, '"default"')])
|
||||
|
||||
assert_array(_parser.parse_arguments('func foo(arg1 :String, arg2 :String ="default"):')) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_STRING, '"default"')])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_Boolean():
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2=false):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :=false):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :bool=false):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_Real():
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2=3.14):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_FLOAT, "3.14")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :=3.14):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_FLOAT, "3.14")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :float=3.14):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_FLOAT, "3.14")])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_Array():
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Array=[]):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[]")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Array=Array()):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_ARRAY, "Array()")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Array=[1, 2, 3]):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[1, 2, 3]")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :=[1, 2, 3]):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[1, 2, 3]")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2=[]):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[]")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Array=[1, 2, 3], arg3 := false):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[1, 2, 3]"),
|
||||
GdFunctionArgument.new("arg3", TYPE_BOOL, "false")])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_Color():
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2=Color.RED):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_COLOR, "Color.RED")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :=Color.RED):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_COLOR, "Color.RED")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Color=Color.RED):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_COLOR, "Color.RED")])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_Vector():
|
||||
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 =Vector3.FORWARD):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_VECTOR3, "Vector3.FORWARD")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 :=Vector3.FORWARD):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_VECTOR3, "Vector3.FORWARD")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 :Vector3=Vector3.FORWARD):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_VECTOR3, "Vector3.FORWARD")])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_AABB():
|
||||
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 := AABB()):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_AABB, "AABB()")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 :AABB=AABB()):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_AABB, "AABB()")])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_types():
|
||||
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 := Vector3.FORWARD, aabb := AABB()):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_VECTOR3, "Vector3.FORWARD"),
|
||||
GdFunctionArgument.new("aabb", TYPE_AABB, "AABB()")])
|
||||
|
||||
|
||||
func test_parse_arguments_fuzzers() -> void:
|
||||
assert_array(_parser.parse_arguments("func test_foo(fuzzer_a = fuzz_a(), fuzzer_b := fuzz_b(), fuzzer_c :Fuzzer = fuzz_c(), fuzzer_iterations = 234, fuzzer_seed = 100):")) \
|
||||
.contains_exactly([
|
||||
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_iterations", TYPE_INT, "234"),
|
||||
GdFunctionArgument.new("fuzzer_seed", TYPE_INT, "100"),])
|
||||
|
||||
|
||||
func test_parse_arguments_no_function():
|
||||
assert_array(_parser.parse_arguments("var x:=10")) \
|
||||
.has_size(0)
|
||||
|
||||
|
||||
class TestObject:
|
||||
var x
|
||||
|
||||
|
||||
func test_parse_function_return_type():
|
||||
assert_that(_parser.parse_func_return_type("func foo():")).is_equal(TYPE_NIL)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> void:")).is_equal(GdObjects.TYPE_VOID)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> TestObject:")).is_equal(TYPE_OBJECT)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> bool:")).is_equal(TYPE_BOOL)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> String:")).is_equal(TYPE_STRING)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> int:")).is_equal(TYPE_INT)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> float:")).is_equal(TYPE_FLOAT)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Vector2:")).is_equal(TYPE_VECTOR2)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Rect2:")).is_equal(TYPE_RECT2)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Vector3:")).is_equal(TYPE_VECTOR3)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Transform2D:")).is_equal(TYPE_TRANSFORM2D)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Plane:")).is_equal(TYPE_PLANE)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Quaternion:")).is_equal(TYPE_QUATERNION)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> AABB:")).is_equal(TYPE_AABB)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Basis:")).is_equal(TYPE_BASIS)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Transform3D:")).is_equal(TYPE_TRANSFORM3D)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Color:")).is_equal(TYPE_COLOR)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> NodePath:")).is_equal(TYPE_NODE_PATH)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> RID:")).is_equal(TYPE_RID)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Dictionary:")).is_equal(TYPE_DICTIONARY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Array:")).is_equal(TYPE_ARRAY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> PackedByteArray:")).is_equal(TYPE_PACKED_BYTE_ARRAY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> PackedInt32Array:")).is_equal(TYPE_PACKED_INT32_ARRAY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> PackedFloat32Array:")).is_equal(TYPE_PACKED_FLOAT32_ARRAY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> PackedStringArray:")).is_equal(TYPE_PACKED_STRING_ARRAY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> PackedVector2Array:")).is_equal(TYPE_PACKED_VECTOR2_ARRAY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> PackedVector3Array:")).is_equal(TYPE_PACKED_VECTOR3_ARRAY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> PackedColorArray:")).is_equal(TYPE_PACKED_COLOR_ARRAY)
|
||||
|
||||
|
||||
func test_parse_func_name():
|
||||
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")
|
||||
# should fail
|
||||
assert_str(_parser.parse_func_name("#func foo():")).is_empty()
|
||||
assert_str(_parser.parse_func_name("var x")).is_empty()
|
||||
|
||||
|
||||
func test_extract_source_code():
|
||||
var path := GdObjects.extract_class_path(AdvancedTestClass)
|
||||
var rows = _parser.extract_source_code(path)
|
||||
|
||||
var file_content := resource_as_array(path[0])
|
||||
assert_array(rows).contains_exactly(file_content)
|
||||
|
||||
|
||||
func test_extract_source_code_inner_class_AtmosphereData():
|
||||
var path := GdObjects.extract_class_path(AdvancedTestClass.AtmosphereData)
|
||||
var rows = _parser.extract_source_code(path)
|
||||
var file_content := resource_as_array("res://addons/gdUnit4/test/core/resources/AtmosphereData.txt")
|
||||
assert_array(rows).contains_exactly(file_content)
|
||||
|
||||
|
||||
func test_extract_source_code_inner_class_SoundData():
|
||||
var path := GdObjects.extract_class_path(AdvancedTestClass.SoundData)
|
||||
var rows = _parser.extract_source_code(path)
|
||||
var file_content := resource_as_array("res://addons/gdUnit4/test/core/resources/SoundData.txt")
|
||||
assert_array(rows).contains_exactly(file_content)
|
||||
|
||||
|
||||
func test_extract_source_code_inner_class_Area4D():
|
||||
var path := GdObjects.extract_class_path(AdvancedTestClass.Area4D)
|
||||
var rows = _parser.extract_source_code(path)
|
||||
var file_content := resource_as_array("res://addons/gdUnit4/test/core/resources/Area4D.txt")
|
||||
assert_array(rows).contains_exactly(file_content)
|
||||
|
||||
|
||||
func test_extract_function_signature() -> void:
|
||||
var path := GdObjects.extract_class_path("res://addons/gdUnit4/test/mocker/resources/ClassWithCustomFormattings.gd")
|
||||
var rows = _parser.extract_source_code(path)
|
||||
|
||||
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
|
||||
) :""".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
|
||||
):""".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" ],
|
||||
]
|
||||
):""".dedent().trim_prefix("\n"))
|
||||
|
||||
|
||||
func test_strip_leading_spaces():
|
||||
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_extract_clazz_name():
|
||||
assert_str(_parser.extract_clazz_name("classSoundData:\n")).is_equal("SoundData")
|
||||
assert_str(_parser.extract_clazz_name("classSoundDataextendsNode:\n")).is_equal("SoundData")
|
||||
|
||||
|
||||
func test_is_virtual_func() -> void:
|
||||
# checked non virtual func
|
||||
assert_bool(_parser.is_virtual_func("UnknownClass", [""], "")).is_false()
|
||||
assert_bool(_parser.is_virtual_func("Node", [""], "")).is_false()
|
||||
assert_bool(_parser.is_virtual_func("Node", [""], "func foo():")).is_false()
|
||||
# checked virtual func
|
||||
assert_bool(_parser.is_virtual_func("Node", [""], "_exit_tree")).is_true()
|
||||
assert_bool(_parser.is_virtual_func("Node", [""], "_ready")).is_true()
|
||||
assert_bool(_parser.is_virtual_func("Node", [""], "_init")).is_true()
|
||||
|
||||
|
||||
func test_is_static_func():
|
||||
assert_bool(_parser.is_static_func("")).is_false()
|
||||
assert_bool(_parser.is_static_func("var a=0")).is_false()
|
||||
assert_bool(_parser.is_static_func("func foo():")).is_false()
|
||||
assert_bool(_parser.is_static_func("func foo() -> void:")).is_false()
|
||||
assert_bool(_parser.is_static_func("static func foo():")).is_true()
|
||||
assert_bool(_parser.is_static_func("static func foo() -> void:")).is_true()
|
||||
|
||||
|
||||
func test_parse_func_description():
|
||||
var fd := _parser.parse_func_description("func foo():", "clazz_name", [""], 10)
|
||||
assert_str(fd.name()).is_equal("foo")
|
||||
assert_bool(fd.is_static()).is_false()
|
||||
assert_int(fd.return_type()).is_equal(GdObjects.TYPE_VARIANT)
|
||||
assert_array(fd.args()).is_empty()
|
||||
assert_str(fd.typeless()).is_equal("func foo() -> Variant:")
|
||||
|
||||
# static function
|
||||
fd = _parser.parse_func_description("static func foo(arg1 :int, arg2:=false) -> String:", "clazz_name", [""], 22)
|
||||
assert_str(fd.name()).is_equal("foo")
|
||||
assert_bool(fd.is_static()).is_true()
|
||||
assert_int(fd.return_type()).is_equal(TYPE_STRING)
|
||||
assert_array(fd.args()).contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_INT),
|
||||
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")
|
||||
])
|
||||
assert_str(fd.typeless()).is_equal("static func foo(arg1, arg2=false) -> String:")
|
||||
|
||||
# static function without return type
|
||||
fd = _parser.parse_func_description("static func foo(arg1 :int, arg2:=false):", "clazz_name", [""], 23)
|
||||
assert_str(fd.name()).is_equal("foo")
|
||||
assert_bool(fd.is_static()).is_true()
|
||||
assert_int(fd.return_type()).is_equal(GdObjects.TYPE_VARIANT)
|
||||
assert_array(fd.args()).contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_INT),
|
||||
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")
|
||||
])
|
||||
assert_str(fd.typeless()).is_equal("static func foo(arg1, arg2=false) -> Variant:")
|
||||
|
||||
|
||||
func test_parse_func_description_return_type_enum():
|
||||
var result := _parser.parse("ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"])
|
||||
assert_result(result).is_success()
|
||||
|
||||
var fd := _parser.parse_func_description("func get_enum() -> TEST_ENUM:", "ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"], 33)
|
||||
assert_that(fd.name()).is_equal("get_enum")
|
||||
assert_that(fd.is_static()).is_false()
|
||||
assert_that(fd.return_type()).is_equal(GdObjects.TYPE_ENUM)
|
||||
assert_that(fd._return_class).is_equal("ClassWithEnumReturnTypes.TEST_ENUM")
|
||||
assert_that(fd.args()).is_empty()
|
||||
|
||||
|
||||
func test_parse_func_description_return_type_internal_class_enum():
|
||||
var result := _parser.parse("ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"])
|
||||
assert_result(result).is_success()
|
||||
|
||||
var fd := _parser.parse_func_description("func get_inner_class_enum() -> InnerClass.TEST_ENUM:", "ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"], 33)
|
||||
assert_that(fd.name()).is_equal("get_inner_class_enum")
|
||||
assert_that(fd.is_static()).is_false()
|
||||
assert_that(fd.return_type()).is_equal(GdObjects.TYPE_ENUM)
|
||||
assert_that(fd._return_class).is_equal("ClassWithEnumReturnTypes.InnerClass.TEST_ENUM")
|
||||
assert_that(fd.args()).is_empty()
|
||||
|
||||
|
||||
func test_parse_func_description_return_type_external_class_enum():
|
||||
var result := _parser.parse("ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"])
|
||||
assert_result(result).is_success()
|
||||
|
||||
var fd := _parser.parse_func_description("func get_external_class_enum() -> CustomEnums.TEST_ENUM:", "ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"], 33)
|
||||
assert_that(fd.name()).is_equal("get_external_class_enum")
|
||||
assert_that(fd.is_static()).is_false()
|
||||
assert_that(fd.return_type()).is_equal(GdObjects.TYPE_ENUM)
|
||||
assert_that(fd._return_class).is_equal("CustomEnums.TEST_ENUM")
|
||||
assert_that(fd.args()).is_empty()
|
||||
|
||||
|
||||
func test_parse_class_inherits():
|
||||
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.new("foo2", 5, false, false, false, GdObjects.TYPE_VARIANT, "", []),
|
||||
GdFunctionDescriptor.new("bar2", 8, false, false, false, TYPE_STRING, "", [])
|
||||
])
|
||||
|
||||
# extends from CustomResourceTestClass
|
||||
clazz_desccriptor = clazz_desccriptor.parent()
|
||||
assert_object(clazz_desccriptor).is_not_null()
|
||||
assert_str(clazz_desccriptor.name()).is_equal("CustomResourceTestClass")
|
||||
assert_bool(clazz_desccriptor.is_inner_class()).is_false()
|
||||
assert_array(clazz_desccriptor.functions()).contains_exactly([
|
||||
GdFunctionDescriptor.new("foo", 4, false, false, false, TYPE_STRING, "", []),
|
||||
GdFunctionDescriptor.new("foo2", 7, false, false, false, GdObjects.TYPE_VARIANT, "", []),
|
||||
GdFunctionDescriptor.new("foo_void", 10, false, false, false, GdObjects.TYPE_VOID, "", []),
|
||||
GdFunctionDescriptor.new("bar", 13, false, false, false, TYPE_STRING, "", [
|
||||
GdFunctionArgument.new("arg1", TYPE_INT),
|
||||
GdFunctionArgument.new("arg2", TYPE_INT, "23"),
|
||||
GdFunctionArgument.new("name", TYPE_STRING, '"test"'),
|
||||
]),
|
||||
GdFunctionDescriptor.new("foo5", 16, false, false, false, GdObjects.TYPE_VARIANT, "", []),
|
||||
])
|
||||
|
||||
# no other class extends
|
||||
clazz_desccriptor = clazz_desccriptor.parent()
|
||||
assert_object(clazz_desccriptor).is_null()
|
||||
|
||||
|
||||
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")))\
|
||||
.is_equal("PascalCaseWithClassName")
|
||||
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithoutClassName.gd")))\
|
||||
.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")))\
|
||||
.is_equal("SnakeCaseWithClassName")
|
||||
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_without_class_name.gd")))\
|
||||
.is_equal("SnakeCaseWithoutClassName")
|
||||
|
||||
|
||||
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, 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, parameters = [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 11],
|
||||
[6, 7, 8, 21] ]):"""
|
||||
.dedent()
|
||||
.trim_prefix("\n")
|
||||
)
|
||||
|
||||
|
||||
func test_parse_func_description_paramized_test():
|
||||
var fd = _parser.parse_func_description("functest_parameterized(a:int,b:int,c:int,expected:int,parameters=[[1,2,3,6],[3,4,5,11],[6,7,8,21]]):", "class", ["path"], 22)
|
||||
|
||||
assert_that(fd).is_equal(GdFunctionDescriptor.new("test_parameterized", 22, false, false, false, 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("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, 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, 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():
|
||||
var source_code := """
|
||||
func test_foo(fuzzer_a = fuzz_a(), fuzzer_b := fuzz_b(),
|
||||
fuzzer_c :Fuzzer = fuzz_c(),
|
||||
fuzzer = Fuzzers.random_rangei(-23, 22),
|
||||
fuzzer_iterations = 234,
|
||||
fuzzer_seed = 100):
|
||||
""".split("\n")
|
||||
var fs = _parser.extract_func_signature(source_code, 0)
|
||||
var fd = _parser.parse_func_description(fs, "class", ["path"], 22)
|
||||
|
||||
assert_that(fd).is_equal(GdFunctionDescriptor.new("test_foo", 22, false, false, false, GdObjects.TYPE_VARIANT, "", [
|
||||
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.random_rangei(-23, 22)"),
|
||||
GdFunctionArgument.new("fuzzer_iterations", TYPE_INT, "234"),
|
||||
GdFunctionArgument.new("fuzzer_seed", TYPE_INT, "100")
|
||||
]))
|
||||
|
||||
|
||||
func test_is_class_enum_type() -> void:
|
||||
var parser := GdScriptParser.new()
|
||||
assert_that(parser.is_class_enum_type("ClassWithEnumReturnTypes.InnerClass.TEST_ENUM")).is_true()
|
||||
assert_that(parser.is_class_enum_type("ClassWithEnumReturnTypes.InnerClass")).is_false()
|
||||
assert_that(parser.is_class_enum_type("ClassWithEnumReturnTypes.TEST_ENUM")).is_true()
|
||||
assert_that(parser.is_class_enum_type("CustomEnums.TEST_ENUM")).is_true()
|
||||
assert_that(parser.is_class_enum_type("CustomEnums")).is_false()
|
||||
assert_that(parser.is_class_enum_type("ClassWithEnumReturnTypes.NOT_AN_ENUM")).is_false()
|
||||
65
addons/gdUnit4/test/core/parse/GdUnitExpressionRunnerTest.gd
Normal file
65
addons/gdUnit4/test/core/parse/GdUnitExpressionRunnerTest.gd
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
# 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():
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(GDScript.new(), "Fuzzers.rangei(-10, 22)")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_that(fuzzer).is_instanceof(Fuzzer)
|
||||
assert_int(fuzzer.next_value()).is_between(-10, 22)
|
||||
|
||||
|
||||
func test_create_fuzzer_argument_with_constants():
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "Fuzzers.rangei(-10, MAX_VALUE)")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_that(fuzzer).is_instanceof(Fuzzer)
|
||||
assert_int(fuzzer.next_value()).is_between(-10, 22)
|
||||
|
||||
|
||||
func test_create_fuzzer_argument_with_custom_function():
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "get_fuzzer()")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_that(fuzzer).is_instanceof(Fuzzer)
|
||||
assert_int(fuzzer.next_value()).is_between(TestFuzzers.MIN_VALUE, TestFuzzers.MAX_VALUE)
|
||||
|
||||
|
||||
func test_create_fuzzer_do_fail():
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "non_fuzzer()")
|
||||
assert_that(fuzzer).is_null()
|
||||
|
||||
|
||||
func test_create_nested_fuzzer_do_fail():
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "NestedFuzzer.new()")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_that(fuzzer is Fuzzer).is_true()
|
||||
assert_bool(fuzzer is TestFuzzers.NestedFuzzer).is_true()
|
||||
|
||||
|
||||
func test_create_external_fuzzer():
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(GDScript.new(), "TestExternalFuzzer.new()")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_that(fuzzer is Fuzzer).is_true()
|
||||
assert_bool(fuzzer is TestExternalFuzzer).is_true()
|
||||
|
||||
|
||||
func test_create_multipe_fuzzers():
|
||||
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_that(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_that(fuzzer_b).is_instanceof(IntFuzzer)
|
||||
var b :IntFuzzer = fuzzer_b
|
||||
assert_int(b._from).is_equal(10)
|
||||
assert_int(b._to).is_equal(20)
|
||||
|
|
@ -0,0 +1,222 @@
|
|||
# GdUnit generated TestSuite
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/parse/GdUnitTestParameterSetResolver.gd'
|
||||
|
||||
|
||||
var _test_param1 := 10
|
||||
var _test_param2 := 20
|
||||
|
||||
|
||||
func before():
|
||||
_test_param1 = 11
|
||||
|
||||
|
||||
func test_before():
|
||||
_test_param2 = 22
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_example_a(a: int, b: int, test_parameters=[[1, 2], [3,4]]) -> void:
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_example_b(a: Vector2, b: Vector2, test_parameters=[
|
||||
[Vector2.ZERO, Vector2.ONE], [Vector2(1.1, 3.2), Vector2.DOWN]] ) -> void:
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_example_c(a: Object, b: Object, test_parameters=[
|
||||
[Resource.new(), Resource.new()],
|
||||
[Resource.new(), null]
|
||||
] ) -> void:
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_resolve_parameters_static(a: int, b: int, test_parameters=[
|
||||
[1, 10],
|
||||
[2, 20]
|
||||
]) -> void:
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_resolve_parameters_at_runtime(a: int, b: int, test_parameters=[
|
||||
[1, _test_param1],
|
||||
[2, _test_param2],
|
||||
[3, 30]
|
||||
]) -> void:
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
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
|
||||
]):
|
||||
pass
|
||||
|
||||
|
||||
func build_param(value: float) -> Vector3:
|
||||
return Vector3(value, value, value)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
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):
|
||||
_value = value
|
||||
|
||||
func _to_string() -> String:
|
||||
return _value
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_example_e(a: Object, b: Object, expected: String, test_parameters:=[
|
||||
[TestObj.new("abc"), TestObj.new("def"), "abcdef"]]):
|
||||
pass
|
||||
|
||||
|
||||
# verify the used 'test_parameters' is completly resolved
|
||||
func test_load_parameter_sets() -> void:
|
||||
var tc := get_test_case("test_example_a")
|
||||
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
|
||||
.is_equal([[1, 2], [3, 4]])
|
||||
|
||||
tc = get_test_case("test_example_b")
|
||||
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
|
||||
.is_equal([[Vector2.ZERO, Vector2.ONE], [Vector2(1.1, 3.2), Vector2.DOWN]])
|
||||
|
||||
tc = get_test_case("test_example_c")
|
||||
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
|
||||
.is_equal([[Resource.new(), Resource.new()], [Resource.new(), null]])
|
||||
|
||||
tc = get_test_case("test_example_d")
|
||||
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
|
||||
.is_equal([[Vector3(1, 1, 1), Vector3(3, 3, 3)], [Vector3.BACK, Vector3.UP]])
|
||||
|
||||
tc = get_test_case("test_example_e")
|
||||
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
|
||||
.is_equal([[TestObj.new("abc"), TestObj.new("def"), "abcdef"]])
|
||||
|
||||
|
||||
func test_load_parameter_sets_at_runtime() -> void:
|
||||
var tc := get_test_case("test_resolve_parameters_at_runtime")
|
||||
assert_that(tc).is_not_null()
|
||||
# check the parameters resolved at runtime
|
||||
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
|
||||
.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 tc := get_test_case("test_parameterized_with_comments")
|
||||
assert_that(tc).is_not_null()
|
||||
# check the parameters resolved at runtime
|
||||
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
|
||||
.is_equal([
|
||||
[1, 2, '3', 6],
|
||||
[3, 4, '5', 11],
|
||||
[6, 7, 'string #ABCD', 21],
|
||||
[6, 7, "string #ABCD", 21]])
|
||||
|
||||
|
||||
func test_build_test_case_names_on_static_parameter_set() -> void:
|
||||
var test_case := get_test_case("test_resolve_parameters_static")
|
||||
var resolver := test_case.parameter_set_resolver()
|
||||
|
||||
assert_array(resolver.build_test_case_names(test_case))\
|
||||
.contains_exactly([
|
||||
"test_resolve_parameters_static:0 [1, 10]",
|
||||
"test_resolve_parameters_static:1 [2, 20]"])
|
||||
assert_that(resolver.is_parameter_sets_static()).is_true()
|
||||
assert_that(resolver.is_parameter_set_static(0)).is_true()
|
||||
assert_that(resolver.is_parameter_set_static(1)).is_true()
|
||||
|
||||
|
||||
func test_build_test_case_names_on_runtime_parameter_set() -> void:
|
||||
var test_case := get_test_case("test_resolve_parameters_at_runtime")
|
||||
var resolver := test_case.parameter_set_resolver()
|
||||
|
||||
assert_array(resolver.build_test_case_names(test_case))\
|
||||
.contains_exactly([
|
||||
"test_resolve_parameters_at_runtime:0 [1, _test_param1]",
|
||||
"test_resolve_parameters_at_runtime:1 [2, _test_param2]",
|
||||
"test_resolve_parameters_at_runtime:2 [3, 30]"])
|
||||
assert_that(resolver.is_parameter_sets_static()).is_false()
|
||||
assert_that(resolver.is_parameter_set_static(0)).is_false()
|
||||
assert_that(resolver.is_parameter_set_static(1)).is_false()
|
||||
assert_that(resolver.is_parameter_set_static(2)).is_false()
|
||||
|
||||
|
||||
func test_validate_test_parameter_set():
|
||||
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")
|
||||
assert_is_not_skipped(test_suite, "test_parameterized_failed")
|
||||
assert_is_skipped(test_suite, "test_parameterized_to_less_args")\
|
||||
.contains("The parameter set at index [0] does not match the expected input parameters!")\
|
||||
.contains("The test case requires [3] input parameters, but the set contains [4]")
|
||||
assert_is_skipped(test_suite, "test_parameterized_to_many_args")\
|
||||
.contains("The parameter set at index [0] does not match the expected input parameters!")\
|
||||
.contains("The test case requires [5] input parameters, but the set contains [4]")
|
||||
assert_is_skipped(test_suite, "test_parameterized_to_less_args_at_index_1")\
|
||||
.contains("The parameter set at index [1] does not match the expected input parameters!")\
|
||||
.contains("The test case requires [3] input parameters, but the set contains [4]")
|
||||
assert_is_skipped(test_suite, "test_parameterized_invalid_struct")\
|
||||
.contains("The parameter set at index [1] does not match the expected input parameters!")\
|
||||
.contains("The test case requires [3] input parameters, but the set contains [1]")
|
||||
assert_is_skipped(test_suite, "test_parameterized_invalid_args")\
|
||||
.contains("The parameter set at index [1] does not match the expected input parameters!")\
|
||||
.contains("The value '4' does not match the required input parameter <b:int>.")
|
||||
|
||||
|
||||
func assert_is_not_skipped(test_suite :GdUnitTestSuite, test_case :String) -> void:
|
||||
# set actual execution context for this test suite
|
||||
test_suite.__execution_context = GdUnitExecutionContext.new(test_suite.get_name())
|
||||
var test :_TestCase = test_suite.find_child(test_case, true, false)
|
||||
if test.is_parameterized():
|
||||
# to load parameter set and force validate
|
||||
var resolver := test.parameter_set_resolver()
|
||||
resolver.build_test_case_names(test)
|
||||
resolver.load_parameter_sets(test, true)
|
||||
assert_that(test.is_skipped()).is_false()
|
||||
|
||||
|
||||
func assert_is_skipped(test_suite :GdUnitTestSuite, test_case :String) -> GdUnitStringAssert:
|
||||
# set actual execution context for this test suite
|
||||
test_suite.__execution_context = GdUnitExecutionContext.new(test_suite.get_name())
|
||||
var test :_TestCase = test_suite.find_child(test_case, true, false)
|
||||
if test.is_parameterized():
|
||||
# to load parameter set and force validate
|
||||
var resolver := test.parameter_set_resolver()
|
||||
resolver.build_test_case_names(test)
|
||||
resolver.load_parameter_sets(test, true)
|
||||
assert_that(test.is_skipped()).is_true()
|
||||
return assert_str(test.skip_info())
|
||||
|
||||
func get_test_case(name: String) -> _TestCase:
|
||||
return find_child(name, true, false)
|
||||
Loading…
Add table
Add a link
Reference in a new issue