From f0d9d5e53f23392a7855be74f5d0e7f662aefc29 Mon Sep 17 00:00:00 2001 From: Peter Saxton Date: Wed, 1 Jan 2025 15:47:17 +0100 Subject: [PATCH] cast inline table as a table --- CHANGELOG.md | 4 ++++ src/tom.gleam | 1 + test/tom_test.gleam | 3 +++ 3 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2181a67..a10e108 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## next + +- Fixed bug where `InlineTable` could not be cast `as_table`. + ## v1.1.0 - 2024-09-23 - Added the `as_array`, `as_bool`, `as_date`, `as_date_time`, `as_float`, diff --git a/src/tom.gleam b/src/tom.gleam index 3aa6008..9cc7694 100644 --- a/src/tom.gleam +++ b/src/tom.gleam @@ -1505,6 +1505,7 @@ pub fn as_array(toml: Toml) -> Result(List(Toml), GetError) { pub fn as_table(toml: Toml) -> Result(Dict(String, Toml), GetError) { case toml { Table(tbl) -> Ok(tbl) + InlineTable(tbl) -> Ok(tbl) other -> Error(WrongType([], "Table", classify(other))) } } diff --git a/test/tom_test.gleam b/test/tom_test.gleam index 8fc0799..cbda588 100644 --- a/test/tom_test.gleam +++ b/test/tom_test.gleam @@ -1038,6 +1038,9 @@ pub fn tom_as_table_test() { tom.as_table(tom.Table(dict)) |> should.equal(Ok(dict)) + tom.as_table(tom.InlineTable(dict)) + |> should.equal(Ok(dict)) + tom.as_table(tom.Int(1)) |> should.equal(Error(tom.WrongType([], "Table", "Int"))) }