a gleam implementation of a CS assignment originally written in cpp

feat: add appending tests

Changed files
+58
test
+58
test/test.sh
···
run_verse_test "First Samuel" "First Samuel" "1" "1" "1 Now there was a certain man of Ramathaim-zophim, of mount Ephraim, and his name [was] Elkanah, the son of Jeroham, the son of Elihu, the son of Tohu, the son of Zuph, an Ephrathite:" true
run_verse_test "Second Kings" "Second Kings" "1" "1" "1 Then Moab rebelled against Israel after the death of Ahab" true
+
# Appending Tests
+
print_section "Appending & File Path Tests"
+
+
# Function to run appending test
+
run_appending_test() {
+
local test_name="$1"
+
+
# Clean up previous test
+
rm -f "$output_file"
+
+
# First verse lookup
+
input1="Genesis\n1\n1"
+
output1=$(timeout "$test_timeout" bash -c "echo -e '$input1' | '$program' OT.txt '$output_file'" 2>&1)
+
exit_code1=$?
+
+
if [ $exit_code1 -ne 0 ]; then
+
print_result "$test_name - First Lookup" "FAIL" "First verse lookup failed"
+
return
+
fi
+
+
# Check first verse was written
+
if [ ! -f "$output_file" ]; then
+
print_result "$test_name - First File" "FAIL" "First verse file not created"
+
return
+
fi
+
+
first_content=$(cat "$output_file")
+
+
# Second verse lookup
+
input2="Genesis\n1\n2"
+
output2=$(timeout "$test_timeout" bash -c "echo -e '$input2' | '$program' OT.txt '$output_file'" 2>&1)
+
exit_code2=$?
+
+
if [ $exit_code2 -ne 0 ]; then
+
print_result "$test_name - Second Lookup" "FAIL" "Second verse lookup failed"
+
return
+
fi
+
+
# Check if file still exists and has content
+
if [ ! -f "$output_file" ]; then
+
print_result "$test_name - Second File" "FAIL" "File disappeared after second lookup"
+
return
+
fi
+
+
second_content=$(cat "$output_file")
+
+
# Check if both verses are in the file (appending behavior)
+
if [[ "$second_content" == *"1 In the beginning God created the heaven and the earth"* ]] && [[ "$second_content" == *"2 And the earth was without form, and void"* ]]; then
+
print_result "$test_name" "PASS" "Both verses found in file (appending works)"
+
elif [[ "$second_content" == *"2 And the earth was without form, and void"* ]] && [[ "$second_content" != *"1 In the beginning God created the heaven and the earth"* ]]; then
+
print_result "$test_name" "FAIL" "Only second verse found (overwriting instead of appending)"
+
else
+
print_result "$test_name" "FAIL" "Unexpected file content after second lookup"
+
fi
+
}
+
+
run_appending_test "Multiple Verse Appending"
+
# Function to run file path test
run_file_path_test() {
local test_name="$1"