Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make 001 accept multiple lines and empty lines #7

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 2 additions & 0 deletions exercises/001-two-fer/empty-lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


3 changes: 3 additions & 0 deletions exercises/001-two-fer/one-name-and-empty-lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

Pierre

File renamed without changes.
39 changes: 37 additions & 2 deletions exercises/001-two-fer/tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ setup() {
}

@test "empty file given" {
run awk -f $AWK_FILE $TEST_FOLDER/empty.txt
run awk -f $AWK_FILE $TEST_FOLDER/empty-file.txt

assert_success
assert_output "One for you, one for me."
}

@test "a name given" {
run awk -f $AWK_FILE $TEST_FOLDER/one.txt
run awk -f $AWK_FILE $TEST_FOLDER/one-name.txt

assert_success
assert_output "One for Alice, one for me."
Expand All @@ -37,3 +37,38 @@ setup() {
assert_success
assert_output "One for Mary Ann, one for me."
}

@test "empty lines" {
run awk -f $AWK_FILE $TEST_FOLDER/empty-lines.txt

assert_success
assert_line --index 0 "One for you, one for me."
assert_line --index 1 "One for you, one for me."
}

@test "name with empty lines" {
run awk -f $AWK_FILE $TEST_FOLDER/one-name-and-empty-lines.txt

assert_success
assert_line --index 0 "One for you, one for me."
assert_line --index 1 "One for Pierre, one for me."
assert_line --index 2 "One for you, one for me."
}

@test "two names" {
run awk -f $AWK_FILE $TEST_FOLDER/two-names.txt

assert_success
assert_line --index 0 "One for Alice, one for me."
assert_line --index 1 "One for Mary Ann, one for me."
}

@test "two names and empty lines" {
run awk -f $AWK_FILE $TEST_FOLDER/two-names-and-empty-lines.txt

assert_success
assert_line --index 0 "One for you, one for me."
assert_line --index 1 "One for Alice, one for me."
assert_line --index 2 "One for you, one for me."
assert_line --index 3 "One for Mary Ann, one for me."
}
9 changes: 5 additions & 4 deletions exercises/001-two-fer/two-fer.awk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
END {
name = length($0) ? $0 : "you";
print "One for " name ", one for me."
}
# NF = Number of Fields in current record
# NR = Number of the current Record

{ print "One for " (NF ? $0 : "you") ", one for me." }
END { if (!NR) print "One for you, one for me." }
4 changes: 4 additions & 0 deletions exercises/001-two-fer/two-names-and-empty-lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

Alice

Mary Ann
2 changes: 2 additions & 0 deletions exercises/001-two-fer/two-names.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Alice
Mary Ann
Loading