# Path: gears/directives_parser.py
# class DirectivesParser(object):
# 
#     header_re = re.compile(r"""
#         ^( \s* (
#             ( /\* .*? \*/ ) |  # multiline comment
#             ( // [^\n]* )+ |   # slash comment
#             ( \# [^\n]* )+     # dash comment
#         ) )+
#     """, re.S | re.X)
# 
#     directive_re = re.compile(r"""
#         ^ \s* (?:\*|//|\#) \s* = \s* ( \w+ [=*?\[\]./'"\s\w-]* ) $
#     """, re.X)
# 
#     def split_source(self, source):
#         header_match = self.header_re.match(source)
#         if not header_match:
#             return '', source
#         header = header_match.group(0)
#         source = source[len(header):]
#         return header, source
# 
#     def split_header(self, header):
#         directives = []
#         header_lines = []
#         for line in header.splitlines():
#             directive_match = self.directive_re.match(line)
#             if directive_match:
#                 directives.append(directive_match.group(1))
#             else:
#                 header_lines.append(line)
#         return directives, '\n'.join(header_lines)
# 
#     def parse(self, source):
#         header, source = self.split_source(source)
#         directives, header = self.split_header(header)
#         return directives, ''.join([header, source]).strip() + '\n'
# 
# Path: tests/helpers.py
# class GearsTestCase(unittest2.TestCase):
# 
#     fixtures_root = None
# 
#     def get_fixture_path(self, fixture):
#         return os.path.join(FIXTURES_DIR, self.fixtures_root, fixture)
# 
#     def find_fixture_file(self, fixture, name):
#         fixture_path = self.get_fixture_path(fixture)
#         for dirpath, dirnames, filenames in os.walk(fixture_path):
#             for filename in filenames:
#                 if filename.split('.')[0] == name:
#                     return os.path.join(dirpath, filename)
#         return None
# 
#     def get_source_path(self, fixture):
#         return self.find_fixture_file(fixture, 'source')
# 
#     def get_source(self, fixture):
#         return read(self.get_source_path(fixture))
# 
#     def get_output(self, fixture, name='output'):
#         return read(self.find_fixture_file(fixture, name))
# 
#     def get_finder(self, fixture):
#         fixture_path = self.get_fixture_path(fixture)
#         return FileSystemFinder([fixture_path])
# 
#     def get_environment(self, fixture):
#         finder = self.get_finder(fixture)
#         environment = Environment(os.path.join(TESTS_DIR, 'static'))
#         environment.finders.register(finder)
#         environment.register_defaults()
#         return environment
# 
#     def get_asset(self, fixture, environment=None, asset_class=Asset):
#         source_path = self.get_source_path(fixture)
#         if environment is None:
#             environment = self.get_environment(fixture)
# 
#         fixture_path = self.get_fixture_path(fixture)
#         logical_path = os.path.relpath(source_path, fixture_path)
#         asset_attributes = AssetAttributes(environment, logical_path)
# 
#         return asset_class(asset_attributes, source_path)
# 
#     def get_static_asset(self, fixture, environment=None):
#         return self.get_asset(fixture, environment, asset_class=StaticAsset)


import os
from gears.directives_parser import DirectivesParser
from unittest2 import TestCase
from .helpers import GearsTestCase
            'require models',
            'require collections',
            'require views',
        ])

    def test_skips_non_header_comments(self):
        self.check_asset('non_header_comments', ['require jquery'])


class DirectivesParserHeaderPatternTests(TestCase):

    def setUp(self):
        self.re = DirectivesParser().header_re

    def test_matches_multiline_comment(self):
        self.assertTrue(self.re.match('\n\n/*\nmultiline comment\n */'))

    def test_matches_multiple_miltiline_comments(self):
        self.assertTrue(self.re.match('/* comment */\n\n/* comment */'))

    def test_matches_slash_comment(self):
        self.assertTrue(self.re.match('  // this\n\n  // is\n  // comment'))

    def test_matches_dash_comment(self):
        self.assertTrue(self.re.match('  # this\n  \n  # is\n  # comment'))


class DirectivesParserDirectivePatternTests(TestCase):

    def setUp(self):

# Path: gears/directives_parser.py
# class DirectivesParser(object):
# 
#     header_re = re.compile(r"""
#         ^( \s* (
#             ( /\* .*? \*/ ) |  # multiline comment
#             ( // [^\n]* )+ |   # slash comment
#             ( \# [^\n]* )+     # dash comment
#         ) )+
#     """, re.S | re.X)
# 
#     directive_re = re.compile(r"""
#         ^ \s* (?:\*|//|\#) \s* = \s* ( \w+ [=*?\[\]./'"\s\w-]* ) $
#     """, re.X)
# 
#     def split_source(self, source):
#         header_match = self.header_re.match(source)
#         if not header_match:
#             return '', source
#         header = header_match.group(0)
#         source = source[len(header):]
#         return header, source
# 
#     def split_header(self, header):
#         directives = []
#         header_lines = []
#         for line in header.splitlines():
#             directive_match = self.directive_re.match(line)
#             if directive_match:
#                 directives.append(directive_match.group(1))
#             else:
#                 header_lines.append(line)
#         return directives, '\n'.join(header_lines)
# 
#     def parse(self, source):
#         header, source = self.split_source(source)
#         directives, header = self.split_header(header)
#         return directives, ''.join([header, source]).strip() + '\n'
# 
# Path: tests/helpers.py
# class GearsTestCase(unittest2.TestCase):
# 
#     fixtures_root = None
# 
#     def get_fixture_path(self, fixture):
#         return os.path.join(FIXTURES_DIR, self.fixtures_root, fixture)
# 
#     def find_fixture_file(self, fixture, name):
#         fixture_path = self.get_fixture_path(fixture)
#         for dirpath, dirnames, filenames in os.walk(fixture_path):
#             for filename in filenames:
#                 if filename.split('.')[0] == name:
#                     return os.path.join(dirpath, filename)
#         return None
# 
#     def get_source_path(self, fixture):
#         return self.find_fixture_file(fixture, 'source')
# 
#     def get_source(self, fixture):
#         return read(self.get_source_path(fixture))
# 
#     def get_output(self, fixture, name='output'):
#         return read(self.find_fixture_file(fixture, name))
# 
#     def get_finder(self, fixture):
#         fixture_path = self.get_fixture_path(fixture)
#         return FileSystemFinder([fixture_path])
# 
#     def get_environment(self, fixture):
#         finder = self.get_finder(fixture)
#         environment = Environment(os.path.join(TESTS_DIR, 'static'))
#         environment.finders.register(finder)
#         environment.register_defaults()
#         return environment
# 
#     def get_asset(self, fixture, environment=None, asset_class=Asset):
#         source_path = self.get_source_path(fixture)
#         if environment is None:
#             environment = self.get_environment(fixture)
# 
#         fixture_path = self.get_fixture_path(fixture)
#         logical_path = os.path.relpath(source_path, fixture_path)
#         asset_attributes = AssetAttributes(environment, logical_path)
# 
#         return asset_class(asset_attributes, source_path)
# 
#     def get_static_asset(self, fixture, environment=None):
#         return self.get_asset(fixture, environment, asset_class=StaticAsset)


# Path: tests/test_directives_parser.py
import os
from gears.directives_parser import DirectivesParser
from unittest2 import TestCase
from .helpers import GearsTestCase

            'require models',
            'require collections',
            'require views',
        ])

    def test_skips_non_header_comments(self):
        self.check_asset('non_header_comments', ['require jquery'])


class DirectivesParserHeaderPatternTests(TestCase):

    def setUp(self):
        self.re = DirectivesParser().header_re

    def test_matches_multiline_comment(self):
        self.assertTrue(self.re.match('\n\n/*\nmultiline comment\n */'))

    def test_matches_multiple_miltiline_comments(self):
        self.assertTrue(self.re.match('/* comment */\n\n/* comment */'))

    def test_matches_slash_comment(self):
        self.assertTrue(self.re.match('  // this\n\n  // is\n  // comment'))

    def test_matches_dash_comment(self):
        self.assertTrue(self.re.match('  # this\n  \n  # is\n  # comment'))


class DirectivesParserDirectivePatternTests(TestCase):

    def setUp(self):

        self.re = DirectivesParser().directive_re