#!/bin/bash
cd $(dirname "$0")

source util.sh
PATH=".." source irc.sh

# irc_ctcpmsg defaults to a CTCP reply.
output=$(IRC_BOTID=shazbot irc_ctcpmsg "#channel" VERB noun)
assert_equal "$output" $'NOTICE #channel :\001VERB noun\001'

# irc_ctcpmsg can be asked to send a CTCP request instead.
output=$(IRC_BOTID=shazbot irc_ctcpmsg -m "#channel" VERB noun)
assert_equal "$output" $'PRIVMSG #channel :\001VERB noun\001'

# irc_ctcpmsg doesn't require a payload.
output=$(IRC_BOTID=shazbot irc_ctcpmsg "#channel" VERB)
assert_equal "$output" $'NOTICE #channel :\001VERB \001'

# irc_ctcpmsg truncates long payloads.
longmsg=$(make_big_payload "1234567 ")
output=$(IRC_BOTID=shazbot irc_ctcpmsg "#channel" VERB "$longmsg")
assert_equal ${#output} 495
assert_equal "$(echo "$output" | wc -l)" "1"

# irc_ctcpmsg escapes ^A in the payload.
output=$(IRC_BOTID=shazbot irc_ctcpmsg "#channel" VERB $'hello\001world')
assert_equal "$output" $'NOTICE #channel :\001VERB hello\\aworld\001'

# irc_ctcpmsg escapes \ in the payload.
output=$(IRC_BOTID=shazbot irc_ctcpmsg "#channel" VERB $'hello\\world')
assert_equal "$output" $'NOTICE #channel :\001VERB hello\\\\world\001'
