Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestFramework: [VM and YYC] Struct Bracket Accessor :Const: with multiple accessors (Read/Write) in BasicAccessorExpressionsTestSuite, This code should be uncommented when the bug #8041 is fixed! #41

Open
sihammill opened this issue Feb 10, 2025 · 0 comments
Assignees

Comments

@sihammill
Copy link
Collaborator

Workflow Artifact URL

https://github.com/YoYoGames/GM-TestFramework/actions/runs/13176739773/artifacts/2546661953

Test Code

	addFact("Struct Bracket Accessor :Const: with multiple accessors (Read/Write)", function() {
		// Initialize the struct with various data structures and values
		var struct = {
		    array: [10, 20, 30],                      // Array for Struct, Array access
		    list: ds_list_create(),                   // List for Struct, List access
		    grid: ds_grid_create(5, 5),               // Grid for Struct, Grid access
		    map: ds_map_create(),                     // Map for Struct, Map access
		    structDot: {name: "dotValue"},            // Struct for Struct, Struct Dot access
		    structBracket: {bracketName: "bracketValue"}, // Struct for Struct, Struct Bracket access
		    structHash: {hashName: "hashValue"},      // Struct for Struct, Struct Hash access
		    functionCall: function() {                // Function Call for Struct, Function Call access
		        return {key: "funcValue"};
		    }
		};

		// Populate List
		ds_list_add(struct[$ "list"], 1, 2, 3);

		// Populate Grid
		ds_grid_set(struct[$ "grid"], 2, 2, 50);

		// Populate Map
		ds_map_add(struct[$ "map"], "mapName", 300);

		// ** Write Operations **

		// Struct Hash, Array Access - Modify value
		struct[$ "array"][1] = 999;
		assert_equals(struct[$ "array"][1], 999, "Struct Bracket :Const:, Array write failed.");

		// Struct Hash, List Access - Modify value
		struct[$ "list"][| 1] = 888;
		assert_equals(struct[$ "list"][| 1], 888,  "Struct Bracket :Const:, List write failed.");

		// Struct Hash, Grid Access - Modify value
		struct[$ "grid"][# 2, 2] = 777;
		assert_equals(struct[$ "grid"][# 2, 2], 777,  "Struct Bracket :Const:, Grid write failed.");

		// Struct Hash, Map Access - Modify value
		struct[$ "map"][? "mapName"] = 666;
		assert_equals(struct[$ "map"][? "mapName"], 666,  "Struct Bracket :Const:, Map write failed.");

		// Struct Hash, Struct Dot Access - Modify value
		struct[$ "structDot"].name = "newDotValue";
		assert_equals(struct[$ "structDot"].name, "newDotValue",  "Struct Bracket :Const:, Struct Dot write failed.");

		// Struct Hash, Struct Bracket Access :Const: - Modify value
		struct[$ "structBracket"][$ "bracketName"] = "newBracketValue";
		assert_equals(struct[$ "structBracket"][$ "bracketName"], "newBracketValue",  "Struct Bracket :Const:, Struct Bracket :Const: write failed.");

		// Struct Hash, Struct Bracket Access :Dynamic: - Modify value
		var _key = "bracketName"
		struct[$ "structBracket"][$ _key] = "newBracketValue";
		assert_equals(struct[$ "structBracket"][$ _key], "newBracketValue",  "Struct Bracket :Const:, Struct Bracket :Dynamic: write failed.");

		// Struct Hash, Struct Hash Access - Modify value
		struct_set_from_hash(struct[$ "structHash"], variable_get_hash("hashName"), "newHashValue");
		assert_equals(struct_get_from_hash(struct[$ "structHash"], variable_get_hash("hashName")), "newHashValue",  "Struct Bracket :Const:, Struct Hash write failed.");

		// ** Read Operations **

		// Struct Hash, Array Access
		assert_equals(struct[$ "array"][1], 999,  "Struct Bracket :Const:, Array access failed.");

		// Struct Hash, List Access
		assert_equals(struct[$ "list"][| 1], 888,  "Struct Bracket :Const:, List access failed.");

		// Struct Hash, Grid Access
		assert_equals(struct[$ "grid"][# 2, 2], 777,  "Struct Bracket :Const:, Grid access failed.");

		// Struct Hash, Map Access
		assert_equals(struct[$ "map"][? "mapName"], 666,  "Struct Bracket :Const:, Map access failed.");

		// Struct Hash, Struct Dot Access
		assert_equals(struct[$ "structDot"].name, "newDotValue",  "Struct Bracket :Const:, Struct Dot access failed.");

		// Struct Hash, Struct Bracket Access :Const:
		assert_equals(struct[$ "structBracket"][$ "bracketName"], "newBracketValue",  "Struct Bracket :Const:, Struct Bracket access failed.");

		// Struct Hash, Struct Bracket Access :Dynamic:
		var _key = "bracketName"
		assert_equals(struct[$ "structBracket"][$ _key], "newBracketValue",  "Struct Bracket :Const:, Struct Bracket access failed.");

		// Struct Hash, Struct Hash Access
		assert_equals(struct_get_from_hash(struct[$ "structHash"], variable_get_hash("hashName")), "newHashValue",  "Struct Bracket :Const:, Struct Hash access failed.");

		// Struct Hash, Function Call Access (no write)
		assert_true(false, "This code should be uncommented when the bug #8041 is fixed!");
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//		assert_equals(struct[$ "functionCall"]()[$ "key"], "funcValue",  "Struct Bracket :Const:, Function Call access failed.");
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		// Work around for the lines above until a bug is fixed ::  https://github.com/YoYoGames/GameMaker-Bugs/issues/8041
		// however both options should still be tested for
		var _retStruct = struct[$ "functionCall"]();
		assert_equals(_retStruct[$ "key"], "funcValue",  "Struct Bracket :Const:, Function Call access failed.");

		// Cleanup
		ds_list_destroy(struct[$ "list"]);
		ds_grid_destroy(struct[$ "grid"]);
		ds_map_destroy(struct[$ "map"]);
	});

Output From The Test

Test Name: Struct Bracket Accessor :Const: with multiple accessors (Read/Write)
Title: Asserted value to be true
Description: This code should be uncommented when the bug #8041 is fixed!
Expected Value: null
Actual Value: false
Stack: gml_Script_anon@28969@BasicAccessorExpressionsTestSuite@BasicAccessorExpressionsTestSuite

Runtime Version

2024.1300.0.749

Location Of The Test

https://github.com/YoYoGames/GM-TestFramework/blob/develop/projects/xUnit/scripts/BasicAccessorExpressionsTestSuite/BasicAccessorExpressionsTestSuite.gml#L638-L739

Which platform(s) are you seeing the problem on?

Windows

@sihammill sihammill self-assigned this Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant