#include "gtest/gtest.h"
#include "jes/FileLoader.h"

using namespace jes;

TEST(FileLoaderTest, num_lines_defaults_to_0)
{
    FileLoader fr;
    EXPECT_EQ(0, fr.num_lines());
}

TEST(FileLoaderTest, load_returns_false_for_nonexistent_file)
{
    FileLoader fr;
    EXPECT_FALSE(fr.load("this/file/does/not/exist.txt"));
}

TEST(FileLoaderTest, loading_empty_file)
{
    FileLoader fr;
    EXPECT_TRUE(fr.load("test/files/empty.txt"));
    EXPECT_EQ(0, fr.num_lines());
}

TEST(FileLoaderTest, reads_lf_format_file)
{
    FileLoader fr;
    EXPECT_TRUE(fr.load("test/files/line_endings/unix_format.txt"));
    EXPECT_EQ(FileLoader::LINE_ENDING_LF, fr.get_line_endings());
    EXPECT_EQ(2, fr.num_lines());
    EXPECT_EQ("Hello.", fr.get_line(0)->to_s());
    EXPECT_EQ("This file is in UNIX line ending format.", fr.get_line(1)->to_s());
}

TEST(FileLoaderTest, reads_cr_format_file)
{
    FileLoader fr;
    EXPECT_TRUE(fr.load("test/files/line_endings/mac_format.txt"));
    EXPECT_EQ(FileLoader::LINE_ENDING_CR, fr.get_line_endings());
    EXPECT_EQ(2, fr.num_lines());
    EXPECT_EQ("Hello.", fr.get_line(0)->to_s());
    EXPECT_EQ("This file is in MAC line ending format.", fr.get_line(1)->to_s());
}

TEST(FileLoaderTest, reads_crlf_format_file)
{
    FileLoader fr;
    EXPECT_TRUE(fr.load("test/files/line_endings/dos_format.txt"));
    EXPECT_EQ(FileLoader::LINE_ENDING_CRLF, fr.get_line_endings());
    EXPECT_EQ(2, fr.num_lines());
    EXPECT_EQ("Hello.", fr.get_line(0)->to_s());
    EXPECT_EQ("This file is in DOS line ending format.", fr.get_line(1)->to_s());
}
