summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/test/corpse.lua
blob: 90854369e4dd8ddaa3917e8a59c3ced21a7d640c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
-----------------------------------------------------------------------
-- Tests for corpse gen.
-----------------------------------------------------------------------

local p = dgn.point(20, 20)

debug.goto_place("Depths:2")

local function ok(corpse, pattern)
  dgn.reset_level()
  dgn.fill_grd_area(1, 1, dgn.GXM - 2, dgn.GYM - 2, 'floor')
  dgn.create_item(p.x, p.y, corpse)

  local items = dgn.items_at(p.x, p.y)
  assert(#items > 0, "Could not create item for '" .. corpse .. "'")
  assert(#items == 1, "Unexpected item count for '" .. corpse .. "'")

  local item = items[1]
  local name = item.name('')

  pattern = pattern or corpse
  assert(string.find(name, pattern, 1, true),
         "Unexpected item name: " .. name .. ", expected: " .. pattern)
end

local function fail(corpse, pattern)
  assert(not pcall(function ()
                     ok(corpse, pattern)
                   end),
         "Expected item '" .. corpse .. "' to fail, but it did not")
end

-- All set up!
ok("hydra corpse")
ok("hippogriff skeleton")
for i = 1,100 do
  ok("any corpse", "corpse")
end
ok("rat chunk", "chunk of rat")
fail("zombie chunk")
fail("giant eyeball corpse")
ok("orc warrior corpse", "orc corpse")