add support for deserializing a map with int keys as a sequence

This commit is contained in:
Robin Appelman 2025-06-05 20:42:13 +02:00
commit b928f85df6
14 changed files with 226 additions and 9 deletions

6
tests/data/maparray.vdf Normal file
View file

@ -0,0 +1,6 @@
"MapArray"
{
"0" "foo"
"1" "bar"
"2" "asd"
}

View file

@ -0,0 +1,6 @@
"MapArray"
{
"0" "foo"
"1" "bar"
"3" "asd"
}

View file

@ -69,6 +69,7 @@ enum Expected {
EnumInMap {
foo: EnumInMap,
},
MapArray(Vec<String>),
}
#[derive(Debug, Serialize, Deserialize)]
@ -211,6 +212,8 @@ struct GameList {
#[test_case("tests/errors/concrete.vmt")]
#[test_case("tests/errors/novalue.vdf")]
#[test_case("tests/errors/serde_array_type.vdf")]
#[test_case("tests/data/maparray.vdf")]
#[test_case("tests/errors/invalidmaparraykeys.vdf")]
fn test_serde(path: &str) {
let raw = read_to_string(path).unwrap();
match from_str::<Expected>(&raw) {
@ -228,6 +231,7 @@ fn test_serde(path: &str) {
#[test_case("tests/data/concrete.vmt")]
#[test_case("tests/data/DialogConfigOverlay_1280x720.vdf")]
#[test_case("tests/data/serde_array_type.vdf")]
#[test_case("tests/data/maparray.vdf")]
fn test_serde_table(path: &str) {
let raw = read_to_string(path).unwrap();
match from_str::<Table>(&raw) {
@ -247,6 +251,7 @@ fn test_serde_table(path: &str) {
#[test_case("tests/data/messy.vdf")]
#[test_case("tests/data/DialogConfigOverlay_1280x720.vdf")]
#[test_case("tests/data/serde_array_type.vdf")]
#[test_case("tests/data/maparray.vdf")]
fn test_serde_from_table(path: &str) {
let raw = read_to_string(path).unwrap();
let result = Table::load_from_str(&raw).unwrap();

View file

@ -0,0 +1,11 @@
---
source: tests/serde.rs
expression: result
---
{
"MapArray": {
"0": "foo",
"1": "bar",
"2": "asd",
},
}

View file

@ -0,0 +1,9 @@
---
source: tests/serde.rs
expression: material
---
MapArray([
"foo",
"bar",
"asd",
])

View file

@ -0,0 +1,9 @@
---
source: tests/serde.rs
expression: result
---
MapArray([
"foo",
"bar",
"asd",
])

View file

@ -0,0 +1,14 @@
---
source: tests/serde.rs
expression: out
---
vmt_reader::unexpected_token
× Invalid array key 3, expected 2
╭─[5:3]
4 │ "1" "bar"
5 │ "3" "asd"
· ─┬─
· ╰── Invalid array key 3, expected 2
6 │ }
╰────

View file

@ -4,11 +4,10 @@ expression: out
---
vmt_parser::unknown_variant
× Unknown variant "Resource" expected on of expected on of Types, LightmappedGeneric, Resource/specificPanel.res, UserConfigData, Sprite, EnumInMap
× Unknown variant "Resource" expected on of expected on of Types, LightmappedGeneric, Resource/specificPanel.res, UserConfigData, Sprite, EnumInMap, MapArray
╭─[1:1]
1 │ "Resource"
· ─────┬────
· ╰── expected on of Types, LightmappedGeneric, Resource/specificPanel.res, UserConfigData, Sprite, EnumInMap
· ╰── expected on of Types, LightmappedGeneric, Resource/specificPanel.res, UserConfigData, Sprite, EnumInMap, MapArray
2 │ {
╰────