-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_swr_properties.py
More file actions
202 lines (183 loc) · 5.14 KB
/
Copy pathtest_swr_properties.py
File metadata and controls
202 lines (183 loc) · 5.14 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import tempfile
from pathlib import Path
from hypothesis import given, settings
from hypothesis import strategies as st
import area_reader.dialects.rom
import area_reader.dialects.swr
import area_reader.model
small_stat = st.integers(min_value=-10_000, max_value=10_000)
def swr_reader_for(text: str) -> area_reader.dialects.swr.SwrAreaFile:
with tempfile.TemporaryDirectory() as directory:
path = Path(directory) / "record.are"
path.write_text(text, encoding="latin-1")
return area_reader.dialects.swr.SwrAreaFile(path)
def padded(values, size):
return values + [0] * (size - len(values))
@given(
stats1=st.lists(small_stat, min_size=0, max_size=6),
stats2=st.lists(small_stat, min_size=0, max_size=3),
stats3=st.lists(small_stat, min_size=0, max_size=3),
stats4=st.lists(small_stat, min_size=0, max_size=5),
)
@settings(max_examples=25, deadline=None)
def test_swr_mobile_stats_accept_every_supported_prefix(
stats1,
stats2,
stats3,
stats4,
):
reader = swr_reader_for(
f"""Vnum 100
Keywords test mobile~
Short a test mobile~
Long A test mobile waits here.~
Desc A generated mobile.~
Race Human~
Position standing~
DefPos resting~
Gender neuter~
Stats1 {" ".join(map(str, stats1))}
Stats2 {" ".join(map(str, stats2))}
Stats3 {" ".join(map(str, stats3))}
Stats4 {" ".join(map(str, stats4))}
Actflags npc~
UnknownMobile 123
#MUDPROG
Progtype all_greet_prog~
Arglist 100~
Comlist say hello~
UnknownProgram ignored~
#ENDPROG
#ENDMOBILE
"""
)
mob = reader.read_fuss_mobile()
stats1 = padded(stats1, 6)
stats2 = padded(stats2, 3)
stats3 = padded(stats3, 3)
stats4 = padded(stats4, 5)
assert mob.vnum == 100
assert mob.alignment == stats1[0]
assert mob.level == stats1[1]
assert mob.wealth == stats1[4]
assert mob.hit == area_reader.model.Dice(*stats2)
assert mob.damage == area_reader.model.Dice(*stats3)
assert mob.hitroll == stats4[3]
assert mob.ac == area_reader.dialects.rom.RomArmorClass(*([stats1[3]] * 4))
@given(
values=st.lists(small_stat, min_size=0, max_size=6),
stats=st.lists(small_stat, min_size=0, max_size=5),
)
@settings(max_examples=20, deadline=None)
def test_swr_object_values_and_stats_preserve_supported_prefixes(values, stats):
reader = swr_reader_for(
f"""Vnum 200
Keywords test object~
Short a test object~
Long A test object lies here.~
Values {" ".join(map(str, values))}
Stats {" ".join(map(str, stats))}
Action ignored~
UnknownObject 456
#EXDESC
ExDescKey object detail~
ExDesc Generated detail text.~
UnknownExDesc ignored~
#ENDEXDESC
#MUDPROG
Progtype get_prog~
Arglist 100~
Comlist say taken~
#ENDPROG
#ENDOBJECT
"""
)
item = reader.read_fuss_object()
assert item.vnum == 200
assert item.value == values
assert item.weight == (stats[0] if len(stats) > 0 else 0)
assert item.cost == (stats[1] if len(stats) > 1 else 0)
assert item.level == (stats[3] if len(stats) > 3 else 0)
assert item.layers == (stats[4] if len(stats) > 4 else 0)
assert item.extra_descriptions == [
area_reader.dialects.swr.SwrExtraDescription(
keyword="object detail",
description="Generated detail text.",
unknown=[
area_reader.dialects.swr.SwrUnknown(
key="UnknownExDesc",
value="ignored",
tilde=True,
),
],
),
]
@given(stats=st.lists(small_stat, min_size=0, max_size=3))
@settings(max_examples=20, deadline=None)
def test_swr_room_stats_and_nested_records_preserve_supported_prefixes(stats):
reader = swr_reader_for(
f"""Vnum 300
Name Test Room~
Desc A generated room.~
Sector city~
Stats {" ".join(map(str, stats))}
Flags nomob indoors~
UnknownRoom ignored~
#EXIT
Direction north~
Desc A northern exit.~
Distance 4
Key 301
Keywords gate~
ToRoom 302
Flags isdoor~
UnknownExit ignored~
#ENDEXIT
#EXDESC
ExDescKey mural~
ExDesc A generated mural.~
#ENDEXDESC
#MUDPROG
Progtype speech_prog~
Arglist hello~
Comlist say hello~
#ENDPROG
Reset M 0 400 1 300
#ENDROOM
"""
)
room = reader.read_fuss_room()
assert room.vnum == 300
assert room.tele_delay == (stats[0] if len(stats) > 0 else 0)
assert room.tele_vnum == (stats[1] if len(stats) > 1 else 0)
assert room.tunnel == (stats[2] if len(stats) > 2 else 0)
assert room.exits == [
area_reader.dialects.swr.SwrExit(
door="north",
description="A northern exit.",
keyword="gate",
key=301,
destination=302,
distance=4,
flags="isdoor",
unknown=[
area_reader.dialects.swr.SwrUnknown(
key="UnknownExit",
value="ignored",
tilde=True,
),
],
),
]
assert room.extra_descriptions == [
area_reader.dialects.swr.SwrExtraDescription(
keyword="mural",
description="A generated mural.",
),
]
assert room.resets[0].command == "M"
assert (room.resets[0].arg1, room.resets[0].arg2, room.resets[0].arg3) == (
400,
1,
300,
)