# Path: gears/environment.py
# class Suffixes(list):
#     """The registry for asset suffixes. It acts like a list of dictionaries.
#     Every dictionary has three keys: ``extensions``, ``result_mimetype`` and
#     ``mimetype``:
# 
#     - ``suffix`` is a suffix as a list of extensions (e.g. ``['.js', '.coffee']``);
#     - ``result_mimetype`` is a MIME type of a compiled asset with this suffix;
#     - ``mimetype`` is a MIME type, for which this suffix is registered.
#     """
# 
#     def register(self, extension, root=False, to=None, mimetype=None):
#         if root:
#             self.append({
#                 'suffix': [extension],
#                 'full': [extension],
#                 'result_mimetype': mimetype,
#                 'mimetype': mimetype,
#             })
#             return
#         new = []
#         for item in self:
#             if to is not None and item['mimetype'] != to:
#                 continue
#             suffix = list(item['suffix'])
#             suffix.append(extension)
#             full = list(item['full'])
#             full.append(extension)
#             new.append({
#                 'suffix': suffix,
#                 'full': full,
#                 'result_mimetype': item['result_mimetype'],
#                 'mimetype': mimetype,
#             })
#             if to is not None:
#                 new.append({
#                     'suffix': [extension],
#                     'full': full,
#                     'result_mimetype': item['result_mimetype'],
#                     'mimetype': mimetype,
#                 })
#         self.extend(new)
# 
#     def unregister(self, extension):
#         for item in list(self):
#             if extension in item['full']:
#                 self.remove(item)
# 
#     def find(self, mimetype=None):
#         suffixes = []
#         for item in self:
#             if mimetype is None or item['result_mimetype'] == mimetype:
#                 suffixes.append(''.join(item['suffix']))
#         return suffixes


from gears.environment import Suffixes
from unittest2 import TestCase


class SuffixesTests(TestCase):

    def setUp(self):
        self.suffixes = Suffixes()
        self.suffixes.register('.css', root=True, mimetype='text/css')
        self.suffixes.register('.txt', root=True, mimetype='text/plain')

    def test_register_root_suffix(self):
        self.assertItemsEqual(self.suffixes, [{
            'suffix': ['.css'],
            'full': ['.css'],
            'result_mimetype': 'text/css',
            'mimetype': 'text/css',
        }, {
            'suffix': ['.txt'],
            'full': ['.txt'],
            'result_mimetype': 'text/plain',
            'mimetype': 'text/plain',
        }])

    def test_register_extension_to_mimetype(self):
        self.suffixes.register('.styl', to='text/css')
        self.assertItemsEqual(self.suffixes, [{
            'suffix': ['.css'],

# Path: gears/environment.py
# class Suffixes(list):
#     """The registry for asset suffixes. It acts like a list of dictionaries.
#     Every dictionary has three keys: ``extensions``, ``result_mimetype`` and
#     ``mimetype``:
# 
#     - ``suffix`` is a suffix as a list of extensions (e.g. ``['.js', '.coffee']``);
#     - ``result_mimetype`` is a MIME type of a compiled asset with this suffix;
#     - ``mimetype`` is a MIME type, for which this suffix is registered.
#     """
# 
#     def register(self, extension, root=False, to=None, mimetype=None):
#         if root:
#             self.append({
#                 'suffix': [extension],
#                 'full': [extension],
#                 'result_mimetype': mimetype,
#                 'mimetype': mimetype,
#             })
#             return
#         new = []
#         for item in self:
#             if to is not None and item['mimetype'] != to:
#                 continue
#             suffix = list(item['suffix'])
#             suffix.append(extension)
#             full = list(item['full'])
#             full.append(extension)
#             new.append({
#                 'suffix': suffix,
#                 'full': full,
#                 'result_mimetype': item['result_mimetype'],
#                 'mimetype': mimetype,
#             })
#             if to is not None:
#                 new.append({
#                     'suffix': [extension],
#                     'full': full,
#                     'result_mimetype': item['result_mimetype'],
#                     'mimetype': mimetype,
#                 })
#         self.extend(new)
# 
#     def unregister(self, extension):
#         for item in list(self):
#             if extension in item['full']:
#                 self.remove(item)
# 
#     def find(self, mimetype=None):
#         suffixes = []
#         for item in self:
#             if mimetype is None or item['result_mimetype'] == mimetype:
#                 suffixes.append(''.join(item['suffix']))
#         return suffixes


# Path: tests/test_environment_suffixes.py
from gears.environment import Suffixes
from unittest2 import TestCase



class SuffixesTests(TestCase):

    def setUp(self):
        self.suffixes = Suffixes()
        self.suffixes.register('.css', root=True, mimetype='text/css')
        self.suffixes.register('.txt', root=True, mimetype='text/plain')

    def test_register_root_suffix(self):
        self.assertItemsEqual(self.suffixes, [{
            'suffix': ['.css'],
            'full': ['.css'],
            'result_mimetype': 'text/css',
            'mimetype': 'text/css',
        }, {
            'suffix': ['.txt'],
            'full': ['.txt'],
            'result_mimetype': 'text/plain',
            'mimetype': 'text/plain',
        }])

    def test_register_extension_to_mimetype(self):
        self.suffixes.register('.styl', to='text/css')
        self.assertItemsEqual(self.suffixes, [{
            'suffix': ['.css'],

            'full': ['.css'],