Debian Codegraph @

nih/nih_test.go

raw
1 /*
2 Copyright 2013-2014 Canonical Ltd.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published
6 by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranties of
10 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 package nih
18
19 import (
20 "testing"
21
22 . "gopkg.in/check.v1"
23 )
24
25 func TestNIH(t *testing.T) { TestingT(t) }
26
27 type nihSuite struct{}
28
29 var _ = Suite(&nihSuite{})
30
31 func (ns *nihSuite) TestQuote(c *C) {
32 for i, s := range []struct {
33 raw []byte
34 quoted []byte
35 }{
36 {[]byte("test"), []byte("test")},
37 {[]byte("foo/bar.baz"), []byte("foo_2fbar_2ebaz")},
38 {[]byte("test_thing"), []byte("test_5fthing")},
39 {[]byte("\x01\x0f\x10\xff"), []byte("_01_0f_10_ff")},
40 {[]byte{}, []byte{'_'}},
41 } {
42 c.Check(string(s.quoted), Equals, string(Quote(s.raw)), Commentf("iter %d (%s)", i, string(s.quoted)))
43 c.Check(string(Quote(s.raw)), DeepEquals, string(s.quoted), Commentf("iter %d (%s)", i, string(s.quoted)))
44 c.Check(Unquote(s.quoted), DeepEquals, s.raw, Commentf("iter %d (%s)", i, string(s.quoted)))
45 c.Check(string(Quote(s.raw)), Equals, string(Quote(s.raw)), Commentf("iter %d (%s)", i, string(s.quoted)))
46 }
47
48 // check one nih doesn't like
49 c.Check(Quote([]byte{0}), DeepEquals, []byte("_00"))
50
51 // check we don't panic with some weird ones
52 for i, s := range []string{"foo_", "foo_a", "foo_zz"} {
53 c.Check(Unquote([]byte(s)), DeepEquals, []byte("foo"), Commentf("iter %d (%s)", i, s))
54 }
55 }