diff --git a/addons/gdUnit4/src/core/parse/GdFunctionArgument.gd b/addons/gdUnit4/src/core/parse/GdFunctionArgument.gd index 4b148233..5d3a24db 100644 --- a/addons/gdUnit4/src/core/parse/GdFunctionArgument.gd +++ b/addons/gdUnit4/src/core/parse/GdFunctionArgument.gd @@ -72,34 +72,43 @@ func _parse_parameter_set(input :String) -> PackedStringArray: return [] input = _cleanup_leading_spaces.sub(input, "", true) - input = input.trim_prefix("[").trim_suffix("]").replace("\n", "").trim_prefix(" ") + input = input.replace("\n", "").trim_prefix("[").trim_suffix("]").trim_prefix(" ") var single_quote := false var double_quote := false var array_end := 0 var current_index := 0 var output :PackedStringArray = [] - var start_index := 0 var buf := input.to_ascii_buffer() + var collected_characters: = PackedByteArray() + var matched :bool = false + for c in buf: current_index += 1 + matched = current_index == buf.size() + collected_characters.push_back(c) + match c: - # ignore spaces between array elements - 32: if array_end == 0: - start_index += 1 - continue - # step over array element seperator ',' + # ' ': ignore spaces between array elements + 32: if array_end == 0 and (not double_quote and not single_quote): + collected_characters.remove_at(collected_characters.size()-1) + # ',': step over array element seperator ',' 44: if array_end == 0: - start_index += 1 - continue + matched = true + collected_characters.remove_at(collected_characters.size()-1) + # '`': 39: single_quote = !single_quote + # '"': 34: if not single_quote: double_quote = !double_quote + # '[' 91: if not double_quote and not single_quote: array_end +=1 # counts array open + # ']' 93: if not double_quote and not single_quote: array_end -=1 # counts array closed # if array closed than collect the element - if array_end == 0 and current_index > start_index: - var parameters := input.substr(start_index, current_index-start_index) - parameters = _fix_comma_space.sub(parameters, ", ", true) - output.append(parameters) - start_index = current_index + if matched: + var parameters := _fix_comma_space.sub(collected_characters.get_string_from_ascii(), ", ", true) + if not parameters.is_empty(): + output.append(parameters) + collected_characters.clear() + matched = false return output diff --git a/addons/gdUnit4/src/core/parse/GdUnitTestParameterSetResolver.gd b/addons/gdUnit4/src/core/parse/GdUnitTestParameterSetResolver.gd index 1ad02326..d67ee254 100644 --- a/addons/gdUnit4/src/core/parse/GdUnitTestParameterSetResolver.gd +++ b/addons/gdUnit4/src/core/parse/GdUnitTestParameterSetResolver.gd @@ -142,7 +142,7 @@ func load_parameter_sets(test_case: _TestCase, do_validate := false) -> Array: var script := GDScript.new() script.source_code = source_code # enable this lines only for debuging - #script.resource_path = GdUnitTools.create_temp_dir("parameter_extract") + "/%s__.gd" % fd.name() + #script.resource_path = GdUnitFileAccess.create_temp_dir("parameter_extract") + "/%s__.gd" % test_case.get_name() #DirAccess.remove_absolute(script.resource_path) #ResourceSaver.save(script, script.resource_path) var result := script.reload() diff --git a/addons/gdUnit4/test/core/ParameterizedTestCaseTest.gd b/addons/gdUnit4/test/core/ParameterizedTestCaseTest.gd index 6bf61b4f..1c15492e 100644 --- a/addons/gdUnit4/test/core/ParameterizedTestCaseTest.gd +++ b/addons/gdUnit4/test/core/ParameterizedTestCaseTest.gd @@ -55,6 +55,10 @@ var _expected_tests := { ["test_a"], ["test_b"], ["test_c"] + ], + "test_with_extern_const_parameter_set" : [ + ["aa"], + ["bb"] ] } @@ -294,3 +298,13 @@ func test_with_extern_parameter_set(value :String, test_parameters := _test_set) assert_that(value).is_not_empty() assert_that(test_parameters).is_empty() collect_test_call("test_with_extern_parameter_set", [value]) + + +const _data1 := ["aa"] +const _data2 := ["bb"] + +@warning_ignore("unused_parameter") +func test_with_extern_const_parameter_set(value :String, test_parameters := [_data1, _data2]) -> void: + assert_that(value).is_not_empty() + assert_that(test_parameters).is_empty() + collect_test_call("test_with_extern_const_parameter_set", [value]) diff --git a/addons/gdUnit4/test/core/parse/GdFunctionArgumentTest.gd b/addons/gdUnit4/test/core/parse/GdFunctionArgumentTest.gd index 08f5b6e6..afffa2cf 100644 --- a/addons/gdUnit4/test/core/parse/GdFunctionArgumentTest.gd +++ b/addons/gdUnit4/test/core/parse/GdFunctionArgumentTest.gd @@ -69,8 +69,41 @@ func test__parse_argument_as_array_typ2() -> void: ) +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(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 1"}]""" + ] + ) + + 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() + + +func test_parse_parameter_set_with_const_data_in_array() -> void: + var test_parameters := "[_data1, _data2]" + + var fa := GdFunctionArgument.new(GdFunctionArgument.ARG_PARAMETERIZED_TEST, TYPE_STRING, test_parameters) + assert_array(fa.parameter_sets()).contains_exactly(["_data1", "_data2"])