diff --git a/CHANGELOG.md b/CHANGELOG.md index fca3e66..23a705d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,14 +8,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.4.1](https://github.com/LebJe/toml.lua/releases/tag/0.4.1) - 2024-11-19 ### Fixed -- The formatting options that were passed as a parameter to `toml.encode`, `toml.encodeToFile`, `toml.toJSON`, and `toml.toYAML` previously had no effect when overriding values. -- Resolved CMake `FetchContent_Populate` warning. + +- The formatting options that were passed as a parameter to `toml.encode`, `toml.encodeToFile`, `toml.toJSON`, and `toml.toYAML` previously had no effect when overriding values. +- Resolved CMake `FetchContent_Populate` warning. ### Changed + - Updated to magic_enum v0.9.7. ### Added -- Added tests for encoding options. + +- Added tests for encoding options. ## [0.4.0](https://github.com/LebJe/toml.lua/releases/tag/0.4.0) - 2024-01-02 diff --git a/src/utilities/utilities.cpp b/src/utilities/utilities.cpp index 8eeede0..27a3137 100644 --- a/src/utilities/utilities.cpp +++ b/src/utilities/utilities.cpp @@ -106,26 +106,27 @@ toml::format_flags tableToFormatFlags(sol::optional t) { // User passed an empty table to clear all flags. if (table.empty()) return flags; - + // Set default flags, and allow user to override std::map userFlags = defaultFlags; - + for (auto [flag, enabled] : userFlags) { std::string camelCaseFlagName = camelCase(magic_enum::enum_name(flag)); if (table[camelCaseFlagName].valid()) { userFlags[flag] = table[camelCaseFlagName].get(); } } - - // `format_flags::indentation` is returned as an empty string from `magic_enum::enum_name`, so we must handle it separately. + + // `format_flags::indentation` is returned as an empty string from `magic_enum::enum_name`, so + // we must handle it separately. if (table["indentation"].valid()) { userFlags[toml::format_flags::indentation] = table["indentation"].get(); } - + for (auto [flag, enabled] : userFlags) { if (enabled) flags |= flag; } - + return flags; } diff --git a/src/utilities/utilities.hpp b/src/utilities/utilities.hpp index 83c1664..578e008 100644 --- a/src/utilities/utilities.hpp +++ b/src/utilities/utilities.hpp @@ -36,8 +36,9 @@ std::string parseErrorToString(toml::parse_error e); /// Inserts the values in `e` into `table`. void parseErrorToTable(toml::parse_error e, sol::table & table); -/// Takes a Lua table, with keys representing flag names, and values, and converts it to `toml::format_flags`. -/// If the table is nil, all format flags are set to their default value, if the table is empty, `toml::format_flags` is set to none. +/// Takes a Lua table, with keys representing flag names, and values, and converts it to +/// `toml::format_flags`. If the table is nil, all format flags are set to their default value, if +/// the table is empty, `toml::format_flags` is set to none. toml::format_flags tableToFormatFlags(sol::optional t); Options tableToOptions(sol::optional t); @@ -56,9 +57,8 @@ std::optional keyToString(sol::object key); /// If a string is not on the stack, then an integer from `luaL_argerror` is returned. std::variant getTableFromStringInState(sol::state_view state, int index = 1); -template <> -struct magic_enum::customize::enum_range { - static constexpr bool is_flags = true; +template <> struct magic_enum::customize::enum_range { + static constexpr bool is_flags = true; }; #endif /* UTILITIES_H */ diff --git a/tests/tests.lua b/tests/tests.lua index 62f43c0..d1cccda 100644 --- a/tests/tests.lua +++ b/tests/tests.lua @@ -32,12 +32,14 @@ end function TestEncoder:testEncodingOptions() local terseKeysToml = read("tests/test-data/encoding/terseKeys+qoutedTimestamps.toml") - lu.assertEquals(toml.encode(toml.decode(terseKeysToml), { terseKeyValuePairs = true, quoteDatesAndTimes = true }), terseKeysToml) + lu.assertEquals( + toml.encode(toml.decode(terseKeysToml), { terseKeyValuePairs = true, quoteDatesAndTimes = true }), + terseKeysToml + ) local noIndentationJSON = read("tests/test-data/encoding/noIndentation.json") lu.assertEquals(toml.toJSON(toml.decode(terseKeysToml), { indentation = false }), noIndentationJSON) - end function TestDecoder:testDecodeSamples()