<commit_before>#include <coffee/core/CUnitTesting>
#include <coffee/core/CFiles>

using namespace Coffee;
using namespace CResources;

const constexpr sbyte_t probe_text[25] = "I'M THE TRASHMAN! Hello.";

bool resource_exist_test()
{
    {
        Resource rsc("the-one-that-works",
                     ResourceAccess::SpecifyStorage|ResourceAccess::AssetFile);
        /* Tests limitations in implementation for names */
        if(!FileExists(rsc))
            return false;
    }

    {
        Resource rsc("filled-dir/subdir/we-need-to-go-deeper/odd-file-with-long-extension.txt.zip.exe",
                     ResourceAccess::SpecifyStorage|ResourceAccess::AssetFile);
        /* Tests limitations in implementation for names */
        if(!FileExists(rsc))
            return false;
    }

    {
        Resource rsc("filled-dir/subdir/we-need-to-go-deeper/Spaced filename.txt",
                     ResourceAccess::SpecifyStorage|ResourceAccess::AssetFile);
        /* Tests errors in scripts regarding spaces */
        if(!FileExists(rsc))
            return false;
    }

    return true;
}

bool resource_exists_odd_characters_test()
{
    Resource rsc("Oddball: æøå, カケ",
                 ResourceAccess::SpecifyStorage|ResourceAccess::AssetFile);
    /* Tests what happens to unexpected characters. We want these to work. */
    /* If existence passes, we assume the rest works too for these cases. */
    return FileExists(rsc);
}

bool resource_read_test()
{
    Resource rsc("Oddball: æøå, カケ",
                 ResourceAccess::SpecifyStorage
                 |ResourceAccess::AssetFile
                 |ResourceAccess::ReadOnly);

    if(!FilePull(rsc))
        return false;

    if(sizeof(probe_text)-1 != rsc.size || !MemCmp(rsc.data,probe_text,rsc.size))
    {
        cDebug("Sizes: {0} ?= {1}",sizeof(probe_text),rsc.size);
        cDebug("Data:\n"
               "Internal: {0}\n"
               "Resource: {1}\n",
               StrUtil::hexdump(probe_text,sizeof(probe_text)),
               StrUtil::hexdump(rsc.data,rsc.size));
        return false;
    }

    FileFree(rsc);

    return true;
}

bool resource_map_test()
{
    return true;
}

bool resource_write_test()
{

    return true;
}

const constexpr CoffeeTest::Test _tests[10] = {
    {resource_exist_test,
     "Resource existence",<commit_msg> - Implement test for mappable and writable resources<commit_after>#include <coffee/core/CUnitTesting>
#include <coffee/core/CFiles>

using namespace Coffee;
using namespace CResources;

const constexpr sbyte_t probe_text[25] = "I'M THE TRASHMAN! Hello.";

bool resource_exist_test()
{
    {
        Resource rsc("the-one-that-works",
                     ResourceAccess::SpecifyStorage|ResourceAccess::AssetFile);
        /* Tests limitations in implementation for names */
        if(!FileExists(rsc))
            return false;
    }

    {
        Resource rsc("filled-dir/subdir/we-need-to-go-deeper/odd-file-with-long-extension.txt.zip.exe",
                     ResourceAccess::SpecifyStorage|ResourceAccess::AssetFile);
        /* Tests limitations in implementation for names */
        if(!FileExists(rsc))
            return false;
    }

    {
        Resource rsc("filled-dir/subdir/we-need-to-go-deeper/Spaced filename.txt",
                     ResourceAccess::SpecifyStorage|ResourceAccess::AssetFile);
        /* Tests errors in scripts regarding spaces */
        if(!FileExists(rsc))
            return false;
    }

    return true;
}

bool resource_exists_odd_characters_test()
{
    Resource rsc("Oddball: æøå, カケ",
                 ResourceAccess::SpecifyStorage|ResourceAccess::AssetFile);
    /* Tests what happens to unexpected characters. We want these to work. */
    /* If existence passes, we assume the rest works too for these cases. */
    return FileExists(rsc);
}

bool resource_read_test()
{
    Resource rsc("Oddball: æøå, カケ",
                 ResourceAccess::SpecifyStorage
                 |ResourceAccess::AssetFile);

    if(!FilePull(rsc))
        return false;

    if(sizeof(probe_text)-1 != rsc.size || !MemCmp(rsc.data,probe_text,rsc.size))
    {
        cDebug("Sizes: {0} ?= {1}",sizeof(probe_text),rsc.size);
        cDebug("Data:\n"
               "Internal: {0}\n"
               "Resource: {1}\n",
               StrUtil::hexdump(probe_text,sizeof(probe_text)),
               StrUtil::hexdump(rsc.data,rsc.size));
        return false;
    }

    FileFree(rsc);

    return true;
}

bool resource_map_test()
{
    Resource rsc("Oddball: æøå, カケ",
                 ResourceAccess::SpecifyStorage
                 |ResourceAccess::AssetFile);

    if(!FileMap(rsc,ResourceAccess::ReadOnly))
        return false;

    if(!FileUnmap(rsc))
        return false;

    return true;
}

bool resource_write_test()
{
    Resource rsc("Oddball: æøå, カケ",
                 ResourceAccess::SpecifyStorage
                 |ResourceAccess::AssetFile);

    if(!FileMap(rsc,ResourceAccess::ReadWrite))
        return false;

    if(!FileUnmap(rsc))
        return false;

    return true;
}

const constexpr CoffeeTest::Test _tests[10] = {
    {resource_exist_test,
     "Resource existence",
{'fraction_non_alphanumeric': 0.1188310431585059, 'fraction_numerical': 0.0034836462163731373, 'mean_word_length': 2.5276450511945394, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '923773', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1535, 'n_words': 301}