From dad5ef49fab9c7e27ee3f1fab57e9da0b6e4c1b5 Mon Sep 17 00:00:00 2001 From: Kai Roth Date: Sun, 16 Apr 2023 16:04:37 +0200 Subject: [PATCH 1/2] test: :white_check_mark: tests for manifest validation --- test/Unit/test_manifest_validation.gd | 74 +++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 test/Unit/test_manifest_validation.gd diff --git a/test/Unit/test_manifest_validation.gd b/test/Unit/test_manifest_validation.gd new file mode 100644 index 00000000..a8c6a206 --- /dev/null +++ b/test/Unit/test_manifest_validation.gd @@ -0,0 +1,74 @@ +extends GutTest + + +var test_is_mod_id_valid_params = [ + ["abc-abc", true], + ["abcdefg-abcdefg", true], + ["abc-abcdefg", true], + ["ABC-AB_CDE", true], + ["123-123", true], + + ["abc-abc-abc", false], + ["abcdef-", false], + ["-abcdef", false], + ["a-bcdef", false], + ["abcdef", false], + ["a", false], + ["abc-%ab", false], +] + + +func test_is_mod_id_valid(params = use_parameters(test_is_mod_id_valid_params)) -> void: + # prepare + var mod_id = params[0] + var expected_result = params[1] + + # test + var result = ModManifest.is_mod_id_valid(mod_id, mod_id, "", true) + + # validate + assert_true( + result == expected_result, + "Expected %s but was %s instead for mod_id \"%s\"" % [expected_result, result, mod_id] + ) + + +func test_validate_distinct_mod_ids_in_arrays(): + var array_one: PoolStringArray = ["mod1-mod1", "mod2-mod2", "mod3-mod3"] + var array_two: PoolStringArray = ["mod4-mod4", "mod5-mod5", "mod6-mod6"] + var array_description: PoolStringArray = ["array_1", "array_2"] + var mod_id = "test-mod" + var additional_info = "additional info" + + # Test with distinct mod ids in arrays + var result = ModManifest.validate_distinct_mod_ids_in_arrays(mod_id, array_one, array_two, ["array_one", "array_two"], additional_info, true) + assert_eq(result, true) + + # Test with overlapping mod ids in arrays + array_two = ["mod4-mod4", "mod5-mod5", "mod6-mod6", "mod2-mod2"] + result = ModManifest.validate_distinct_mod_ids_in_arrays(mod_id, array_one, array_two, ["array_one", "array_two"], additional_info, true) + assert_eq(result, false) + + # Test with no mod ids in one array + array_two = [] + result = ModManifest.validate_distinct_mod_ids_in_arrays(mod_id, array_one, array_two, ["array_one", "array_two"], additional_info, true) + assert_eq(result, true) + + # Test with no mod ids in both arrays + array_one = [] + array_two = [] + result = ModManifest.validate_distinct_mod_ids_in_arrays(mod_id, array_one, array_two, ["array_one", "array_two"], additional_info, true) + assert_eq(result, true) + + +func test_is_mod_id_array_valid(): + var mod_id_array = PoolStringArray(["mod1-mod1", "mod2-mod2", "mod3-mod3"]) + + # Test with a valid mod id array + var result = ModManifest.is_mod_id_array_valid("own-mod", mod_id_array, "dependencies", true) + assert_eq(result, true) + + # Test with an invalid mod id array + mod_id_array = PoolStringArray(["mod1-mod1", "mod2-mod2", "invalid-mod21###"]) + result = ModManifest.is_mod_id_array_valid("own-mod", mod_id_array, "dependencies", true) + assert_eq(result, false) From ae5bb1f745cc49782d4fca1f9ad5c233340e3d2c Mon Sep 17 00:00:00 2001 From: Kai Roth Date: Mon, 17 Apr 2023 22:42:18 +0200 Subject: [PATCH 2/2] test: :white_check_mark: use parameterized tests updated `test_validate_distinct_mod_ids_in_arrays()` and `test_is_mod_id_array_valid()` --- test/Unit/test_manifest_validation.gd | 76 ++++++++++++++++----------- 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/test/Unit/test_manifest_validation.gd b/test/Unit/test_manifest_validation.gd index a8c6a206..b25a22f5 100644 --- a/test/Unit/test_manifest_validation.gd +++ b/test/Unit/test_manifest_validation.gd @@ -17,6 +17,25 @@ var test_is_mod_id_valid_params = [ ["abc-%ab", false], ] +# Test with distinct mod ids in arrays +# Test with overlapping mod ids in arrays +# Test with no mod ids in one array +# Test with no mod ids in both arrays +var test_validate_distinct_mod_ids_in_arrays_params = [ + [["mod1-mod1", "mod2-mod2", "mod3-mod3"], ["mod4-mod4", "mod5-mod5", "mod6-mod6"], true], + [["mod1-mod1", "mod2-mod2", "mod3-mod3"], ["mod4-mod4", "mod5-mod5", "mod6-mod6", "mod2-mod2"], false], + [[], ["mod4-mod4", "mod5-mod5", "mod6-mod6"], true], + [["mod1-mod1", "mod2-mod2", "mod3-mod3"], [], true], + [[], [], true], +] + +# Test with a valid mod id array +# Test with an invalid mod id array +var test_is_mod_id_array_valid_params = [ + [["mod1-mod1", "mod2-mod2", "mod3-mod3"], true], + [["mod1-mod1", "mod2-mod2", "invalid-mod21###"], false], +] + func test_is_mod_id_valid(params = use_parameters(test_is_mod_id_valid_params)) -> void: # prepare @@ -33,42 +52,37 @@ func test_is_mod_id_valid(params = use_parameters(test_is_mod_id_valid_params)) ) -func test_validate_distinct_mod_ids_in_arrays(): - var array_one: PoolStringArray = ["mod1-mod1", "mod2-mod2", "mod3-mod3"] - var array_two: PoolStringArray = ["mod4-mod4", "mod5-mod5", "mod6-mod6"] - var array_description: PoolStringArray = ["array_1", "array_2"] +func test_validate_distinct_mod_ids_in_arrays(params = use_parameters(test_validate_distinct_mod_ids_in_arrays_params)) -> void: + # prepare var mod_id = "test-mod" + var array_one = params[0] + var array_two = params[1] + var array_description = ["array_one", "array_two"] var additional_info = "additional info" + var expected_result = params[2] - # Test with distinct mod ids in arrays - var result = ModManifest.validate_distinct_mod_ids_in_arrays(mod_id, array_one, array_two, ["array_one", "array_two"], additional_info, true) - assert_eq(result, true) - - # Test with overlapping mod ids in arrays - array_two = ["mod4-mod4", "mod5-mod5", "mod6-mod6", "mod2-mod2"] - result = ModManifest.validate_distinct_mod_ids_in_arrays(mod_id, array_one, array_two, ["array_one", "array_two"], additional_info, true) - assert_eq(result, false) - - # Test with no mod ids in one array - array_two = [] - result = ModManifest.validate_distinct_mod_ids_in_arrays(mod_id, array_one, array_two, ["array_one", "array_two"], additional_info, true) - assert_eq(result, true) + # test + var result = ModManifest.validate_distinct_mod_ids_in_arrays(mod_id, array_one, array_two, array_description, additional_info, true) - # Test with no mod ids in both arrays - array_one = [] - array_two = [] - result = ModManifest.validate_distinct_mod_ids_in_arrays(mod_id, array_one, array_two, ["array_one", "array_two"], additional_info, true) - assert_eq(result, true) + # validate + assert_true( + result == expected_result, + "Expected %s but was %s instead for this arrays \"%s\" - \"%s\"" % [expected_result, result, array_one, array_two] + ) -func test_is_mod_id_array_valid(): - var mod_id_array = PoolStringArray(["mod1-mod1", "mod2-mod2", "mod3-mod3"]) +func test_is_mod_id_array_valid(params = use_parameters(test_is_mod_id_array_valid_params)) -> void: + # prepare + var mod_id = "test-mod" + var mod_id_array = params[0] + var description = "array_description" + var expected_result = params[1] - # Test with a valid mod id array - var result = ModManifest.is_mod_id_array_valid("own-mod", mod_id_array, "dependencies", true) - assert_eq(result, true) + # test + var result = ModManifest.is_mod_id_array_valid(mod_id, mod_id_array, description, true) - # Test with an invalid mod id array - mod_id_array = PoolStringArray(["mod1-mod1", "mod2-mod2", "invalid-mod21###"]) - result = ModManifest.is_mod_id_array_valid("own-mod", mod_id_array, "dependencies", true) - assert_eq(result, false) + # validate + assert_true( + result == expected_result, + "Expected %s but was %s instead for this array \"%s\"" % [expected_result, result, mod_id_array] + )