| 1 |
--[[ Copyright (c) 2018 Pavel "sofo" Schoffer |
| 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("entity") |
| 24 |
require("entities.humanoid") |
| 25 |
|
| 26 |
describe("Humanoid:", function() |
| 27 |
local function getHumanoid() |
| 28 |
local animation = {setHitTestResult = function() end} |
| 29 |
return Humanoid(animation) |
| 30 |
end |
| 31 |
|
| 32 |
it("Gets the current action", function() |
| 33 |
local humanoid = getHumanoid() |
| 34 |
|
| 35 |
local action1 = {name = "fake1"} |
| 36 |
local action2 = {name = "fake2"} |
| 37 |
humanoid:queueAction(action1) |
| 38 |
humanoid:queueAction(action2) |
| 39 |
|
| 40 |
local recievedAction = humanoid:getCurrentAction() |
| 41 |
|
| 42 |
assert.equal(action1, recievedAction) |
| 43 |
end) |
| 44 |
it("Throws error if no action is queued", function() |
| 45 |
local humanoid = getHumanoid() |
| 46 |
|
| 47 |
local state, error = pcall(humanoid.getCurrentAction, humanoid) |
| 48 |
|
| 49 |
assert.False(state) |
| 50 |
local expected_message = "Action queue was empty. This should never happen." |
| 51 |
assert.matches(error, expected_message) |
| 52 |
assert.matches(error, "humanoid %-") |
| 53 |
end) |
| 54 |
it("Can represent itself as a string", function() |
| 55 |
local humanoid = getHumanoid() |
| 56 |
humanoid.humanoid_class = "class" |
| 57 |
|
| 58 |
local result = humanoid:tostring() |
| 59 |
|
| 60 |
assert.matches(result, "humanoid[ -]*class.*class") |
| 61 |
assert.matches(result, "Warmth.*Happiness.*Fatigue") |
| 62 |
assert.matches(result, "Actions: %[%]") |
| 63 |
end) |
| 64 |
it("Can add actions to a representation", function() |
| 65 |
local humanoid = getHumanoid() |
| 66 |
humanoid.action_queue = {{name = "A1", room_type = "room"}, {name = "A2"}} |
| 67 |
|
| 68 |
local result = humanoid:tostring() |
| 69 |
|
| 70 |
assert.matches(result, "Actions.*%[A1 %- room, A2%]") |
| 71 |
end) |
| 72 |
|
| 73 |
end) |