Skip to content

Commit

Permalink
a real fix to the newline start issue (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
eeroel authored Jan 18, 2024
1 parent 62a9a8b commit ebac56f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
10 changes: 0 additions & 10 deletions hae.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ std::string read_all()
std::stringstream ss;
std::string s;

// ignore leading newlines
while (std::getline(std::cin, s) && s.empty()) {
if (!s.empty()) {
ss << s << '\n';
}
}

while (std::getline(std::cin, s)) {
ss << s << '\n';
}
Expand Down Expand Up @@ -392,9 +385,6 @@ int main(int argc, char *argv[])
std::stringstream ss(input);
std::string line;
while (std::getline(ss, line)) {
if (line == "") {
break;
}
auto d = std::shared_ptr<rapidjson::Document>(new rapidjson::Document());
d->Parse(line.c_str());
if (d->IsNull()) {
Expand Down
3 changes: 3 additions & 0 deletions test/data/empty_start.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

Foo | bar baz
1.
11 changes: 7 additions & 4 deletions test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ function error_hook() {
trap error_hook ERR

$HAE_PATH/hae "a detailed description of food" < data/meta.txt -n 3 -hl > res_t1.txt
diff t1.txt res_t1.txt
cmp t1.txt res_t1.txt

cat data/meta.json | jq -c .[] | $HAE_PATH/hae "the time" -n 1 > res_t2.txt
diff t2.txt res_t2.txt
cmp t2.txt res_t2.txt

cat data/newline_at_start.txt | $HAE_PATH/hae "foo" > res_t3.txt
diff t3.txt res_t3.txt
cmp t3.txt res_t3.txt

cat data/single_line.txt | $HAE_PATH/hae "foo" > res_t4.txt
diff t4.txt res_t4.txt
cmp t4.txt res_t4.txt

cat data/empty_start.txt | $HAE_PATH/hae "foo" > res_t5.txt
cmp t5.txt res_t5.txt
3 changes: 2 additions & 1 deletion test/t3.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
This is a test

This is a test


3 changes: 3 additions & 0 deletions test/t4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is a test


5 changes: 5 additions & 0 deletions test/t5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

Foo | bar baz
1. 


0 comments on commit ebac56f

Please sign in to comment.