1###
2# Copyright (c) 2002-2004, Jeremiah Fincher
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are met:
7#
8#   * Redistributions of source code must retain the above copyright notice,
9#     this list of conditions, and the following disclaimer.
10#   * Redistributions in binary form must reproduce the above copyright notice,
11#     this list of conditions, and the following disclaimer in the
12#     documentation and/or other materials provided with the distribution.
13#   * Neither the name of the author of this software nor the name of
14#     contributors to this software may be used to endorse or promote products
15#     derived from this software without specific prior written consent.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
28###
29
30from supybot.test import *
31
32class FormatTestCase(PluginTestCase):
33    plugins = ('Format',)
34    def testBold(self):
35        self.assertResponse('bold foobar', '\x02foobar\x02')
36
37    def testUnderline(self):
38        self.assertResponse('underline foobar', '\x1ffoobar\x1f')
39
40    def testReverse(self):
41        self.assertResponse('reverse foobar', '\x16foobar\x16')
42
43
44    def testFormat(self):
45        self.assertResponse('format %s foo', 'foo')
46        self.assertResponse('format %s%s foo bar', 'foobar')
47        self.assertResponse('format "%sbaz%s" "foo bar" 1', 'foo barbaz1')
48        self.assertError('format %s foo bar')
49        self.assertError('format %s%s foo')
50
51    def testJoin(self):
52        self.assertResponse('join + foo bar baz', 'foo+bar+baz')
53        self.assertResponse('join "" foo bar baz', 'foobarbaz')
54
55    def testTranslate(self):
56        self.assertResponse('translate 123 456 1234567890', '4564567890')
57        self.assertError('translate 123 1234 123125151')
58
59    def testReplace(self):
60        self.assertResponse('replace # %23 bla#foo', 'bla%23foo')
61
62    def testUpper(self):
63        self.assertResponse('upper foo', 'FOO')
64        self.assertResponse('upper FOO', 'FOO')
65
66    def testLower(self):
67        self.assertResponse('lower foo', 'foo')
68        self.assertResponse('lower FOO', 'foo')
69
70    def testCapitalize(self):
71        self.assertResponse('capitalize foo', 'Foo')
72        self.assertResponse('capitalize foo bar', 'Foo bar')
73
74    def testTitle(self):
75        self.assertResponse('title foo', 'Foo')
76        self.assertResponse('title foo bar', 'Foo Bar')
77
78    def testRepr(self):
79        self.assertResponse('repr foo bar baz', '"foo bar baz"')
80
81    def testConcat(self):
82        self.assertResponse('concat foo bar baz', 'foobar baz')
83
84    def testCut(self):
85        self.assertResponse('cut 5 abcdefgh', 'abcde')
86        self.assertResponse('cut 5 abcd', 'abcd')
87        self.assertResponse('cut -1 abcde', 'abcd')
88
89    def testField(self):
90        self.assertResponse('field 2 foo bar baz', 'bar')
91        self.assertResponse('field -1 foo bar baz', 'baz')
92
93# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
94