forked from PathOfBuildingCommunity/PathOfBuilding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestItemParse_spec.lua
More file actions
522 lines (466 loc) · 18.1 KB
/
TestItemParse_spec.lua
File metadata and controls
522 lines (466 loc) · 18.1 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
describe("TestItemParse", function()
local function raw(s, base)
base = base or "Plate Vest"
return "Rarity: Rare\nName\n"..base.."\n"..s
end
it("Rarity", function()
local item = new("Item", "Rarity: Normal\nCoral Ring")
assert.are.equals("NORMAL", item.rarity)
item = new("Item", "Rarity: Magic\nCoral Ring")
assert.are.equals("MAGIC", item.rarity)
item = new("Item", "Rarity: Rare\nName\nCoral Ring")
assert.are.equals("RARE", item.rarity)
item = new("Item", "Rarity: Unique\nName\nCoral Ring")
assert.are.equals("UNIQUE", item.rarity)
item = new("Item", "Rarity: Unique\nName\nCoral Ring\nFoil Unique (Verdant)")
assert.are.equals("RELIC", item.rarity)
end)
it("Superior/Synthesised", function()
local item = new("Item", raw("", "Superior Plate Vest"))
assert.are.equals("Plate Vest", item.baseName)
item = new("Item", raw("", "Synthesised Plate Vest"))
assert.are.equals("Plate Vest", item.baseName)
item = new("Item", raw("", "Superior Synthesised Plate Vest"))
assert.are.equals("Plate Vest", item.baseName)
end)
it("Two-Toned Boots", function()
local item = new("Item", raw("", "Two-Toned Boots"))
assert.are.equals("Two-Toned Boots (Armour/Energy Shield)", item.baseName)
item = new("Item", raw("Armour: 10\nEnergy Shield: 10", "Two-Toned Boots"))
assert.are.equals("Two-Toned Boots (Armour/Energy Shield)", item.baseName)
item = new("Item", raw("Armour: 10\nEvasion Rating: 10", "Two-Toned Boots"))
assert.are.equals("Two-Toned Boots (Armour/Evasion)", item.baseName)
item = new("Item", raw("Evasion Rating: 10\nEnergy Shield: 10", "Two-Toned Boots"))
assert.are.equals("Two-Toned Boots (Evasion/Energy Shield)", item.baseName)
end)
it("Magic Two-Toned Boots", function()
local item = new("Item", [[
Rarity: Magic
Stalwart Two-Toned Boots of Plunder
Armour: 100
Energy Shield: 100
]])
assert.are.equal("Two-Toned Boots (Armour/Energy Shield)", item.baseName)
assert.are.equal("Stalwart ", item.namePrefix)
assert.are.equal(" of Plunder", item.nameSuffix)
item = new("Item", [[
Rarity: Magic
Sanguine Two-Toned Boots of the Phoenix
Armour: 100
Evasion Rating: 100
]])
assert.are.equal("Two-Toned Boots (Armour/Evasion)", item.baseName)
assert.are.equal("Sanguine ", item.namePrefix)
assert.are.equal(" of the Phoenix", item.nameSuffix)
item = new("Item", [[
Rarity: Magic
Stout Two-Toned Boots of the Lightning
Evasion Rating: 100
Energy Shield: 100
]])
assert.are.equal("Two-Toned Boots (Evasion/Energy Shield)", item.baseName)
assert.are.equal("Stout ", item.namePrefix)
assert.are.equal(" of the Lightning", item.nameSuffix)
end)
it("Title", function()
local item = new("Item", [[
Rarity: Rare
Phoenix Paw
Iron Gauntlets
]])
assert.are.equal("Phoenix Paw", item.title)
assert.are.equal("Iron Gauntlets", item.baseName)
assert.are.equal("Phoenix Paw, Iron Gauntlets", item.name)
end)
it("Unique ID", function()
local item = new("Item", raw("Unique ID: 40f9711d5bd7ad2bcbddaf71c705607aef0eecd3dcadaafec6c0192f79b82863"))
assert.are.equals("40f9711d5bd7ad2bcbddaf71c705607aef0eecd3dcadaafec6c0192f79b82863", item.uniqueID)
end)
it("Item Level", function()
local item = new("Item", raw("Item Level: 10"))
assert.are.equals(10, item.itemLevel)
end)
it("Quality", function()
local item = new("Item", raw("Quality: 10"))
assert.are.equals(10, item.quality)
item = new("Item", raw("Quality: +12% (augmented)"))
assert.are.equals(12, item.quality)
end)
it("Sockets", function()
local item = new("Item", raw("Sockets: R-G R-B-W A"))
assert.are.same({
{ color = "R", group = 0 },
{ color = "G", group = 0 },
{ color = "R", group = 1 },
{ color = "B", group = 1 },
{ color = "W", group = 1 },
{ color = "A", group = 2 },
}, item.sockets)
end)
it("Jewel", function()
local item = new("Item", raw("Radius: Large\nLimited to: 2", "Cobalt Jewel"))
assert.are.equals("Large", item.jewelRadiusLabel)
assert.are.equals(2, item.limit)
end)
it("Variant name", function()
local item = new("Item", raw("Variant: Pre 3.19.0\nVariant: Current"))
assert.are.same({ "Pre 3.19.0", "Current" }, item.variantList)
end)
it("Talisman Tier", function()
local item = new("Item", raw("Talisman Tier: 3", "Rotfeather Talisman"))
assert.are.equals(3, item.talismanTier)
end)
it("Defence", function()
local item = new("Item", raw("Armour: 25"))
assert.are.equals(25, item.armourData.Armour)
item = new("Item", raw("Armour: 25 (augmented)"))
assert.are.equals(25, item.armourData.Armour)
item = new("Item", raw("Evasion Rating: 35", "Shabby Jerkin"))
assert.are.equals(35, item.armourData.Evasion)
item = new("Item", raw("Energy Shield: 15", "Simple Robe"))
assert.are.equals(15, item.armourData.EnergyShield)
item = new("Item", raw("Ward: 180", "Runic Crown"))
assert.are.equals(180, item.armourData.Ward)
end)
it("Defence BasePercentile", function()
local item = new("Item", raw("ArmourBasePercentile: 0.5"))
assert.are.equals(0.5, item.armourData.ArmourBasePercentile)
item = new("Item", raw("EvasionBasePercentile: 0.6", "Shabby Jerkin"))
assert.are.equals(0.6, item.armourData.EvasionBasePercentile)
item = new("Item", raw("EnergyShieldBasePercentile: 0.7", "Simple Robe"))
assert.are.equals(0.7, item.armourData.EnergyShieldBasePercentile)
item = new("Item", raw("WardBasePercentile: 0.8", "Runic Crown"))
assert.are.equals(0.8, item.armourData.WardBasePercentile)
end)
it("Requires Level", function()
local item = new("Item", raw("Requires Level 10"))
assert.are.equals(10, item.requirements.level)
item = new("Item", raw("Level: 10"))
assert.are.equals(10, item.requirements.level)
item = new("Item", raw("LevelReq: 10"))
assert.are.equals(10, item.requirements.level)
end)
it("Alt Variant", function()
local item = new("Item", raw([[
Has Alt Variant: true
Has Alt Variant Two: true
Has Alt Variant Three: true
Has Alt Variant Four: true
Has Alt Variant Five: true
Selected Variant: 10
Selected Alt Variant: 11
Selected Alt Variant Two: 12
Selected Alt Variant Three: 13
Selected Alt Variant Four: 14
Selected Alt Variant Five: 15
]]))
assert.truthy(item.hasAltVariant)
assert.truthy(item.hasAltVariant2)
assert.truthy(item.hasAltVariant3)
assert.truthy(item.hasAltVariant4)
assert.truthy(item.hasAltVariant5)
assert.are.equals(10, item.variant)
assert.are.equals(11, item.variantAlt)
assert.are.equals(12, item.variantAlt2)
assert.are.equals(13, item.variantAlt3)
assert.are.equals(14, item.variantAlt4)
assert.are.equals(15, item.variantAlt5)
end)
it("Prefix/Suffix", function()
local item = new("Item", raw([[
Prefix: {range:0.1}IncreasedLife1
Suffix: {range:0.2}ColdResist1
]]))
assert.are.equals("IncreasedLife1", item.prefixes[1].modId)
assert.are.equals(0.1, item.prefixes[1].range)
assert.are.equals("ColdResist1", item.suffixes[1].modId)
assert.are.equals(0.2, item.suffixes[1].range)
end)
it("Implicits", function()
local item = new("Item", raw([[
Implicits: 2
+8 to Strength
+10 to Intelligence
+12 to Dexterity
]]))
assert.are.equals(2, #item.implicitModLines)
assert.are.equals("+8 to Strength", item.implicitModLines[1].line)
assert.are.equals("+10 to Intelligence", item.implicitModLines[2].line)
assert.are.equals(1, #item.explicitModLines)
assert.are.equals("+12 to Dexterity", item.explicitModLines[1].line)
end)
it("League", function()
local item = new("Item", raw("League: Heist"))
assert.are.equals("Heist", item.league)
end)
it("Source", function()
local item = new("Item", raw("Source: No longer obtainable"))
assert.are.equals("No longer obtainable", item.source)
end)
it("Note", function()
local item = new("Item", raw("Note: ~price 1 chaos"))
assert.are.equals("~price 1 chaos", item.note)
end)
it("Attribute Requirements", function()
local item = new("Item", raw("Dex: 100"))
assert.are.equals(100, item.requirements.dex)
item = new("Item", raw("Int: 101"))
assert.are.equals(101, item.requirements.int)
item = new("Item", raw("Str: 102"))
assert.are.equals(102, item.requirements.str)
end)
it("Requires Class", function()
local item = new("Item", raw("Requires Class Witch"))
assert.are.equals("Witch", item.classRestriction)
item = new("Item", raw("Class:: Witch"))
assert.are.equals("Witch", item.classRestriction)
end)
it("Requires Class variant", function()
local item = new("Item", raw([[
Selected Variant: 2
+8 to Strength
{variant:1}Requires Class Witch
{variant:2}Requires Class Templar
]]))
assert.are.equals(2, item.variant)
assert.are.equals("Templar", item.classRestriction)
end)
it("Influence", function()
local item = new("Item", raw("Shaper Item"))
assert.truthy(item.shaper)
item = new("Item", raw("Elder Item"))
assert.truthy(item.elder)
item = new("Item", raw("Warlord Item"))
assert.truthy(item.adjudicator)
item = new("Item", raw("Hunter Item"))
assert.truthy(item.basilisk)
item = new("Item", raw("Crusader Item"))
assert.truthy(item.crusader)
item = new("Item", raw("Redeemer Item"))
assert.truthy(item.eyrie)
item = new("Item", raw("Searing Exarch Item"))
assert.truthy(item.cleansing)
item = new("Item", raw("Eater of Worlds Item"))
assert.truthy(item.tangle)
end)
it("short flags", function()
local item = new("Item", raw("Split"))
assert.truthy(item.split)
item = new("Item", raw("Mirrored"))
assert.truthy(item.mirrored)
item = new("Item", raw("Corrupted"))
assert.truthy(item.corrupted)
item = new("Item", raw("Fractured Item"))
assert.truthy(item.fractured)
item = new("Item", raw("Synthesised Item"))
assert.truthy(item.synthesised)
item = new("Item", raw("Crafted: true"))
assert.truthy(item.crafted)
item = new("Item", raw("Unreleased: true"))
assert.truthy(item.unreleased)
end)
it("long flags", function()
local item = new("Item", raw("This item can be anointed by Cassia"))
assert.truthy(item.canBeAnointed)
item = new("Item", raw("Can have a second Enchantment Modifier"))
assert.truthy(item.canHaveTwoEnchants)
item = new("Item", raw("Can have 1 additional Enchantment Modifiers"))
assert.truthy(item.canHaveTwoEnchants)
item = new("Item", raw("Can have 2 additional Enchantment Modifiers"))
assert.truthy(item.canHaveTwoEnchants)
assert.truthy(item.canHaveThreeEnchants)
item = new("Item", raw("Can have 3 additional Enchantment Modifiers"))
assert.truthy(item.canHaveTwoEnchants)
assert.truthy(item.canHaveThreeEnchants)
assert.truthy(item.canHaveFourEnchants)
item = new("Item", raw("Has a Crucible Passive Skill Tree with only Support Passive Skills"))
assert.truthy(item.canHaveOnlySupportSkillsCrucibleTree)
item = new("Item", raw("Has a Crucible Passive Skill Tree"))
assert.truthy(item.canHaveShieldCrucibleTree)
item = new("Item", raw("Has a Two Handed Sword Crucible Passive Skill Tree"))
assert.truthy(item.canHaveTwoHandedSwordCrucibleTree)
end)
it("tags", function()
local item = new("Item", raw("{tags:life,physical_damage}+8 to Strength"))
assert.are.same({ "life", "physical_damage" }, item.explicitModLines[1].modTags)
end)
it("variant", function()
local item = new("Item", raw([[
Selected Variant: 2
{variant:1}+8 to Strength
{variant:2,3}+10 to Strength
]]))
assert.are.equals(2, item.variant)
assert.are.same({ [1] = true }, item.explicitModLines[1].variantList)
assert.are.same({ [2] = true, [3] = true }, item.explicitModLines[2].variantList)
assert.are.equals(10, item.baseModList[1].value) -- variant 2 has +10 to Strength
end)
it("range", function()
local item = new("Item", raw("{range:0.8}+(8-12) to Strength"))
assert.are.equals(0.8, item.explicitModLines[1].range)
assert.are.equals(11, item.baseModList[1].value) -- range 0.8 of (8-12) = 11
end)
it("crafted", function()
local item = new("Item", raw("{crafted}+8 to Strength"))
assert.truthy(item.explicitModLines[1].crafted)
item = new("Item", raw("+8 to Strength (crafted)"))
assert.truthy(item.explicitModLines[1].crafted)
end)
it("crucible", function()
local item = new("Item", raw("{crucible}+8 to Strength"))
assert.truthy(item.crucibleModLines[1].crucible)
item = new("Item", raw("+8 to Strength (crucible)"))
assert.truthy(item.crucibleModLines[1].crucible)
end)
it("custom", function()
local item = new("Item", raw("{custom}+8 to Strength"))
assert.truthy(item.explicitModLines[1].custom)
end)
it("eater", function()
local item = new("Item", raw("{eater}+8 to Strength"))
assert.truthy(item.explicitModLines[1].eater)
end)
it("enchant", function()
local item = new("Item", raw("+8 to Strength (enchant)"))
assert.are.equals(1, #item.enchantModLines)
-- enchant also sets crafted and implicit
assert.truthy(item.enchantModLines[1].crafted)
assert.truthy(item.enchantModLines[1].implicit)
end)
it("exarch", function()
local item = new("Item", raw("{exarch}+8 to Strength"))
assert.truthy(item.explicitModLines[1].exarch)
end)
it("fractured", function()
local item = new("Item", raw("{fractured}+8 to Strength"))
assert.truthy(item.explicitModLines[1].fractured)
item = new("Item", raw("+8 to Strength (fractured)"))
assert.truthy(item.explicitModLines[1].fractured)
end)
it("implicit", function()
local item = new("Item", raw("+8 to Strength (implicit)"))
assert.truthy(item.implicitModLines[1].implicit)
end)
it("scourge", function()
local item = new("Item", raw("{scourge}+8 to Strength"))
assert.truthy(item.scourgeModLines[1].scourge)
item = new("Item", raw("+8 to Strength (scourge)"))
assert.truthy(item.scourgeModLines[1].scourge)
end)
it("synthesis", function()
local item = new("Item", raw("{synthesis}+8 to Strength"))
assert.truthy(item.explicitModLines[1].synthesis)
end)
it("multiple bases", function()
local item = new("Item", [[
Ashcaller
Selected Variant: 3
{variant:1,2,3}Quartz Wand
{variant:4}Carved Wand
]])
assert.are.same({
["Quartz Wand"] = { line = "Quartz Wand", variantList = { [1] = true, [2] = true, [3] = true } },
["Carved Wand"] = { line = "Carved Wand", variantList = { [4] = true } }
}, item.baseLines)
assert.are.equals("Quartz Wand", item.baseName)
item = new("Item", [[
Ashcaller
Selected Variant: 4
{variant:1,2,3}Quartz Wand
{variant:4}Carved Wand
]])
assert.are.equals("Carved Wand", item.baseName)
end)
it("parses text without armour value then changes quality and has correct final armour", function()
local item = new("Item", [[
Armour Gloves
Iron Gauntlets
Quality: 0
]])
local original = item.armourData.Armour
item.quality = 20
item:BuildAndParseRaw()
assert.are.equals(round(original * 1.2), item.armourData.Armour)
end)
it("magic item", function()
local item = new("Item", [[
Rarity: MAGIC
Name Prefix Iron Gauntlets -> +50 ignite chance
+50% chance to Ignite
]])
assert.are.equals("Name Prefix ", item.namePrefix)
assert.are.equals(" -> +50 ignite chance", item.nameSuffix)
assert.are.equals("Iron Gauntlets", item.baseName)
assert.are.equals(1, #item.explicitModLines)
assert.are.equals("+50% chance to Ignite", item.explicitModLines[1].line)
end)
it("Energy Blade", function()
local item = new("Item", [[
Item Class: One Hand Swords
Rarity: Magic
Superior Energy Blade
]])
assert.are.equal("Energy Blade One Handed", item.baseName)
item = new("Item", [[
Item Class: Two Hand Swords
Rarity: Magic
Superior Energy Blade
]])
assert.are.equal("Energy Blade Two Handed", item.baseName)
end)
it("Flask buff", function()
local item = new("Item", [[
Rarity: Magic
Chemist's Granite Flask of the Opossum
]])
assert.are.equal(1, #item.buffModLines)
assert.are.equal("+1500 to Armour", item.buffModLines[1].line)
end)
it("Catalyst quality from PoB internal format", function()
-- Fertile = index 3, Prismatic = index 7 in catalystList
local item = new("Item", raw("Catalyst: Fertile\nCatalystQuality: 20"))
assert.are.equals(3, item.catalyst)
assert.are.equals(20, item.catalystQuality)
item = new("Item", raw("Catalyst: Prismatic\nCatalystQuality: 12"))
assert.are.equals(7, item.catalyst)
assert.are.equals(12, item.catalystQuality)
end)
it("Catalyst quality from game clipboard format", function()
-- Game clipboard uses "Quality (X Modifiers)" header rather than "Catalyst:"
-- Life and Mana Modifiers -> Fertile = index 3
local item = new("Item", raw("Quality (Life and Mana Modifiers): +20% (augmented)"))
assert.are.equals(3, item.catalyst)
assert.are.equals(20, item.catalystQuality)
-- Resistance Modifiers -> Prismatic = index 7
item = new("Item", raw("Quality (Resistance Modifiers): +12% (augmented)"))
assert.are.equals(7, item.catalyst)
assert.are.equals(12, item.catalystQuality)
end)
it("PoB internal catalyst format takes precedence over clipboard format", function()
-- If both are present, the internal Catalyst: line wins (parsed first; clipboard guarded by 'not self.catalyst')
local item = new("Item", raw("Catalyst: Fertile\nCatalystQuality: 20\nQuality (Resistance Modifiers): +12% (augmented)"))
assert.are.equals(3, item.catalyst) -- Fertile, not Prismatic
assert.are.equals(20, item.catalystQuality)
end)
it("valueScalar annotation parsed from mod line", function()
local item = new("Item", raw("{valueScalar:1.2}+50 to maximum Life"))
assert.are.equals(1.2, item.explicitModLines[1].valueScalar)
end)
it("valueScalar annotation preserved through BuildRaw round-trip", function()
local item = new("Item", raw("{valueScalar:1.2}+50 to maximum Life"))
assert.are.equals(1.2, item.explicitModLines[1].valueScalar)
-- Serialised raw should contain the annotation
local rawStr = item:BuildRaw()
assert.truthy(rawStr:find("valueScalar:1.2", 1, true))
-- Re-parsing restores the value
local item2 = new("Item", rawStr)
assert.are.equals(1.2, item2.explicitModLines[1].valueScalar)
end)
it("valueScalar of exactly 1 is not written to BuildRaw", function()
-- Scalar = 1 is a no-op; writing it would create noise in saved items
local item = new("Item", raw("+50 to maximum Life"))
assert.is_nil(item.explicitModLines[1].valueScalar)
local rawStr = item:BuildRaw()
assert.falsy(rawStr:find("valueScalar", 1, true))
end)
end)