From 2617f5e022b8eaaaf9f051e0c1f249c276e3e9fc Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 27 May 2018 10:41:02 +1000 Subject: [PATCH] Add unit test for option parsing --- src/option_types.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/option_types.cc diff --git a/src/option_types.cc b/src/option_types.cc new file mode 100644 index 00000000..bd30d4f8 --- /dev/null +++ b/src/option_types.cc @@ -0,0 +1,24 @@ +#include "option_types.hh" +#include "unit_tests.hh" + +namespace Kakoune +{ + +UnitTest test_option_parsing{[]{ + auto check = [](auto&& value, StringView str) + { + auto repr = option_to_string(value); + kak_assert(repr == str); + std::decay_t parsed; + option_from_string(str, parsed); + kak_assert(parsed == value); + }; + + check(123, "123"); + check(true, "true"); + check(Vector{"foo", "bar:", "baz"}, "foo:bar\\::baz"); + check(HashMap{{"foo", 10}, {"b=r", 20}, {"b:z", 30}}, "foo=10:b\\=r=20:b\\:z=30"); + check(DebugFlags::Keys | DebugFlags::Hooks, "hooks|keys"); +}}; + +}