inf2ron 0.1.0

Parse Stranded II .inf definition files (items, objects, units, buildings, combinations) and output RON format
Documentation
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
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
// inf2ron – parse Stranded II .inf definition files to RON
// Copyright (C) 2025  inf2ron contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

//! Typed domain structures for .inf definitions with Serde support.
//!
//! Each type corresponds to a domain from the original game:
//! - `ItemDef` — items (items_*.inf)
//! - `ObjectDef` — world objects (objects_*.inf)
//! - `UnitDef` — AI units / creatures (units.inf)
//! - `BuildingDef` — placeable buildings (buildings.inf)
//! - `CombiDef` — crafting combinations (combinations*.inf)
//!
//! All types implement `Serialize` + `Deserialize` for RON output.
//! Conversion is best-effort: expected fields are extracted into typed
//! members; everything else goes into `raw_extra`.

use std::collections::HashMap;
use std::fmt;

use serde::{Deserialize, Serialize};

use crate::types::InfEntry;

// ── Error type ─────────────────────────────────────────────

/// Errors that can occur when converting an `InfEntry` to a typed definition.
#[derive(Debug, Clone)]
pub enum RegistryError {
    /// A required field is missing.
    MissingField(String),
    /// The entry is not a combination block.
    NotACombi,
}

impl fmt::Display for RegistryError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::MissingField(field) => write!(f, "missing required field '{field}'"),
            Self::NotACombi => write!(f, "entry is not a combination block"),
        }
    }
}

impl std::error::Error for RegistryError {}

// ── Helpers ────────────────────────────────────────────────

/// Extract a single-valued field.
fn get_one(fields: &HashMap<String, Vec<String>>, key: &str) -> Option<String> {
    fields.get(key).and_then(|v| v.first().cloned())
}

/// Extract a multi-valued field.
fn get_many(fields: &HashMap<String, Vec<String>>, key: &str) -> Vec<String> {
    fields.get(key).cloned().unwrap_or_default()
}

/// Extract script content.
fn get_script(entry: &InfEntry) -> Option<String> {
    entry.script.clone()
}

// ── Item ───────────────────────────────────────────────────

/// Typed item definition from `items_*.inf`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ItemDef {
    pub id: String,
    pub name: String,
    pub group: String,
    pub icon: String,
    pub model: String,
    pub scale: Option<String>,
    pub mat: Option<String>,
    pub weight: Option<String>,
    pub info: Option<String>,
    pub behaviour: Option<String>,
    pub damage: Option<String>,
    pub speed: Option<String>,
    pub drag: Option<String>,
    pub rate: Option<String>,
    pub color: Option<String>,
    pub shine: Option<String>,
    pub blend: Option<String>,
    pub healthchange: Option<String>,
    pub script: Option<String>,
    /// Any fields not explicitly listed above.
    #[serde(skip_serializing_if = "HashMap::is_empty")]
    pub raw_extra: HashMap<String, Vec<String>>,
}

impl TryFrom<&InfEntry> for ItemDef {
    type Error = RegistryError;

    fn try_from(entry: &InfEntry) -> Result<Self, Self::Error> {
        let id = get_one(&entry.fields, "id")
            .ok_or_else(|| RegistryError::MissingField("id".into()))?;
        let name = get_one(&entry.fields, "name")
            .ok_or_else(|| RegistryError::MissingField("name".into()))?;
        let group = get_one(&entry.fields, "group")
            .ok_or_else(|| RegistryError::MissingField("group".into()))?;
        let icon = get_one(&entry.fields, "icon")
            .ok_or_else(|| RegistryError::MissingField("icon".into()))?;
        let model = get_one(&entry.fields, "model")
            .ok_or_else(|| RegistryError::MissingField("model".into()))?;

        // Known item field keys (everything else → raw_extra)
        const KNOWN: &[&str] = &[
            "id", "name", "group", "icon", "model", "scale", "mat", "weight",
            "info", "behaviour", "damage", "speed", "drag", "rate",
            "color", "shine", "blend", "healthchange",
        ];

        let raw_extra = extract_extra(&entry.fields, KNOWN);

        Ok(ItemDef {
            id,
            name,
            group,
            icon,
            model,
            scale: get_one(&entry.fields, "scale"),
            mat: get_one(&entry.fields, "mat"),
            weight: get_one(&entry.fields, "weight"),
            info: get_one(&entry.fields, "info"),
            behaviour: get_one(&entry.fields, "behaviour"),
            damage: get_one(&entry.fields, "damage"),
            speed: get_one(&entry.fields, "speed"),
            drag: get_one(&entry.fields, "drag"),
            rate: get_one(&entry.fields, "rate"),
            color: get_one(&entry.fields, "color"),
            shine: get_one(&entry.fields, "shine"),
            blend: get_one(&entry.fields, "blend"),
            healthchange: get_one(&entry.fields, "healthchange"),
            script: get_script(entry),
            raw_extra,
        })
    }
}

// ── Object ─────────────────────────────────────────────────

/// Typed world-object definition from `objects_*.inf`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ObjectDef {
    pub id: String,
    pub name: String,
    pub group: String,
    pub icon: String,
    pub model: String,
    pub mat: Option<String>,
    pub scale: Option<String>,
    pub health: Option<String>,
    pub healthchange: Option<String>,
    pub behaviour: Option<String>,
    pub swayspeed: Option<String>,
    pub swaypower: Option<String>,
    pub fx: Option<String>,
    /// `find=` entries (multivalue: "id,prob" or "id,prob,min,skill,lvl")
    pub find: Vec<String>,
    pub script: Option<String>,
    /// Any fields not explicitly listed above.
    #[serde(skip_serializing_if = "HashMap::is_empty")]
    pub raw_extra: HashMap<String, Vec<String>>,
}

impl TryFrom<&InfEntry> for ObjectDef {
    type Error = RegistryError;

    fn try_from(entry: &InfEntry) -> Result<Self, Self::Error> {
        let id = get_one(&entry.fields, "id")
            .ok_or_else(|| RegistryError::MissingField("id".into()))?;
        let name = get_one(&entry.fields, "name")
            .ok_or_else(|| RegistryError::MissingField("name".into()))?;
        let group = get_one(&entry.fields, "group")
            .ok_or_else(|| RegistryError::MissingField("group".into()))?;
        let icon = get_one(&entry.fields, "icon")
            .ok_or_else(|| RegistryError::MissingField("icon".into()))?;
        let model = get_one(&entry.fields, "model")
            .ok_or_else(|| RegistryError::MissingField("model".into()))?;

        const KNOWN: &[&str] = &[
            "id", "name", "group", "icon", "model", "mat", "scale",
            "health", "healthchange", "behaviour", "swayspeed", "swaypower",
            "fx", "find",
        ];

        let raw_extra = extract_extra(&entry.fields, KNOWN);

        Ok(ObjectDef {
            id,
            name,
            group,
            icon,
            model,
            mat: get_one(&entry.fields, "mat"),
            scale: get_one(&entry.fields, "scale"),
            health: get_one(&entry.fields, "health"),
            healthchange: get_one(&entry.fields, "healthchange"),
            behaviour: get_one(&entry.fields, "behaviour"),
            swayspeed: get_one(&entry.fields, "swayspeed"),
            swaypower: get_one(&entry.fields, "swaypower"),
            fx: get_one(&entry.fields, "fx"),
            find: get_many(&entry.fields, "find"),
            script: get_script(entry),
            raw_extra,
        })
    }
}

// ── Unit ───────────────────────────────────────────────────

/// Typed unit/AI definition from `units.inf`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UnitDef {
    pub id: String,
    pub name: String,
    pub group: String,
    pub icon: String,
    pub model: String,
    pub scale: Option<String>,
    pub colxr: Option<String>,
    pub colyr: Option<String>,
    pub speed: Option<String>,
    pub eyes: Option<String>,
    pub store: Option<String>,
    pub health: Option<String>,
    pub damage: Option<String>,
    pub attackrange: Option<String>,
    pub maxweight: Option<String>,
    pub healthchange: Option<String>,
    pub behaviour: Option<String>,
    pub script: Option<String>,
    /// Any fields not explicitly listed above.
    #[serde(skip_serializing_if = "HashMap::is_empty")]
    pub raw_extra: HashMap<String, Vec<String>>,
}

impl TryFrom<&InfEntry> for UnitDef {
    type Error = RegistryError;

    fn try_from(entry: &InfEntry) -> Result<Self, Self::Error> {
        let id = get_one(&entry.fields, "id")
            .ok_or_else(|| RegistryError::MissingField("id".into()))?;
        let name = get_one(&entry.fields, "name")
            .ok_or_else(|| RegistryError::MissingField("name".into()))?;
        let group = get_one(&entry.fields, "group")
            .ok_or_else(|| RegistryError::MissingField("group".into()))?;
        let icon = get_one(&entry.fields, "icon")
            .ok_or_else(|| RegistryError::MissingField("icon".into()))?;
        let model = get_one(&entry.fields, "model")
            .ok_or_else(|| RegistryError::MissingField("model".into()))?;

        const KNOWN: &[&str] = &[
            "id", "name", "group", "icon", "model", "scale",
            "colxr", "colyr", "speed", "eyes", "store", "health",
            "damage", "attackrange", "maxweight", "healthchange", "behaviour",
        ];

        let raw_extra = extract_extra(&entry.fields, KNOWN);

        Ok(UnitDef {
            id,
            name,
            group,
            icon,
            model,
            scale: get_one(&entry.fields, "scale"),
            colxr: get_one(&entry.fields, "colxr"),
            colyr: get_one(&entry.fields, "colyr"),
            speed: get_one(&entry.fields, "speed"),
            eyes: get_one(&entry.fields, "eyes"),
            store: get_one(&entry.fields, "store"),
            health: get_one(&entry.fields, "health"),
            damage: get_one(&entry.fields, "damage"),
            attackrange: get_one(&entry.fields, "attackrange"),
            maxweight: get_one(&entry.fields, "maxweight"),
            healthchange: get_one(&entry.fields, "healthchange"),
            behaviour: get_one(&entry.fields, "behaviour"),
            script: get_script(entry),
            raw_extra,
        })
    }
}

// ── Building ───────────────────────────────────────────────

/// Typed building definition from `buildings.inf`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BuildingDef {
    pub id: String,
    pub group: String,
    pub objectid: Option<String>,
    /// Required materials: `req=itemid,count` (multivalue)
    pub req: Vec<String>,
    pub buildspace: Option<String>,
    /// Objects this building requires proximity to
    pub atobject: Vec<String>,
    pub script: Option<String>,
    /// Any fields not explicitly listed above.
    #[serde(skip_serializing_if = "HashMap::is_empty")]
    pub raw_extra: HashMap<String, Vec<String>>,
}

impl TryFrom<&InfEntry> for BuildingDef {
    type Error = RegistryError;

    fn try_from(entry: &InfEntry) -> Result<Self, Self::Error> {
        let id = get_one(&entry.fields, "id")
            .ok_or_else(|| RegistryError::MissingField("id".into()))?;
        let group = get_one(&entry.fields, "group")
            .ok_or_else(|| RegistryError::MissingField("group".into()))?;

        const KNOWN: &[&str] = &[
            "id", "group", "objectid", "req", "buildspace", "atobject",
        ];

        let raw_extra = extract_extra(&entry.fields, KNOWN);

        Ok(BuildingDef {
            id,
            group,
            objectid: get_one(&entry.fields, "objectid"),
            req: get_many(&entry.fields, "req"),
            buildspace: get_one(&entry.fields, "buildspace"),
            atobject: get_many(&entry.fields, "atobject"),
            script: get_script(entry),
            raw_extra,
        })
    }
}

// ── Combination ────────────────────────────────────────────

/// Typed crafting combination from `combinations*.inf`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CombiDef {
    /// String identifier (e.g. "bendablebranch", "makefire")
    pub id: String,
    /// Required items: `req=itemid` or `req=itemid,count,stay`
    pub req: Vec<String>,
    /// Generated items: `gen=itemid` (optional count)
    pub r#gen: Vec<String>,
    /// Display name for the action (e.g. "make fire")
    pub genname: Option<String>,
    pub script: Option<String>,
    /// Any fields not explicitly listed above.
    #[serde(skip_serializing_if = "HashMap::is_empty")]
    pub raw_extra: HashMap<String, Vec<String>>,
}

impl TryFrom<&InfEntry> for CombiDef {
    type Error = RegistryError;

    fn try_from(entry: &InfEntry) -> Result<Self, Self::Error> {
        let combi = entry
            .combi
            .as_ref()
            .ok_or(RegistryError::NotACombi)?;

        let id = get_one(&combi.fields, "id")
            .ok_or_else(|| RegistryError::MissingField("id".into()))?;

        const KNOWN: &[&str] = &["id", "req", "gen", "genname"];

        let raw_extra = extract_extra(&combi.fields, KNOWN);

        Ok(CombiDef {
            id,
            req: get_many(&combi.fields, "req"),
            r#gen: get_many(&combi.fields, "gen"),
            genname: get_one(&combi.fields, "genname"),
            script: combi.script.clone(),
            raw_extra,
        })
    }
}

// ── Helpers ────────────────────────────────────────────────

/// Build a `HashMap` of key→values for fields NOT in `known`.
fn extract_extra(
    fields: &HashMap<String, Vec<String>>,
    known: &[&str],
) -> HashMap<String, Vec<String>> {
    let mut extra = HashMap::new();
    for (k, v) in fields {
        if !known.contains(&k.as_str()) {
            extra.insert(k.clone(), v.clone());
        }
    }
    extra
}

/// Classify an .inf filename into its domain type.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum InfDomain {
    Items,
    Objects,
    Units,
    Buildings,
    Combinations,
    Infos,
    Random,
    States,
    Groups,
    Game,
    Strings,
    Keys,
    Lightcycle,
    Credits,
    SkillInfo,
    Unknown(String),
}

impl fmt::Display for InfDomain {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Items => write!(f, "items"),
            Self::Objects => write!(f, "objects"),
            Self::Units => write!(f, "units"),
            Self::Buildings => write!(f, "buildings"),
            Self::Combinations => write!(f, "combinations"),
            Self::Infos => write!(f, "infos"),
            Self::Random => write!(f, "random"),
            Self::States => write!(f, "states"),
            Self::Groups => write!(f, "groups"),
            Self::Game => write!(f, "game"),
            Self::Strings => write!(f, "strings"),
            Self::Keys => write!(f, "keys"),
            Self::Lightcycle => write!(f, "lightcycle"),
            Self::Credits => write!(f, "credits"),
            Self::SkillInfo => write!(f, "skillinfo"),
            Self::Unknown(name) => write!(f, "unknown({name})"),
        }
    }
}

/// Classify an `.inf` filename into a domain.
pub fn classify_inf(filename: &str) -> InfDomain {
    let name = filename.rsplit('/').next().unwrap_or(filename);
    let name = name.rsplit('\\').next().unwrap_or(name);
    let lower = name.to_lowercase();

    if lower.starts_with("items_") || lower == "items.inf" {
        InfDomain::Items
    } else if lower.starts_with("objects_") || lower == "objects.inf" {
        InfDomain::Objects
    } else if lower == "units.inf" {
        InfDomain::Units
    } else if lower == "buildings.inf" {
        InfDomain::Buildings
    } else if lower.starts_with("combinations") {
        InfDomain::Combinations
    } else if lower == "infos.inf" {
        InfDomain::Infos
    } else if lower.starts_with("random_") {
        InfDomain::Random
    } else if lower == "states.inf" {
        InfDomain::States
    } else if lower == "groups.inf" {
        InfDomain::Groups
    } else if lower == "game.inf" {
        InfDomain::Game
    } else if lower == "strings.inf" {
        InfDomain::Strings
    } else if lower == "keys.inf" {
        InfDomain::Keys
    } else if lower == "lightcycle.inf" {
        InfDomain::Lightcycle
    } else if lower == "credits.inf" {
        InfDomain::Credits
    } else if lower.ends_with(".inf") && lower.contains("skillinfo") {
        InfDomain::SkillInfo
    } else {
        InfDomain::Unknown(name.to_string())
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::parser::InfParser;

    #[test]
    fn test_convert_item() {
        let input = r#"### Meat
id=9
name=Meat
group=food
icon=gfx\meat.bmp
model=gfx\meat.b3d
scale=0.15
mat=flesh
weight=500"#;
        let entries = InfParser::parse_str(input).unwrap();
        assert_eq!(entries.len(), 1);
        let item = ItemDef::try_from(&entries[0]).unwrap();
        assert_eq!(item.id, "9");
        assert_eq!(item.name, "Meat");
        assert_eq!(item.group, "food");
        assert_eq!(item.scale, Some("0.15".into()));
        assert_eq!(item.mat, Some("flesh".into()));
        assert_eq!(item.weight, Some("500".into()));
        assert!(item.raw_extra.is_empty());
    }

    #[test]
    fn test_convert_item_with_script() {
        let input = r#"### Meat
id=9
name=Meat
group=food
icon=gfx\meat.bmp
model=gfx\meat.b3d
script=start
    on:eat {
        eat 5,20,10,0;
    }
script=end"#;
        let entries = InfParser::parse_str(input).unwrap();
        let item = ItemDef::try_from(&entries[0]).unwrap();
        assert_eq!(item.id, "9");
        assert!(item.script.as_ref().unwrap().contains("on:eat"));
    }

    #[test]
    fn test_convert_object() {
        let input = r#"### Tree
id=10
name=Tree
group=tree
icon=gfx\tree01.bmp
model=gfx\tree01.b3d
mat=wood
health=600
find=15,20,3
behaviour=tree"#;
        let entries = InfParser::parse_str(input).unwrap();
        let obj = ObjectDef::try_from(&entries[0]).unwrap();
        assert_eq!(obj.id, "10");
        assert_eq!(obj.find, vec!["15,20,3"]);
        assert_eq!(obj.behaviour, Some("tree".into()));
    }

    #[test]
    fn test_convert_unit() {
        let input = r#"### Player
id=1
name=Player
group=human
icon=gfx\strandedguy.bmp
model=gfx\strandedguy.b3d
speed=1.6
health=100
damage=3"#;
        let entries = InfParser::parse_str(input).unwrap();
        let unit = UnitDef::try_from(&entries[0]).unwrap();
        assert_eq!(unit.id, "1");
        assert_eq!(unit.speed, Some("1.6".into()));
        assert_eq!(unit.health, Some("100".into()));
    }

    #[test]
    fn test_convert_building() {
        let input = r#"### Tent
id=1
group=building
objectid=184
req=97"#;
        let entries = InfParser::parse_str(input).unwrap();
        let bld = BuildingDef::try_from(&entries[0]).unwrap();
        assert_eq!(bld.id, "1");
        assert_eq!(bld.objectid, Some("184".into()));
        assert_eq!(bld.req, vec!["97"]);
    }

    #[test]
    fn test_convert_combi() {
        let input = r#"### Make fire
combi=start
id=makefire
req=107
req=24
gen=107
gen=24
genname=make fire
combi=end"#;
        let entries = InfParser::parse_str(input).unwrap();
        assert_eq!(entries.len(), 1);
        let combi = CombiDef::try_from(&entries[0]).unwrap();
        assert_eq!(combi.id, "makefire");
        assert_eq!(combi.req, vec!["107", "24"]);
        assert_eq!(combi.r#gen, vec!["107", "24"]);
        assert_eq!(combi.genname, Some("make fire".into()));
    }

    #[test]
    fn test_classify_items() {
        assert_eq!(classify_inf("items_edible.inf"), InfDomain::Items);
        assert_eq!(classify_inf("items.inf"), InfDomain::Items);
        assert_eq!(classify_inf("items_weapons.inf"), InfDomain::Items);
    }

    #[test]
    fn test_classify_objects() {
        assert_eq!(classify_inf("objects_trees.inf"), InfDomain::Objects);
        assert_eq!(classify_inf("objects.inf"), InfDomain::Objects);
    }

    #[test]
    fn test_classify_combinations() {
        assert_eq!(
            classify_inf("combinations_basic.inf"),
            InfDomain::Combinations
        );
        assert_eq!(classify_inf("combinations.inf"), InfDomain::Combinations);
    }

    #[test]
    fn test_classify_other() {
        assert_eq!(classify_inf("units.inf"), InfDomain::Units);
        assert_eq!(classify_inf("buildings.inf"), InfDomain::Buildings);
        assert_eq!(classify_inf("infos.inf"), InfDomain::Infos);
        assert_eq!(classify_inf("states.inf"), InfDomain::States);
        assert_eq!(classify_inf("groups.inf"), InfDomain::Groups);
        assert_eq!(classify_inf("random_01_endless_e.inf"), InfDomain::Random);
        assert_eq!(classify_inf("random_05_raptors.inf"), InfDomain::Random);
    }

    #[test]
    fn test_classify_unknown() {
        assert_eq!(
            classify_inf("game.inf"),
            InfDomain::Game
        );
        assert_eq!(
            classify_inf("strings.inf"),
            InfDomain::Strings
        );
        assert_eq!(
            classify_inf("keys.inf"),
            InfDomain::Keys
        );
        assert_eq!(
            classify_inf("lightcycle.inf"),
            InfDomain::Lightcycle
        );
        assert_eq!(
            classify_inf("credits.inf"),
            InfDomain::Credits
        );
        assert_eq!(
            classify_inf("settings.cfg"),
            InfDomain::Unknown("settings.cfg".into())
        );
    }

    #[test]
    fn test_convert_item_unknown_field_in_raw_extra() {
        let input = r#"### Custom item
id=999
name=Custom
group=misc
icon=gfx\custom.bmp
model=gfx\custom.b3d
mycustomfield=hello"#;
        let entries = InfParser::parse_str(input).unwrap();
        let item = ItemDef::try_from(&entries[0]).unwrap();
        assert_eq!(item.raw_extra.get("mycustomfield").unwrap()[0], "hello");
    }
}