Underscode

Check-in [f2cc8d82aa]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Changed unit tests to check for the new encoding.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f2cc8d82aa1a5bdd99916c020a6d73fe4abeec92
User & Date: ivan@selidor.net 2007-11-28 20:48:52
Context
2007-11-28
21:01
Forgot to update the test for valid strings. check-in: 7986bdcc47 user: ivan@selidor.net tags: trunk
20:48
Changed unit tests to check for the new encoding. check-in: f2cc8d82aa user: ivan@selidor.net tags: trunk
20:36
Updated all documentation to the new encoding. check-in: ce081413dd user: ivan@selidor.net tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to underscode/tests.py.

120
121
122
123
124
125
126
127

128

129
130
131
132
133
134
135
...
138
139
140
141
142
143
144

145
146
147
148
149
150
151
152
...
186
187
188
189
190
191
192
193
194

195
196
197
198
199
200
201
                self.assertRaises(
                    exception, underscode.underscode_decode, encoded )

    def test_valid_character(self):
        """Decoding and checking valid encoded characters."""

        valid_encodings = {
            u'_': ['___', '_x5f_', '_u005f_', '_U0000005f_'],

            u'0': ['_0_', '_x30_', '_u0030_', '_U00000030_'],

            u'\x1a': ['_x1a_', '_u001a_', '_U0000001a_'],
            u'\u12ab': ['_u12ab_', '_U000012ab_'],
            u'\U0001abcd': ['_U0001abcd_'], }

        for (decoded, encodings) in valid_encodings.items():
            for encoded in encodings:
                # Check ``is_underscode_encoded()``.
................................................................................
                udecoded = underscode.underscode_decode(encoded)
                self.assert_(type(udecoded) is unicode)
                self.assertEqual(udecoded, decoded)

    def test_invalid_character(self):
        """Decoding and checking invalid encoded characters."""


        valid_encoded = ['___', '_0_', '_x1a_', '_u12ab_', '_U0001abcd_']

        # All incomplete versions for each of the previous encoded
        # characters; from two input characters on, since ``_`` is a
        # valid encoded string with no encoded characters, and up to
        # the full encoded character bar the final underscore.
        incomplete_encoded = [
            [encchar[:i] for i in range(2, len(encchar))]
................................................................................
        # are not encoded in the same way at the beginning and in the
        # middle of a string.
        canonical_encoding = [
            # 0 characters.
            {u'': '_'},
            # 1 character.
            { u'a': 'a_',
              u'_': '___',
              u'0': '_0_',

              u'\x1a': '_x1a_',
              u'\u12ab': '_u12ab_',
              u'\U0001abcd': '_U0001abcd_', },
            # 2 characters.
            {u'a0': 'a0_'}, ]

        for nsteps in range(len(canonical_encoding)):







|
>

>







 







>
|







 







|

>







120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
                self.assertRaises(
                    exception, underscode.underscode_decode, encoded )

    def test_valid_character(self):
        """Decoding and checking valid encoded characters."""

        valid_encodings = {
            u'a': ['a_', '_x61_', '_u0061_', '_U00000061_'],
            u' ': ['___', '_x20_', '_u0020_', '_U00000020_'],
            u'0': ['_0_', '_x30_', '_u0030_', '_U00000030_'],
            u'_': ['_x5f_', '_u005f_', '_U0000005f_'],
            u'\x1a': ['_x1a_', '_u001a_', '_U0000001a_'],
            u'\u12ab': ['_u12ab_', '_U000012ab_'],
            u'\U0001abcd': ['_U0001abcd_'], }

        for (decoded, encodings) in valid_encodings.items():
            for encoded in encodings:
                # Check ``is_underscode_encoded()``.
................................................................................
                udecoded = underscode.underscode_decode(encoded)
                self.assert_(type(udecoded) is unicode)
                self.assertEqual(udecoded, decoded)

    def test_invalid_character(self):
        """Decoding and checking invalid encoded characters."""

        valid_encoded = [
            'a_', '___', '_0_', '_x5f_', '_x1a_', '_u12ab_', '_U0001abcd_' ]

        # All incomplete versions for each of the previous encoded
        # characters; from two input characters on, since ``_`` is a
        # valid encoded string with no encoded characters, and up to
        # the full encoded character bar the final underscore.
        incomplete_encoded = [
            [encchar[:i] for i in range(2, len(encchar))]
................................................................................
        # are not encoded in the same way at the beginning and in the
        # middle of a string.
        canonical_encoding = [
            # 0 characters.
            {u'': '_'},
            # 1 character.
            { u'a': 'a_',
              u' ': '___',
              u'0': '_0_',
              u'_': '_x5f_',
              u'\x1a': '_x1a_',
              u'\u12ab': '_u12ab_',
              u'\U0001abcd': '_U0001abcd_', },
            # 2 characters.
            {u'a0': 'a0_'}, ]

        for nsteps in range(len(canonical_encoding)):