#include "app_core/document_route.h"
#include "test_harness.h"

namespace {

void classifies_regular_project_path(pp::tests::Harness& harness)
{
    const auto route = pp::app::classify_document_open_path("D:\\Paint\\Scenes\\demo.ppi");

    PP_EXPECT(harness, route);
    PP_EXPECT(harness, route.value().kind == pp::app::DocumentOpenKind::open_project);
    PP_EXPECT(harness, route.value().path == "D:\\Paint\\Scenes\\demo.ppi");
    PP_EXPECT(harness, route.value().directory == "D:\\Paint\\Scenes");
    PP_EXPECT(harness, route.value().name == "demo");
    PP_EXPECT(harness, route.value().extension == "ppi");
}

void classifies_brush_imports_case_insensitively(pp::tests::Harness& harness)
{
    const auto abr_route = pp::app::classify_document_open_path("/brushes/Clouds.ABR");
    const auto ppbr_route = pp::app::classify_document_open_path("/brushes/palette.PpBr");

    PP_EXPECT(harness, abr_route);
    PP_EXPECT(harness, ppbr_route);
    PP_EXPECT(harness, abr_route.value().kind == pp::app::DocumentOpenKind::import_abr);
    PP_EXPECT(harness, abr_route.value().extension == "abr");
    PP_EXPECT(harness, ppbr_route.value().kind == pp::app::DocumentOpenKind::import_ppbr);
    PP_EXPECT(harness, ppbr_route.value().extension == "ppbr");
}

void preserves_names_with_inner_dots(pp::tests::Harness& harness)
{
    const auto route = pp::app::classify_document_open_path("C:/projects/shot.001.paint.ppi");

    PP_EXPECT(harness, route);
    PP_EXPECT(harness, route.value().directory == "C:/projects");
    PP_EXPECT(harness, route.value().name == "shot.001.paint");
    PP_EXPECT(harness, route.value().extension == "ppi");
}

void rejects_paths_that_legacy_regex_did_not_accept(pp::tests::Harness& harness)
{
    const auto no_directory = pp::app::classify_document_open_path("demo.ppi");
    const auto no_extension = pp::app::classify_document_open_path("D:/Paint/demo");
    const auto empty_file = pp::app::classify_document_open_path("D:/Paint/.ppi");
    const auto unsupported_extension_chars = pp::app::classify_document_open_path("D:/Paint/demo.ppi.tmp!");

    PP_EXPECT(harness, !no_directory);
    PP_EXPECT(harness, !no_extension);
    PP_EXPECT(harness, !empty_file);
    PP_EXPECT(harness, !unsupported_extension_chars);
}

}

int main()
{
    pp::tests::Harness harness;
    harness.run("classifies regular project path", classifies_regular_project_path);
    harness.run("classifies brush imports case insensitively", classifies_brush_imports_case_insensitively);
    harness.run("preserves names with inner dots", preserves_names_with_inner_dots);
    harness.run("rejects paths that legacy regex did not accept", rejects_paths_that_legacy_regex_did_not_accept);
    return harness.finish();
}
