From 777b7490470c9f1328abe8d0f83bedda8f02593d Mon Sep 17 00:00:00 2001 From: Claudius Holeksa Date: Thu, 15 Jun 2023 20:45:27 +0200 Subject: c++, codec-json: Added multi dimensional arrays to json --- tests/codec-json.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests') diff --git a/tests/codec-json.cpp b/tests/codec-json.cpp index 1b6c5d2..1c77f46 100644 --- a/tests/codec-json.cpp +++ b/tests/codec-json.cpp @@ -16,6 +16,10 @@ using TestArray = Array< String, 1 >; +using TestMultiArray = Array< + String, 3 +>; + using TestStruct = Struct< Member, Member @@ -104,6 +108,27 @@ SAW_TEST("Array write"){ SAW_EXPECT(enc_val == str_v, std::string{"Array not encoded correctly. Encoded: "} + enc_val + std::string{" Expected: "} + std::string{str_v}); } +SAW_TEST("Three Dim Array write"){ + using namespace saw; + data native{2,1,2}; + data json; + + native.at(0,0,0).set("multi"); + native.at(0,0,1).set("baz"); + native.at(1,0,0).set("foo"); + native.at(1,0,1).set("bar"); + + codec json_codec; + + error_or eov = json_codec.encode(native, json); + SAW_EXPECT(eov.is_value(), "Encoding error"); + + std::string_view str_v = "[[[\"multi\",\"baz\"]],[[\"foo\",\"bar\"]]]"; + std::string enc_val = convert_to_string(json.get_buffer()); + + SAW_EXPECT(enc_val == str_v, std::string{"Array not encoded correctly. Encoded: "} + enc_val + std::string{" Expected: "} + std::string{str_v}); +} + SAW_TEST("Struct write"){ using namespace saw; data native; -- cgit v1.2.3