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

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

# ^P0 should be unquoted to \0 but there's no way to store that in an
# environment variable, so let's not even bother testing.

# Items without any quoted characters ar left unmolested.
IRC_PARAMS=(hello)
irc_dequote
assert_equal "${IRC_PARAMS[*]}" "hello"

# We keep separate parameters separate.
IRC_PARAMS=(hello world)
irc_dequote
assert_equal "${#IRC_PARAMS[@]}" "2"
assert_equal "${IRC_PARAMS[0]}" "hello"
assert_equal "${IRC_PARAMS[1]}" "world"

# ^Pn is unquoted to \n
IRC_PARAMS=($'hello\020nworld')
irc_dequote
assert_equal "${IRC_PARAMS[*]}" $'hello\nworld'

# ^Pr is unquoted to \r
IRC_PARAMS=($'hello\020rworld')
irc_dequote
assert_equal "${IRC_PARAMS[*]}" $'hello\rworld'

# ^P^P is unquoted to ^P
IRC_PARAMS=($'hello\020\020world')
irc_dequote
assert_equal "${IRC_PARAMS[*]}" $'hello\020world'

# Any other character is dequoted to itself.
IRC_PARAMS=($'hello \020pretty world')
irc_dequote
assert_equal "${IRC_PARAMS[*]}" $'hello pretty world'

# Although this text contains ^Pn, there should be no \n in the output.
IRC_PARAMS=($'hello\020\020new world')
irc_dequote
assert_equal "${IRC_PARAMS[*]}" $'hello\020new world'
