/*
 * MinimalEndSymbolTest.cpp
 *
 *  Created on: 21. 02. 2021
 *      Author: Martin Prokopic
 */

#include "catch2/catch.hpp"

#include <alphabet/MinimalEndSymbol.h>
#include <alphabet/xml/MinimalEndSymbol.h>
#include <alphabet/common/SymbolNormalize.h>
#include <factory/XmlDataFactory.hpp>

using alphabet::SymbolNormalize;
using factory::XmlDataFactory;
using alphabet::MinimalEndSymbol;

TEST_CASE ( "MinimalEndSymbol", "[unit][alphabet]" ) {

    SECTION ( "instance equality test" ) {
        REQUIRE ( MinimalEndSymbol ( ) == MinimalEndSymbol ( ));
        REQUIRE ( MinimalEndSymbol::instance < char > ( ) == MinimalEndSymbol::instance < char > ( ));
        REQUIRE (
                MinimalEndSymbol::instance < object::Object > ( ) == MinimalEndSymbol::instance < object::Object > ( ));
    }

    SECTION ( "normalization test" ) {
        REQUIRE ( SymbolNormalize::normalizeSymbol ( MinimalEndSymbol ( )) ==
                  MinimalEndSymbol::instance < object::Object > ( ));
    }

    SECTION ( "can be serialized and deserialized through xmlApi" ) {
        SECTION ( "with normalization" ) {
            std::string xml = XmlDataFactory::toString ( MinimalEndSymbol::instance < object::Object > ( ));
            INFO ( xml );
            object::Object deserialized = XmlDataFactory::fromString ( xml );

            REQUIRE( deserialized == MinimalEndSymbol::instance < object::Object > ( ));
        }

        SECTION ( "without normalization" ) {
            MinimalEndSymbol original;

            std::string xml = XmlDataFactory::toString ( original );
            INFO ( xml );
            MinimalEndSymbol deserialized = XmlDataFactory::fromString ( xml );

            REQUIRE ( deserialized == original );
        }
    }

}