#!/bin/bash
# Runs every command published on the page, plus one edge input each, and writes commands.log. Usage: bash commands-run.sh <dir with check-yt.py and in/>
cd "$1" || exit 2
python3 mkinputs.py
L=commands.log; : > $L
run() { # $1 published text, $2 command as run, $3 edge note
  echo "published: $1" >> $L; echo "run: $2" >> $L
  out=$(eval "$2" 2>&1); code=$?
  printf '%s\n' "$out" | sed 's/^/  /' >> $L; echo "exit=$code" >> $L
  [ -n "$3" ] && echo "edge: $3" >> $L; echo >> $L
}
run 'python3 check-yt.py titles.txt' 'python3 check-yt.py in/titles.txt' ''
run 'python3 check-yt.py titles.txt' 'printf "" > in/empty.txt; python3 check-yt.py in/empty.txt' 'an empty file: exit 2, nothing to check'
run 'python3 check-yt.py titles.txt' 'python3 check-yt.py in/missing.txt' 'a file that does not exist: exit 2 with a message'
run 'python3 check-yt.py --kind description description.txt' 'python3 check-yt.py --kind description in/desc_ok.txt' ''
run 'python3 check-yt.py --kind description description.txt' 'python3 check-yt.py --kind description in/desc_cyr.txt' '3000 Cyrillic letters: 3000 characters, 6000 bytes'
run 'python3 check-yt.py --kind description description.txt' 'python3 check-yt.py --kind description in/desc_5000.txt' 'exactly 5000 ASCII characters (boundary)'
run 'python3 check-yt.py --kind description description.txt' 'python3 check-yt.py --kind description in/desc_5001.txt' '5001 ASCII characters (one over)'
run 'python3 check-yt.py --csv sheet.csv --column Title' 'python3 check-yt.py --csv in/sheet.csv --column Title' 'a CSV saved by Excel with a UTF-8 BOM, a quoted comma and a line break inside a cell'
run 'python3 check-yt.py --csv sheet.csv --column Title' 'python3 check-yt.py --csv in/sheet.csv --column Headline' 'a column name that is not in the file: exit 2'
run 'python3 check-yt.py --csv sheet.csv --column Description --kind description' 'python3 check-yt.py --csv in/sheet.csv --column Description --kind description' 'description column of the same sheet'
run 'python3 check-yt.py titles.txt --keyword "zoom"' 'python3 check-yt.py in/titles.txt --keyword "zoom"' 'titles without the key word report none'
run 'python3 check-yt.py --kind description description.txt' 'printf "" > in/empty_desc.txt; python3 check-yt.py --kind description in/empty_desc.txt' 'an empty description file: exit 2, nothing to check'
run 'python3 check-yt.py titles.txt' 'printf "short title\r\n\r\n   \r\nsecond\r\n" > in/blank.txt; python3 check-yt.py in/blank.txt' 'CRLF file with a blank and a spaces-only line: both skipped, two items'
run 'python3 check-yt.py titles.txt --keyword "zoom"' 'printf "😀😀 zoom tips\n" > in/emoji_kw.txt; python3 check-yt.py in/emoji_kw.txt --keyword ZOOM' 'keyword after two emoji: position 4 in code points (6 in UTF-16 units)'
run 'python3 check-yt.py --kind description description.txt' 'python3 -c "print(\"é\"*2500)" > in/d_nl.txt; python3 check-yt.py --kind description in/d_nl.txt' '2500 two-byte letters plus the final newline most editors add: 5001 bytes, API-OVER'
run 'python3 check-yt.py --kind description description.txt' 'python3 -c "import sys; sys.stdout.write(\"é\"*2500)" > in/d_nonl.txt; python3 check-yt.py --kind description in/d_nonl.txt' 'the same 2500 letters saved without a final newline: 5000 bytes, OK'
run 'python3 check-yt.py titles.txt --keyword "zoom"' 'printf "İstanbul zoom\n" > in/tr_kw.txt; python3 check-yt.py in/tr_kw.txt --keyword zoom' 'a capital İ lower-cases to two code points, so the position is found on the original text: 10, not 11'
run 'python3 check-yt.py --kind description description.txt' 'python3 -c "import sys; sys.stdout.write(\"\U0001F600\"*2600)" > in/d_emo2600.txt; python3 check-yt.py --kind description in/d_emo2600.txt' '2600 emoji: 2600 code points, 5200 UTF-16 units, 10400 bytes: CHECK, and the line also names the byte overflow'
run 'python3 check-yt.py --kind description description.txt' 'python3 -c "import sys; sys.stdout.write(\"\U0001F600\"*1300)" > in/d_emo1300.txt; python3 check-yt.py --kind description in/d_emo1300.txt' '1300 emoji: 1300 code points, 2600 UTF-16 units, 5200 bytes: API-OVER'
