# Path: flap/latex/macros/commons.py
# class Invocation:
#     """ The invocation of a LaTeX command, including the name of the
#     command, and its parameters indexed by name as sequences of
#     tokens.
#     """
# 
#     def __init__(self, command):
#         self.name = command
#         self._arguments = []
#         self._keys = dict()
# 
#     @property
#     def as_text(self):
#         text = self.to_text(self.name)
#         for each_argument in self._arguments:
#             text += "".join(map(str, each_argument))
#         return text
# 
#     @staticmethod
#     def to_text(parameter):
#         if isinstance(parameter, list):
#             return "".join(map(Invocation.to_text, parameter))
#         elif isinstance(parameter, str):
#              return parameter
#         else:
#             return parameter.as_text
# 
#     @property
#     def command_name(self):
#         """Returns the name (as a string) of the command without the first
#         control character.
#         """
#         return str(self.name)[1:]
# 
#     def send_to(self, parser):
#         return parser.process_invocation(self)
# 
#     def append(self, tokens):
#         self._arguments.append(tokens)
# 
#     def append_argument(self, name, value):
#         self._arguments.append(value)
#         self._keys[name] = len(self._arguments) - 1
# 
#     def argument(self, key):
#         return self._arguments[self._keys[key]]
# 
#     def argument_as_text(self, key):
#         return "".join(each_token.as_text
#                        for each_token in self.argument(key))
# 
#     @property
#     def location(self):
#         assert self.as_tokens, \
#             "Could not fetch invocation's position '%s'" % self.as_text
#         return self.as_tokens[0].location
# 
#     @property
#     def arguments(self):
#         return {key: self._arguments[value]
#                 for (key, value) in self._keys.items()}
# 
# 
#     @property
#     def as_tokens(self):
#         start = copy(self.name) \
#             if isinstance(self.name, list) \
#             else [self.name]
#         return sum(self._arguments, start)
# 
#     def substitute(self, argument, value):
#         clone = Invocation(self.name)
#         clone.name = copy(self.name)
#         clone._arguments = copy(self._arguments)
#         clone._keys = copy(self._keys)
#         clone._arguments[clone._keys[argument]] = value
#         return clone


from unittest import TestCase, main
from flap.latex.macros.commons import Invocation
#!/usr/bin/env python

#
# This file is part of Flap.
#
# Flap is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Flap is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Flap.  If not, see <http://www.gnu.org/licenses/>.
#




class InvocationTests(TestCase):

    def setUp(self):
        self._name = "foo"

# Path: flap/latex/macros/commons.py
# class Invocation:
#     """ The invocation of a LaTeX command, including the name of the
#     command, and its parameters indexed by name as sequences of
#     tokens.
#     """
# 
#     def __init__(self, command):
#         self.name = command
#         self._arguments = []
#         self._keys = dict()
# 
#     @property
#     def as_text(self):
#         text = self.to_text(self.name)
#         for each_argument in self._arguments:
#             text += "".join(map(str, each_argument))
#         return text
# 
#     @staticmethod
#     def to_text(parameter):
#         if isinstance(parameter, list):
#             return "".join(map(Invocation.to_text, parameter))
#         elif isinstance(parameter, str):
#              return parameter
#         else:
#             return parameter.as_text
# 
#     @property
#     def command_name(self):
#         """Returns the name (as a string) of the command without the first
#         control character.
#         """
#         return str(self.name)[1:]
# 
#     def send_to(self, parser):
#         return parser.process_invocation(self)
# 
#     def append(self, tokens):
#         self._arguments.append(tokens)
# 
#     def append_argument(self, name, value):
#         self._arguments.append(value)
#         self._keys[name] = len(self._arguments) - 1
# 
#     def argument(self, key):
#         return self._arguments[self._keys[key]]
# 
#     def argument_as_text(self, key):
#         return "".join(each_token.as_text
#                        for each_token in self.argument(key))
# 
#     @property
#     def location(self):
#         assert self.as_tokens, \
#             "Could not fetch invocation's position '%s'" % self.as_text
#         return self.as_tokens[0].location
# 
#     @property
#     def arguments(self):
#         return {key: self._arguments[value]
#                 for (key, value) in self._keys.items()}
# 
# 
#     @property
#     def as_tokens(self):
#         start = copy(self.name) \
#             if isinstance(self.name, list) \
#             else [self.name]
#         return sum(self._arguments, start)
# 
#     def substitute(self, argument, value):
#         clone = Invocation(self.name)
#         clone.name = copy(self.name)
#         clone._arguments = copy(self._arguments)
#         clone._keys = copy(self._keys)
#         clone._arguments[clone._keys[argument]] = value
#         return clone


# Path: tests/unit/latex/test_macro.py
from unittest import TestCase, main
from flap.latex.macros.commons import Invocation

#!/usr/bin/env python

#
# This file is part of Flap.
#
# Flap is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Flap is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Flap.  If not, see <http://www.gnu.org/licenses/>.
#




class InvocationTests(TestCase):

    def setUp(self):
        self._name = "foo"

        self._invocation = Invocation("foo")