mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-10-30 23:15:32 +01:00 
			
		
		
		
	Support packing arbitrary graphs (#12289)
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							d17d7eba14
						
					
				
				
					commit
					7f58887ae3
				
			| @@ -60,15 +60,34 @@ local function test_object_passing() | ||||
| 	local tmp = core.serialize_roundtrip(test_object) | ||||
| 	assert(deepequal(test_object, tmp)) | ||||
|  | ||||
| 	-- Circular key, should error | ||||
| 	tmp = {"foo", "bar"} | ||||
| 	tmp[tmp] = true | ||||
| 	assert(not pcall(core.serialize_roundtrip, tmp)) | ||||
| 	local circular_key = {"foo", "bar"} | ||||
| 	circular_key[circular_key] = true | ||||
| 	tmp = core.serialize_roundtrip(circular_key) | ||||
| 	assert(tmp[1] == "foo") | ||||
| 	assert(tmp[2] == "bar") | ||||
| 	assert(tmp[tmp] == true) | ||||
|  | ||||
| 	-- Circular value, should error | ||||
| 	tmp = {"foo"} | ||||
| 	tmp[2] = tmp | ||||
| 	assert(not pcall(core.serialize_roundtrip, tmp)) | ||||
| 	local circular_value = {"foo"} | ||||
| 	circular_value[2] = circular_value | ||||
| 	tmp = core.serialize_roundtrip(circular_value) | ||||
| 	assert(tmp[1] == "foo") | ||||
| 	assert(tmp[2] == tmp) | ||||
|  | ||||
| 	-- Two-segment cycle | ||||
| 	local cycle_seg_1, cycle_seg_2 = {}, {} | ||||
| 	cycle_seg_1[1] = cycle_seg_2 | ||||
| 	cycle_seg_2[1] = cycle_seg_1 | ||||
| 	tmp = core.serialize_roundtrip(cycle_seg_1) | ||||
| 	assert(tmp[1][1] == tmp) | ||||
|  | ||||
| 	-- Duplicated value without a cycle | ||||
| 	local acyclic_dup_holder = {} | ||||
| 	tmp = ItemStack("") | ||||
| 	acyclic_dup_holder[tmp] = tmp | ||||
| 	tmp = core.serialize_roundtrip(acyclic_dup_holder) | ||||
| 	for k, v in pairs(tmp) do | ||||
| 		assert(rawequal(k, v)) | ||||
| 	end | ||||
| end | ||||
| unittests.register("test_object_passing", test_object_passing) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user