Apply the new ground_level method.
[crawl.git] / crawl-ref / source / test / monster-name.lua
blob5bc6e343ce47b5193d4bb65a6674e2540a744d1c
1 local place = dgn.point(20, 20)
3 debug.goto_place("D:2")
4 dgn.reset_level()
6 local function itemname(item_spec, name_type)
7 dgn.reset_level()
8 dgn.fill_grd_area(1, 1, dgn.GXM - 2, dgn.GYM - 2, 'floor')
9 local items = test.place_items_at(place, item_spec)
10 assert(#items == 1,
11 "Could not create item: '" .. item_spec .. "'")
12 local top_item = items[1]
13 return top_item.name(name_type)
14 end
16 local function check_monster_name(mspec, monster_name_checks,
17 corpse_name_checks)
19 dgn.reset_level()
20 dgn.fill_grd_area(1, 1, dgn.GXM - 2, dgn.GYM - 2, 'floor')
22 local function check_names(thing, name_checks, namefn)
23 if type(name_checks) == 'string' then
24 test.eq(namefn(thing), name_checks, mspec)
25 else
26 local desc_type = name_checks[1]
27 local expected_name = name_checks[2]
28 if type(desc_type) == 'string' then
29 test.eq(namefn(thing, desc_type), expected_name, mspec)
30 else
31 for i = 1, #desc_type do
32 test.eq(namefn(thing, desc_type[i]), expected_name[i], mspec)
33 end
34 end
35 end
36 end
38 local function check_monster_names(name_checks)
39 local mons = dgn.create_monster(place.x, place.y, mspec)
40 assert(mons, "Could not create monster from spec: " .. mspec)
41 check_names(mons, name_checks,
42 function (mons, desc)
43 return mons.mfull_name(desc)
44 end)
45 end
47 local function check_monster_corpse_names(name_checks)
48 local corpse_spec = mspec .. " corpse"
49 local items = test.place_items_at(place, corpse_spec)
50 assert(#items == 1,
51 "Could not create corpse: " .. corpse_spec)
52 local corpse = items[1]
53 check_names(corpse, name_checks,
54 function (corpse, desc)
55 return corpse.name(desc)
56 end)
57 end
59 check_monster_names(monster_name_checks)
60 if corpse_name_checks then
61 check_monster_corpse_names(corpse_name_checks)
62 end
63 end
65 local function check_names(list)
66 for _, check in ipairs(list) do
67 check_monster_name(check[1], check[2], check[3])
68 end
69 end
71 -- Each line must have two or three entries:
72 -- 1. A valid monster spec to generate the monster
73 -- 2. The expected monster name (string) for DESC_PLAIN OR
74 -- a table as { desc_type, expected_monster_name } where
75 -- desc_type is a description type string ("a", "The", etc.) or a table
76 -- of description type strings. expected_monster_name is an expected
77 -- monster name string or a table of strings (if the description type is
78 -- also a table.
79 -- 3. Optionally, the expected item name for DESC_PLAIN or a table of
80 -- item description type and expected item name.
81 local name_checks = {
82 { "griffon", { "The", "The griffon" }, { "a", "a griffon corpse" } },
83 { "kobold name:ugly name_adjective",
84 { "A", "An ugly kobold" } },
85 { "kobold name:ugly name_adjective",
86 { "the", "the ugly kobold" } },
87 { "kobold name:ugly n_adj n_spe", "ugly kobold", "ugly kobold corpse" },
88 { "kobold name:Durwent",
89 { "A", "Durwent the kobold" },
90 { "a", "the kobold corpse of Durwent" } },
91 { "kobold name:wearing_mittens name_suffix",
92 { "A", "A kobold wearing mittens" },
93 "kobold corpse" },
94 { "gnoll name:gnoll_sergeant name_replace name_descriptor name_species",
95 { "A", "A gnoll sergeant" },
96 { "a", "a gnoll sergeant corpse" } },
97 { "gnoll name:gnoll_sergeant name_replace name_descriptor",
98 { "A", "A gnoll sergeant" },
99 -- [ds] FIXME: this should probably be just "a gnoll corpse"
100 { "a", "a gnoll corpse of gnoll sergeant" } },
102 check_names(name_checks)
104 test.eq(itemname("hydra chunk q:10"), "10 chunks of hydra flesh")