TEST(LineReader, MultiLineFile) {
  SystemMock sys;
  static const char kFile[] =
      "This is a multi\n"
      "line text file that to test the crazy::LineReader class implementation\n"
      "And this is a very long text line to check that the class properly "
      "handles them, through the help of dynamic allocation or something. "
      "Yadda yadda yadda yadda. No newline";
  static const size_t kFileSize = sizeof(kFile) - 1;
  sys.AddRegularFile(kFilePath, kFile, kFileSize);

  LineReader reader(kFilePath);

  EXPECT_TRUE(reader.GetNextLine());
  EXPECT_MEMEQ("This is a multi\n", 16, reader.line(), reader.length());

  EXPECT_TRUE(reader.GetNextLine());
  EXPECT_MEMEQ(
      "line text file that to test the crazy::LineReader class "
      "implementation\n",
      88 - 17,
      reader.line(),
      reader.length());

  EXPECT_TRUE(reader.GetNextLine());
  EXPECT_MEMEQ(
      "And this is a very long text line to check that the class properly "
      "handles them, through the help of dynamic allocation or something. "
      "Yadda yadda yadda yadda. No newline\n",
      187 - 17,
      reader.line(),
      reader.length());

  EXPECT_FALSE(reader.GetNextLine());
}
TEST(LineReader, EmptyFile) {
  SystemMock sys;
  sys.AddRegularFile(kFilePath, "", 0);

  LineReader reader(kFilePath);
  EXPECT_FALSE(reader.GetNextLine());
}
TEST(LineReader, SingleLineFile) {
  SystemMock sys;
  static const char kFile[] = "foo bar\n";
  static const size_t kFileSize = sizeof(kFile) - 1;
  sys.AddRegularFile(kFilePath, kFile, kFileSize);

  LineReader reader(kFilePath);
  EXPECT_TRUE(reader.GetNextLine());
  EXPECT_EQ(kFileSize, reader.length());
  EXPECT_MEMEQ(kFile, kFileSize, reader.line(), reader.length());
  EXPECT_FALSE(reader.GetNextLine());
}
TEST(LineReader, SingleLineFileUnterminated) {
  SystemMock sys;
  static const char kFile[] = "foo bar";
  static const size_t kFileSize = sizeof(kFile) - 1;
  sys.AddRegularFile(kFilePath, kFile, kFileSize);

  LineReader reader(kFilePath);
  EXPECT_TRUE(reader.GetNextLine());
  // The LineReader will add a newline to the last line.
  EXPECT_EQ(kFileSize + 1, reader.length());
  EXPECT_MEMEQ(kFile, kFileSize, reader.line(), reader.length() - 1);
  EXPECT_EQ('\n', reader.line()[reader.length() - 1]);
  EXPECT_FALSE(reader.GetNextLine());
}
TEST(System, SingleFile) {
  static const char kPath[] = "/tmp/foo/bar";

  static const char kString[] = "Hello World";
  const size_t kStringLen = sizeof(kString) - 1;

  SystemMock sys;
  sys.AddRegularFile(kPath, kString, kStringLen);

  char buff2[kStringLen + 10];
  FileDescriptor fd(kPath);

  EXPECT_EQ(kStringLen, fd.Read(buff2, sizeof(buff2)));
  buff2[kStringLen] = '\0';
  EXPECT_STREQ(kString, buff2);
}
TEST(System, PathExists) {
  SystemMock sys;
  sys.AddRegularFile("/tmp/foo", "FOO", 3);

  EXPECT_TRUE(PathExists("/tmp/foo"));
}