diff --git a/bash/gilded_rose.sh b/bash/gilded_rose.sh index d1d32b34..cf4aef82 100755 --- a/bash/gilded_rose.sh +++ b/bash/gilded_rose.sh @@ -1,7 +1,7 @@ #!/bin/bash update_quality() { - local IFS=',' + local IFS='|' while read -r name sell_in_str quality_str; do declare -i sell_in="$sell_in_str" @@ -50,7 +50,7 @@ update_quality() { fi fi - echo "$name,$sell_in,$quality" + echo "$name|$sell_in|$quality" done } diff --git a/bash/texttest_fixture.sh b/bash/texttest_fixture.sh new file mode 100755 index 00000000..690c9833 --- /dev/null +++ b/bash/texttest_fixture.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +GILDED_ROSE_SCRIPT="./gilded_rose.sh" + +create_initial_items() { + local temp_file=$(mktemp) + + cat <"$temp_file" ++5 Dexterity Vest|10|20 +Aged Brie|2|0 +Elixir of the Mongoose|5|7 +Sulfuras, Hand of Ragnaros|0|80 +Sulfuras, Hand of Ragnaros|-1|80 +Backstage passes to a TAFKAL80ETC concert|15|20 +Backstage passes to a TAFKAL80ETC concert|10|49 +Backstage passes to a TAFKAL80ETC concert|5|49 +Conjured Mana Cake|3|6 +EOF + + echo "$temp_file" +} + +simulate_days() { + local days=$1 + local items_file=$2 + + for ((day = 0; day <= days; day++)); do + echo "-------- day $day --------" + echo "name, sellIn, quality" + + cat "$items_file" | sed 's/|/, /g' + + local temp_output=$(mktemp) + cat "$items_file" | bash "$GILDED_ROSE_SCRIPT" >"$temp_output" + mv "$temp_output" "$items_file" + + echo "" + done +} + +echo OMGHAI! + +ITEMS_FILE=$(create_initial_items) + +DAYS_TO_SIMULATE=${1:-2} + +simulate_days $DAYS_TO_SIMULATE $ITEMS_FILE + +rm "$ITEMS_FILE" diff --git a/bash/verify.sh b/bash/verify.sh new file mode 100755 index 00000000..561af69d --- /dev/null +++ b/bash/verify.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +./texttest_fixture.sh 30 | diff -u - ../texttests/ThirtyDays/stdout.gr