# Path: tests/helper.py
# class RegexTestCase(TestCase):
#     """
#     A helper class to provide functions useful for performing tests against
#     regex test scenarios.
#     """
# 
#     def run_regex(self, input, is_js=False):
#         """Run the standard regex tests for non-JavaScript input."""
#         if self.err is None:
#             self.setup_err()
# 
#         if not is_js:
#             input = '<input onclick="%s" />' % input
#         else:
#             input = "'use strict';\n%s" % input
#         regex.run_regex_tests(input, self.err, 'foo.txt', is_js=is_js)
# 
#     def run_js_regex(self, input):
#         """Run the standard regex tests for JavaScript input."""
#         if self.err is None:
#             self.setup_err()
#         regex.run_regex_tests(input, self.err, 'foo.txt', is_js=True)
# 
# Path: tests/js_helper.py
# class TestCase(helper.TestCase):
#     """A TestCase object with specialized functions for JS testing."""
# 
#     def setUp(self):
#         self.file_path = 'foo.js'
#         self.final_context = None
#         super(TestCase, self).setUp()
# 
#     def run_script_from_file(self, path):
#         """
#         Run the standard set of JS engine tests on a script found at the
#         location in `path`.
#         """
#         with open(path) as script_file:
#             return self.run_script(script_file.read())
# 
#     def run_script(self, script, expose_pollution=False, bootstrap=False):
#         """
#         Run the standard set of JS engine tests on the script passed via
#         `script`.
#         """
#         if self.err is None:
#             self.setup_err()
#         if self.err.supported_versions is None:
#             self.err.supported_versions = {}
#         if bootstrap:
#             self.err.save_resource('em:bootstrap', 'true')
# 
#         validator.testcases.content._process_file(self.err, MockXPI(),
#                                                   self.file_path, script,
#                                                   self.file_path.lower(),
#                                                   expose_pollution)
#         if self.err.final_context is not None:
#             print self.err.final_context.output()
#             self.final_context = self.err.final_context
# 
#     def get_var(self, name):
#         """
#         Return the value of a variable from the final script context.
#         """
#         try:
#             return self.final_context.data[name].get_literal_value()
#         except KeyError:
#             raise ('Test seeking variable (%s) not found in final context.' %
#                    name)
# 
#     def assert_var_eq(self, name, value):
#         """
#         Assert that the value of a variable from the final script context
#         contains the value specified.
#         """
#         assert self.get_var(name) == value


from ..helper import RegexTestCase
from ..js_helper import TestCase as JSTestCase
class CompatTestCase(JSTestCase, RegexTestCase):
    """
    A TestCase object which aids in running tests regarding compatibility
    tests. It is expected that you will supply a static member `VERSION`
    describing the version(s) of Gecko that these tests apply to.
    """

    def setUp(self, *args, **kwargs):
        super(CompatTestCase, self).setUp(*args, **kwargs)

    def run_script_for_compat(self, script, expose_pollution=False):
        """
        Test a script with and without version restrictions to determine
        whether it properly raises JavaScript compatibility messages.
        """
        self._run_member_for_compat(
            lambda: self.run_script(script, expose_pollution))

    def run_xpcom_for_compat(self, interface, methods):
        """Yields after each method has been run as a script. Used to test that
        XPCOM members are properly flagged for compatibility tests.

        - `interface` should be the name of the XPCOM interface.
        - `methods` should be the member to test. It may be a simple reference
          to a member (i.e.: `foo`) or an action upon a member (i.e.:
          `foo('bar')` or `foo["bar"] = "zap"`).

        """

        script = """

# Path: tests/helper.py
# class RegexTestCase(TestCase):
#     """
#     A helper class to provide functions useful for performing tests against
#     regex test scenarios.
#     """
# 
#     def run_regex(self, input, is_js=False):
#         """Run the standard regex tests for non-JavaScript input."""
#         if self.err is None:
#             self.setup_err()
# 
#         if not is_js:
#             input = '<input onclick="%s" />' % input
#         else:
#             input = "'use strict';\n%s" % input
#         regex.run_regex_tests(input, self.err, 'foo.txt', is_js=is_js)
# 
#     def run_js_regex(self, input):
#         """Run the standard regex tests for JavaScript input."""
#         if self.err is None:
#             self.setup_err()
#         regex.run_regex_tests(input, self.err, 'foo.txt', is_js=True)
# 
# Path: tests/js_helper.py
# class TestCase(helper.TestCase):
#     """A TestCase object with specialized functions for JS testing."""
# 
#     def setUp(self):
#         self.file_path = 'foo.js'
#         self.final_context = None
#         super(TestCase, self).setUp()
# 
#     def run_script_from_file(self, path):
#         """
#         Run the standard set of JS engine tests on a script found at the
#         location in `path`.
#         """
#         with open(path) as script_file:
#             return self.run_script(script_file.read())
# 
#     def run_script(self, script, expose_pollution=False, bootstrap=False):
#         """
#         Run the standard set of JS engine tests on the script passed via
#         `script`.
#         """
#         if self.err is None:
#             self.setup_err()
#         if self.err.supported_versions is None:
#             self.err.supported_versions = {}
#         if bootstrap:
#             self.err.save_resource('em:bootstrap', 'true')
# 
#         validator.testcases.content._process_file(self.err, MockXPI(),
#                                                   self.file_path, script,
#                                                   self.file_path.lower(),
#                                                   expose_pollution)
#         if self.err.final_context is not None:
#             print self.err.final_context.output()
#             self.final_context = self.err.final_context
# 
#     def get_var(self, name):
#         """
#         Return the value of a variable from the final script context.
#         """
#         try:
#             return self.final_context.data[name].get_literal_value()
#         except KeyError:
#             raise ('Test seeking variable (%s) not found in final context.' %
#                    name)
# 
#     def assert_var_eq(self, name, value):
#         """
#         Assert that the value of a variable from the final script context
#         contains the value specified.
#         """
#         assert self.get_var(name) == value


# Path: tests/compat/helper.py
from ..helper import RegexTestCase
from ..js_helper import TestCase as JSTestCase

class CompatTestCase(JSTestCase, RegexTestCase):
    """
    A TestCase object which aids in running tests regarding compatibility
    tests. It is expected that you will supply a static member `VERSION`
    describing the version(s) of Gecko that these tests apply to.
    """

    def setUp(self, *args, **kwargs):
        super(CompatTestCase, self).setUp(*args, **kwargs)

    def run_script_for_compat(self, script, expose_pollution=False):
        """
        Test a script with and without version restrictions to determine
        whether it properly raises JavaScript compatibility messages.
        """
        self._run_member_for_compat(
            lambda: self.run_script(script, expose_pollution))

    def run_xpcom_for_compat(self, interface, methods):
        """Yields after each method has been run as a script. Used to test that
        XPCOM members are properly flagged for compatibility tests.

        - `interface` should be the name of the XPCOM interface.
        - `methods` should be the member to test. It may be a simple reference
          to a member (i.e.: `foo`) or an action upon a member (i.e.:
          `foo('bar')` or `foo["bar"] = "zap"`).

        """

        script = """

        var x = Components.classes[""].createInstance(Components.interfaces.%s);