1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-30 04:30:58 +02:00

More landfill_remover tests

This commit is contained in:
James Gillham 2020-09-30 19:47:03 +01:00
parent 965cebb005
commit 475b7dc8c6
2 changed files with 50 additions and 9 deletions

View File

@ -6,6 +6,14 @@ local Helper = require 'utils.test.helper'
local main_inventory = defines.inventory.character_main
local config = global.config.landfill_remover
local tile_items = {
'stone-brick',
'concrete',
'hazard-concrete',
'refined-concrete',
'refined-hazard-concrete'
}
Declare.module(
'landfill remover',
function()
@ -29,6 +37,7 @@ Declare.module(
inventory.insert('deconstruction-planner')
local stack = inventory.find_item_stack('deconstruction-planner')
stack.set_tile_filter(1, 'landfill')
stack.tile_selection_mode = defines.deconstruction_item.tile_selection_mode.only
local cursor = player.cursor_stack
cursor.set_stack(stack)
@ -56,14 +65,7 @@ Declare.module(
end
)
local items = {
'stone-brick',
'concrete',
'hazard-concrete',
'refined-concrete',
'refined-hazard-concrete'
}
for _, item_name in pairs(items) do
for _, item_name in pairs(tile_items) do
Declare.test(
'can remove landfill when covered by ' .. item_name,
function(context)
@ -101,6 +103,7 @@ Declare.module(
local area = {{2.1, 2.1}, {2.9, 2.9}}
surface.set_tiles({{name = 'landfill', position = position}})
-- Place entity.
local cursor = player.cursor_stack
cursor.set_stack('iron-chest')
player.build_from_cursor({position = position})
@ -120,5 +123,44 @@ Declare.module(
entity.destroy()
end
)
for _, item_name in pairs(tile_items) do
Declare.test(
'does not remove covered by ' .. item_name .. ' landfill when entity present',
function(context)
-- Arrange
local player = context.player
local surface = player.surface
local position = {2, 2}
local area = {{2.1, 2.1}, {2.9, 2.9}}
surface.set_tiles({{name = 'landfill', position = position}})
-- Place covering tile.
local cursor = player.cursor_stack
cursor.set_stack(item_name)
player.build_from_cursor({position = position, terrain_building_size = 1})
local before_tile = surface.get_tile(position[1], position[2])
-- Place entity.
cursor.set_stack('iron-chest')
player.build_from_cursor({position = position})
cursor = setup_player_with_valid_deconstruction_planner(player)
-- Act
EventFactory.do_player_deconstruct_area(cursor, player, area)
-- Assert
local tile = surface.get_tile(position[1], position[2])
Assert.equal(before_tile.name, tile.name)
local entities = surface.find_entities(area)
local entity = entities[1]
Assert.is_lua_object_with_name(entity, 'iron-chest', 'iron-chest was not valid.')
entity.destroy()
end
)
end
end
)

View File

@ -5,7 +5,6 @@ function find_all_tests()
local loaded = _G.package.loaded
for name in pairs(loaded) do
pcall(require, name .. '_test')
pcall(require, name .. '_tests')
end
end