~skiqqy/q

90aa40fa8df46d759a250c10a47975ad60a733c2 — Stephen Cochrane 2 months ago ddd2ed1 master
Bug fix
2 files changed, 24 insertions(+), 3 deletions(-)

M q
M test.sh
M q => q +23 -2
@@ 97,6 97,22 @@ qpeek()
# See: q help push
qpush()
{
	local tty
	tty=true
	OPTIND=1
	while getopts e opt
	do
		case "$opt" in
			e)
				tty=false
				;;
			*)
				return 1
				;;
		esac
	done
	shift "$((OPTIND-1))" # Get rid of optargs

	prio=${1:-$(tail -1 "$qdir/q" | cut -d"$delim" -f3)}
	[ -z "$prio" ] && prio=0
	if [[ ! "$prio" =~ ^[0-9]+$ ]] || [[ ! "$prio" -ge 0 ]] > /dev/null


@@ 106,8 122,13 @@ qpush()
	fi

	read -rp "Title: " title
	write_desc
	desc="$(tr_desc)"
	if "$tty"
	then
		read -rp "Desc: "  desc
	else
		write_desc
		desc="$(tr_desc)"
	fi

	if [ "$prio" = "$(tail -1 "$q" | cut -d"$delim" -f3)" ] # If max prio, simply put on top of stack.
	then

M test.sh => test.sh +1 -1
@@ 87,7 87,7 @@ assert <($q peek all) <(expect c 2 0 d; echo; expect e 1 0 f; echo; expect a 0 0
assert <($q pop  all) <(expect c 2 0 d; echo; expect e 1 0 f; echo; expect a 0 0 b)

assert <(put c d | $q push abcd) <(echo "Priority must be an int in [0,inf)")
assert <(put c d | $q push -1) <(echo "Priority must be an int in [0,inf)")
assert <(put c d | $q push \\-1) <(echo "Priority must be an int in [0,inf)")
assert <($q peek) <(printf '')
assert <($q pop) <(printf '')