diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2025-06-29 12:17:26 -0400 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2025-06-29 12:17:26 -0400 |
| commit | 7c8ce5f32feb970f1842e6859a8c74f6cb86cfe8 (patch) | |
| tree | 3755e89a93e87a2e1c712db7fb70109b005d34c7 | |
| parent | Fix malloc and memset usage (diff) | |
| download | cli-7c8ce5f32feb970f1842e6859a8c74f6cb86cfe8.zip | |
Add bats tests
| -rw-r--r-- | .gitmodules | 12 | ||||
| -rw-r--r-- | tests/justify.bats | 77 | ||||
| m--------- | tests/vendor/bats-assert | 0 | ||||
| m--------- | tests/vendor/bats-core | 0 | ||||
| m--------- | tests/vendor/bats-file | 0 | ||||
| m--------- | tests/vendor/bats-support | 0 |
6 files changed, 89 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ef84bfb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,12 @@ +[submodule "tests/vendor/bats-core"] + path = tests/vendor/bats-core + url = https://github.com/bats-core/bats-core.git +[submodule "tests/vendor/bats-assert"] + path = tests/vendor/bats-assert + url = https://github.com/bats-core/bats-assert.git +[submodule "tests/vendor/bats-file"] + path = tests/vendor/bats-file + url = https://github.com/bats-core/bats-file.git +[submodule "tests/vendor/bats-support"] + path = tests/vendor/bats-support + url = https://github.com/bats-core/bats-support.git diff --git a/tests/justify.bats b/tests/justify.bats new file mode 100644 index 0000000..6fac7ef --- /dev/null +++ b/tests/justify.bats @@ -0,0 +1,77 @@ +#!/usr/bin/env bats + +load 'vendor/bats-support/load' +load 'vendor/bats-assert/load' +load 'vendor/bats-file/load' + +JUSTIFY_BIN="./build/justify" + +@test "last line of the output is left aligned" { + run "${JUSTIFY_BIN}" <<EOF +This is a test of the emergency broadcast system. +EOF + assert_success + assert_output "This is a test of the emergency broadcast system." +} + +@test "lines are justified to both margins except last line" { + run "${JUSTIFY_BIN}" <<EOF +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt +EOF + assert_success + expected_output="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do +eiusmod tempor incididunt" + assert_output "$expected_output" +} + +@test "lines are justified to both margins except last line with custom line width" { + run "${JUSTIFY_BIN}" -w 60 <<EOF +This is a test of the emergency broadcast system. +EOF + assert_success + expected_output="This is a test of the emergency broadcast system." + assert_output "$expected_output" +} + +@test "extra spaces are distributed between words" { + run "${JUSTIFY_BIN}" -w 60 <<EOF +A B C D E F G H I J K L M N O P Q R S T U V W X Y Z +EOF + assert_success + expected_output="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z" + assert_output "$expected_output" +} + +@test "words are not split if they fit" { + run "${JUSTIFY_BIN}" -w 60 <<EOF +Hello world +EOF + assert_success + assert_output "Hello world" +} + +@test "word longer than buffer is wrapped" { + run "${JUSTIFY_BIN}" -w 60 <<EOF +123456789012345678901234567890123456789012345678901234567890EXTRA +EOF + assert_success + expected_output="123456789012345678901234567890123456789012345678901234567890 +EXTRA" + assert_output "$expected_output" +} + +@test "multiple spaces in input are collapsed when on last left-aligned line" { + run "${JUSTIFY_BIN}" <<EOF +This is spaced +EOF + assert_success + assert_output --partial "This is spaced" +} + +@test "empty input produces no output" { + run "${JUSTIFY_BIN}" <<EOF + +EOF + assert_success + assert_output "" +} diff --git a/tests/vendor/bats-assert b/tests/vendor/bats-assert new file mode 160000 +Subproject 912a98804efd34f24d5eae1bf97ee622ca770e9 diff --git a/tests/vendor/bats-core b/tests/vendor/bats-core new file mode 160000 +Subproject 855844b8344e67d60dc0f43fa39817ed7787f14 diff --git a/tests/vendor/bats-file b/tests/vendor/bats-file new file mode 160000 +Subproject 0f24d004706e7d3747c3d7d0f14a47f05a31748 diff --git a/tests/vendor/bats-support b/tests/vendor/bats-support new file mode 160000 +Subproject 0ad082d4590108684c68975ca517a90459f05cd |