# Path: css2video/constants.py
# class ValueType(object):
#     """Class to define constants for value types"""
# 
#     number = 'number'
#     length = 'length'
#     percentage = 'percentage'
#     time = 'time'
#     color = 'color'
#     text = 'text'
#     url = 'url'
#     function = 'function'
#     array = 'array'
# 
# Path: css2video/parsers/value.py
# class Function(BaseParser):
#     """Parse a function value with optional arguments passed"""
# 
#     ParseException = FunctionParseException
# 
#     @classmethod
#     def grammar(cls):
#         """Grammar to parse a function value"""
#         name = pp.Word(pp.alphas)
#         args = cls.args_parser()
# 
#         return (
#             name +
#             pp.Suppress(pp.Literal('(')) +
#             args +
#             pp.Suppress(pp.Literal(')'))
#         )
# 
#     @classmethod
#     def parse_action(cls, tokens):
#         """Returns a dictionary from the parsed tokens"""
#         return {
#             'type': ValueType.function,
#             'name': tokens[0],
#             'args': tokens[1:]
#         }
# 
#     @classmethod
#     def args_parser(cls):
#         """Returns the arguments of the function which can be a Number, Length,
#         Percentage, Time, Color, Text or URL"""
#         arg_types = [Number, Length, Percentage, Time, Color, Text, Url]
#         arg_parser = arg_types[0].parser()
#         for arg_type in arg_types[1:]:
#             arg_parser ^= arg_type.parser()
#         return pp.OneOrMore(arg_parser)
# 
# class FunctionParseException(Exception):
#     """Raised when there is an while parsing a function value"""
#     pass


import unittest
from css2video.constants import ValueType
from css2video.parsers.value import Function, FunctionParseException



class TestCase(unittest.TestCase):

    def test_parser(self):
        response = Function.parse('url("background.png")')
        self.assertEqual(
            response,
            dict(type=ValueType.function, name='url', args=[
                dict(type=ValueType.url, value='"background.png"')
            ])
        )

        response = Function.parse('translate(0 20px)')
        self.assertEqual(
            response,
            dict(type=ValueType.function, name='translate', args=[
                dict(type=ValueType.number, value=0.),
                dict(type=ValueType.length, value=20., unit='px')
            ])
        )

        with self.assertRaises(FunctionParseException):

# Path: css2video/constants.py
# class ValueType(object):
#     """Class to define constants for value types"""
# 
#     number = 'number'
#     length = 'length'
#     percentage = 'percentage'
#     time = 'time'
#     color = 'color'
#     text = 'text'
#     url = 'url'
#     function = 'function'
#     array = 'array'
# 
# Path: css2video/parsers/value.py
# class Function(BaseParser):
#     """Parse a function value with optional arguments passed"""
# 
#     ParseException = FunctionParseException
# 
#     @classmethod
#     def grammar(cls):
#         """Grammar to parse a function value"""
#         name = pp.Word(pp.alphas)
#         args = cls.args_parser()
# 
#         return (
#             name +
#             pp.Suppress(pp.Literal('(')) +
#             args +
#             pp.Suppress(pp.Literal(')'))
#         )
# 
#     @classmethod
#     def parse_action(cls, tokens):
#         """Returns a dictionary from the parsed tokens"""
#         return {
#             'type': ValueType.function,
#             'name': tokens[0],
#             'args': tokens[1:]
#         }
# 
#     @classmethod
#     def args_parser(cls):
#         """Returns the arguments of the function which can be a Number, Length,
#         Percentage, Time, Color, Text or URL"""
#         arg_types = [Number, Length, Percentage, Time, Color, Text, Url]
#         arg_parser = arg_types[0].parser()
#         for arg_type in arg_types[1:]:
#             arg_parser ^= arg_type.parser()
#         return pp.OneOrMore(arg_parser)
# 
# class FunctionParseException(Exception):
#     """Raised when there is an while parsing a function value"""
#     pass


# Path: tests/parsers/value/test_function.py
import unittest
from css2video.constants import ValueType
from css2video.parsers.value import Function, FunctionParseException




class TestCase(unittest.TestCase):

    def test_parser(self):
        response = Function.parse('url("background.png")')
        self.assertEqual(
            response,
            dict(type=ValueType.function, name='url', args=[
                dict(type=ValueType.url, value='"background.png"')
            ])
        )

        response = Function.parse('translate(0 20px)')
        self.assertEqual(
            response,
            dict(type=ValueType.function, name='translate', args=[
                dict(type=ValueType.number, value=0.),
                dict(type=ValueType.length, value=20., unit='px')
            ])
        )

        with self.assertRaises(FunctionParseException):

            Function.parse('hello')