#include "test.h"
#include "namespace.h"

static int
test_namespace()
{
    LSUP_NSMap *nsm = LSUP_nsmap_new();
    ASSERT (nsm != NULL, "Error creating namespace map!");

    EXPECT_PASS (
            LSUP_nsmap_add (nsm, "dc", "http://purl.org/dc/elements/1.1/"));
    EXPECT_PASS (LSUP_nsmap_add (nsm, "dcterms", "http://purl.org/dc/terms/"));

    EXPECT_STR_EQ (
            LSUP_nsmap_get (nsm, "dc"), "http://purl.org/dc/elements/1.1/");
    EXPECT_STR_EQ (
            LSUP_nsmap_get (nsm, "dcterms"), "http://purl.org/dc/terms/");
    // Prefixes longer than 7 chars are truncated.
    ASSERT (
            LSUP_nsmap_get (nsm, "dctermsxxx") == NULL,
            "Non-existent NS found!");
    ASSERT (LSUP_nsmap_get (nsm, "none") == NULL, "Non-existent NS found!");

    EXPECT_PASS (LSUP_nsmap_remove (nsm, "dc"));
    ASSERT (
            LSUP_nsmap_remove (nsm, "none") == LSUP_NOACTION,
            "Wrong result for removal of non-existent prefix!");
    ASSERT (LSUP_nsmap_get (nsm, "dc") == NULL, "Deleted NS found!");

    LSUP_nsmap_free (nsm);

    return 0;
}

int namespace_tests()
{
    RUN (test_namespace);
    return 0;
}