#include #include #include "../c++/schema.hpp" #include "../c++/schema_hash.hpp" #include "../c++/schema_factory.hpp" namespace { template struct schema_hash_test { static_assert(saw::always_false, "Needs the test pair"); }; template struct schema_test_pair{}; template struct schema_hash_test> { static void check(){ using namespace saw; constexpr uint64_t hash = schema_hash::apply(); SAW_EXPECT( hash == expected, std::string{"Hash for "} + std::string{T::name.view()} + " is " + std::to_string(hash) +", but should be "+ std::to_string(expected) + "."); } }; template struct schema_hash_test_multi { template static void check_ele(){ using type = typename saw::parameter_pack_type::type; schema_hash_test::check(); if constexpr ( (i+1) < sizeof...(T)){ check_ele(); } } static void check(){ if constexpr (sizeof...(T) > 0){ check_ele<0>(); } } }; namespace schema { using namespace saw::schema; using HashIface = Interface< Member, UInt32>, "foo"> >; } SAW_TEST("Schema Hashes"){ using namespace saw; schema_hash_test_multi< schema_test_pair, schema_test_pair, schema_test_pair, schema_test_pair, schema_test_pair, schema_test_pair, schema_test_pair, schema_test_pair, schema_test_pair, schema_test_pair, schema_test_pair, schema_test_pair, schema_test_pair, schema_test_pair, schema_test_pair >::check(); } SAW_TEST("Schema Factory Compiles"){ using namespace saw; auto factory = build_schema>(); auto str = factory .add() .add() .add_maybe() .add_maybe() ; using FactorySchema = decltype(str)::Schema; using Schema = schema::Struct< schema::Member, schema::Member, schema::Member >; SAW_EXPECT(is_struct::value, "Expected a struct"); schema_hash_test_multi< schema_test_pair, schema_test_pair >::check(); } template auto ensure_types_one(saw::schema_factory builder){ return builder .template add_maybe, "foo">() .template add_maybe() ; } template auto ensure_types_two(saw::schema_factory builder){ return builder .template add_maybe, "foo">() .template add_maybe() ; } SAW_TEST("Schema Factory Multimethod"){ using namespace saw; auto builder = build_schema>(); /** * This would basically be multiple components */ auto b2 = ensure_types_one(builder); auto b3 = ensure_types_two(b2); using Schema = schema::Struct< schema::Member, "foo">, schema::Member, schema::Member >; schema_hash_test_multi< schema_test_pair, schema_test_pair >::check(); } }