Sha256: 69af3a7e532e471f49e2580bdc66ca8b7e159390f5d7a19b071415856697d1c6

Contents?: true

Size: 1.55 KB

Versions: 16

Compression:

Stored size: 1.55 KB

Contents

// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/json/

#include "test.hpp"

#include <tao/json.hpp>
#include <tao/json/contrib/get.hpp>

namespace tao::json
{
   void unit_test()
   {
      const value v = from_string( "{ \"a\": 1, \"b\": { \"ba\": 2, \"bb\": [ 3, 4, [], {}, { \"bb4a\": true } ] } }" );
      TEST_ASSERT( get::value( v, "a" ).is_value_ptr() );
      TEST_ASSERT( get::value( v, "a" ).skip_value_ptr().is_integer() );
      TEST_ASSERT( get::value( v, "a" ).skip_value_ptr().as< int >() == 1 );

      TEST_ASSERT( get::as< int >( get::value( v, "a" ) ) == 1 );
      TEST_ASSERT( !get::value( v, "zz" ) );
      TEST_THROWS( get::as< int >( get::value( v, "zz" ) ) );

      TEST_ASSERT( get::as< int >( v, "a" ) == 1 );
      TEST_THROWS( get::as< int >( v, "zz" ) );

      TEST_ASSERT( *get::optional< int >( v, "a" ) == 1 );
      TEST_ASSERT( !get::optional< int >( v, "zz" ) );
      TEST_ASSERT( !get::optional< int >( get::value( v, "zz" ) ) );

      TEST_ASSERT( get::defaulted( 2, v, "a" ) == 1 );
      TEST_ASSERT( get::defaulted( 2, v, "zz" ) == 2 );
      TEST_ASSERT( get::defaulted( 2, get::value( v, "zz" ) ) == 2 );

      TEST_ASSERT( get::as< bool >( v, "b", "bb", 4, "bb4a" ) == true );
      TEST_ASSERT( *get::optional< bool >( v, "b", "bb", 4, "bb4a" ) == true );
      TEST_ASSERT( get::defaulted( false, v, "b", "bb", 4, "bb4a" ) == true );

      TEST_ASSERT( !get::value( get::value( v, "zz" ), "zz" ) );
   }

}  // namespace tao::json

#include "main.hpp"

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
couchbase-3.0.0.alpha.4-x86_64-linux ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.4-x86_64-darwin-19 ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.4-universal-darwin-19 ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.4 ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.3-x86_64-linux ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.3-x86_64-darwin-19 ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.3-universal-darwin-19 ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.3 ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.2-x86_64-linux ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.2-x86_64-darwin-19 ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.2-universal-darwin-19 ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.2 ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.1-x86_64-linux ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.1-x86_64-darwin-19 ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.1-universal-darwin-19 ext/third_party/json/src/test/json/contrib_get.cpp
couchbase-3.0.0.alpha.1 ext/third_party/json/src/test/json/contrib_get.cpp