#include <stic.h>
#include <stdlib.h> /* free() */
#include "../../src/background.h"
#include "../../src/utils/string_array.h"
TEST(non_existing_file)
{
int nlines = -1;
char **lines = read_file_of_lines(TEST_DATA_PATH "/read/wrong-path", &nlines);
assert_null(lines);
assert_int_equal(-1, nlines);
free(lines);
}
TEST(empty_file)
{
int nlines = -1;
char **lines =
read_file_of_lines(TEST_DATA_PATH "/existing-files/a", &nlines);
assert_non_null(lines);
assert_int_equal(0, nlines);
free(lines);
}
TEST(dos_line_endings)
{
int nlines;
char **lines = read_file_of_lines(TEST_DATA_PATH "/read/dos-line-endings",
&nlines);
if(lines == NULL)
{
assert_fail("Failed to read file lines");
return;
}
assert_int_equal(3, nlines);
assert_string_equal("first line", lines[0]);
assert_string_equal("second line", lines[1]);
assert_string_equal("third line", lines[2]);
free_string_array(lines, nlines);
}
TEST(dos_end_of_file)
{
int nlines;
char **lines = read_file_of_lines(TEST_DATA_PATH "/read/dos-eof", &nlines);
if(lines == NULL)
{
assert_fail("Failed to read file lines");
return;
}
assert_int_equal(3, nlines);
assert_string_equal("next line contains EOF", lines[0]);
assert_string_equal("\x1a", lines[1]);
assert_string_equal("this is \"invisible\" line", lines[2]);
free_string_array(lines, nlines);
}
TEST(binary_data_is_fully_read)
{
int nlines;
char **lines = read_file_of_lines(TEST_DATA_PATH "/read/binary-data",
&nlines);
assert_true(lines != NULL);
assert_int_equal(12, nlines);
free_string_array(lines, nlines);
}
TEST(bom_is_skipped)
{
int nlines;
char **lines = read_file_of_lines(TEST_DATA_PATH "/read/utf8-bom", &nlines);
assert_true(lines != NULL);
assert_int_equal(2, nlines);
free_string_array(lines, nlines);
}
TEST(bom_is_skipped_for_file)
{
FILE *fp = fopen(TEST_DATA_PATH "/read/utf8-bom", "rb");
int nlines;
char **lines = read_file_lines(fp, &nlines);
assert_true(lines != NULL);
assert_int_equal(2, nlines);
free_string_array(lines, nlines);
fclose(fp);
}
TEST(bom_is_skipped_for_stream)
{
FILE *fp = fopen(TEST_DATA_PATH "/read/utf8-bom", "rb");
int nlines;
char **lines = read_stream_lines(fp, &nlines, 0, NULL, NULL);
assert_true(lines != NULL);
assert_int_equal(2, nlines);
free_string_array(lines, nlines);
fclose(fp);
}
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 filetype=c : */
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master