| 1 |
--[[ Copyright (c) 2014 Edvin "Lego3" Linge |
| 2 |
|
| 3 |
Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 4 |
this software and associated documentation files (the "Software"), to deal in |
| 5 |
the Software without restriction, including without limitation the rights to |
| 6 |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 7 |
of the Software, and to permit persons to whom the Software is furnished to do |
| 8 |
so, subject to the following conditions: |
| 9 |
|
| 10 |
The above copyright notice and this permission notice shall be included in all |
| 11 |
copies or substantial portions of the Software. |
| 12 |
|
| 13 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 |
SOFTWARE. --]] |
| 20 |
|
| 21 |
require("class_test_base") |
| 22 |
|
| 23 |
require("utility") |
| 24 |
require("entity") |
| 25 |
require("entities.object") |
| 26 |
|
| 27 |
describe("object.lua: ", function() |
| 28 |
local stub_world = {map = {}} |
| 29 |
local stub_hospital = {world = stub_world} |
| 30 |
_G["Hospital"] = stub_hospital |
| 31 |
|
| 32 |
local fake_object_type = {ticks = false, idle_animations = {west = true}} |
| 33 |
local tile_x, tile_y, direction = 10, 10, "west" |
| 34 |
|
| 35 |
local function createObjectWithFakeInput() |
| 36 |
stub(stub_world, "getLocalPlayerHospital") |
| 37 |
stub(stub_world, "addObjectToTile") |
| 38 |
stub(stub_world, "clearCaches") |
| 39 |
return Object(stub_hospital, fake_object_type, tile_x, tile_y, direction) |
| 40 |
end |
| 41 |
|
| 42 |
it("can create Object objects", function() |
| 43 |
local object = createObjectWithFakeInput() |
| 44 |
|
| 45 |
assert.are.equal(fake_object_type, object.object_type) |
| 46 |
assert.are.equal(stub_world.map, object.world.map) |
| 47 |
end) |
| 48 |
it("can transfer state", function() |
| 49 |
local object1 = createObjectWithFakeInput() |
| 50 |
object1.times_used = object1.times_used + 7 |
| 51 |
local object2 = createObjectWithFakeInput() |
| 52 |
assert.are_not.equal(object1.times_used, object2.times_used) |
| 53 |
|
| 54 |
object2:setState(object1:getState()) |
| 55 |
assert.are.equal(object1.times_used, object2.times_used) |
| 56 |
end) |
| 57 |
end) |