# Path: vii/Dispatcher.py
# class Dispatcher:
#     def __init__(self):
#         self.actionManager = None
#         self.currentMode = None
#         self.currentAction = None
#         self.currentCommand = None
#         self.forceTokenToString = False
# 
#     def step(self, token):
#         self.stepInit(token)
#         self.stepCommand(token)
#         self.stepAction(token)
# 
#     def stepInit(self, token):
#         if isinstance(token, int): raise TokenExecption
#         if self.currentCommand == None: self.reset()
#         if self.currentMode == None or self.currentAction == None:
#             self.currentMode = "normal"
#             self.currentAction = self.actionManager.action(
#                 "normal", "idle")
# 
#     def stepCommand(self, token):
#         if self.currentMode == "insert":
#             self.currentCommand.last().appendToInserts(token)
#         else:
#             if(len(self.currentCommand.last().numeral) == 0
#                 and token == '0'): self.forceTokenToString = True
#             if token.isdigit() and not self.forceTokenToString:
#                 self.currentCommand.last().appendToNumeral(token)
#                 self.currentCommand.last().numeralToCount()
#             else:
#                 self.forceTokenToString = True
#                 self.currentCommand.last().operator = token
#                 self.currentCommand.last().ready = True
# 
#     def stepAction(self, token):
#         if token == chr(27):
#             self.currentAction.finish()
#             self.currentMode = "normal"
#             self.currentAction = self.actionManager.action(
#                 "normal", "idle")
#         if self.currentCommand.last().ready:
#             self.currentMode, self.currentAction = self.currentAction.act()
# 
#     def logHistory(self):
#         # TODO
#         pass
# 
#     def extend(self):
#         self.currentCommand.extend()
#         self.forceTokenToString = False
# 
#     def reset(self):
#         self.currentCommand = Command()
#         self.currentCommand.extend()
#         self.forceTokenToString = False
# 
# class TokenExecption(Exception): pass
# 
# Path: vii/Command.py
# class Command:
# 
#     def __init__(self):
#         self.parts = []
# 
#     def extend(self):
#         self.parts.append(Part())
# 
#     def part(self, nr):
#         return self.parts[nr]
# 
#     def previous(self):
#         return self.parts[-2]
# 
#     def last(self):
#         return self.parts[-1]
# 
#     def multiplyAll(self):
#         result = 1
#         for i in range(len(self.parts)):
#             count = self.parts[i].count
#             count = count if count else 1
#             result *= count
#         return result
# 
#     def hasNoCounts(self):
#         result = True
#         for i in range(len(self.parts)):
#             count = self.parts[i].count
#             if count: result = False
#         return result
# 
#     """ Shortcuts to the last part """
# 
#     def lpReady(self):
#         return self.last().ready
# 
#     def lpRegister(self):
#         return self.last().register
# 
#     def lpOperator(self):
#         return self.last().operator
# 
#     def lpCount(self):
#         return self.last().count
# 
#     def lpInserts(self):
#         return self.last().inserts
# 
#     def lpInsert(self):
#         return self.last().insert()


from vii.Dispatcher import Dispatcher, TokenExecption
from vii.Command import Command
from nose.tools import *
    def test_stepCommand_normal(self):
        self.fixture.reset()
        self.fixture.currentMode = "normal"
        self.fixture.stepCommand("1")
        self.fixture.stepCommand("2")
        assert self.fixture.forceTokenToString == False
        assert self.fixture.currentCommand.lpReady() == False
        assert self.fixture.currentCommand.lpCount() == 12
        self.fixture.stepCommand("a")
        assert self.fixture.forceTokenToString == True
        assert self.fixture.currentCommand.lpReady() == True
        assert self.fixture.currentCommand.lpOperator() == "a"

    def test_stepAction(self):
        pass
        # TODO

    def test_extend(self):
        self.fixture.reset()
        assert self.fixture.forceTokenToString == False
        self.fixture.forceTokenToString = True
        self.fixture.extend()
        assert self.fixture.forceTokenToString == False

    def test_reset(self):
        self.fixture.currentCommand = None
        self.fixture.forceTokenToString = True
        self.fixture.reset()
        assert self.fixture.forceTokenToString == False
        command = self.fixture.currentCommand

# Path: vii/Dispatcher.py
# class Dispatcher:
#     def __init__(self):
#         self.actionManager = None
#         self.currentMode = None
#         self.currentAction = None
#         self.currentCommand = None
#         self.forceTokenToString = False
# 
#     def step(self, token):
#         self.stepInit(token)
#         self.stepCommand(token)
#         self.stepAction(token)
# 
#     def stepInit(self, token):
#         if isinstance(token, int): raise TokenExecption
#         if self.currentCommand == None: self.reset()
#         if self.currentMode == None or self.currentAction == None:
#             self.currentMode = "normal"
#             self.currentAction = self.actionManager.action(
#                 "normal", "idle")
# 
#     def stepCommand(self, token):
#         if self.currentMode == "insert":
#             self.currentCommand.last().appendToInserts(token)
#         else:
#             if(len(self.currentCommand.last().numeral) == 0
#                 and token == '0'): self.forceTokenToString = True
#             if token.isdigit() and not self.forceTokenToString:
#                 self.currentCommand.last().appendToNumeral(token)
#                 self.currentCommand.last().numeralToCount()
#             else:
#                 self.forceTokenToString = True
#                 self.currentCommand.last().operator = token
#                 self.currentCommand.last().ready = True
# 
#     def stepAction(self, token):
#         if token == chr(27):
#             self.currentAction.finish()
#             self.currentMode = "normal"
#             self.currentAction = self.actionManager.action(
#                 "normal", "idle")
#         if self.currentCommand.last().ready:
#             self.currentMode, self.currentAction = self.currentAction.act()
# 
#     def logHistory(self):
#         # TODO
#         pass
# 
#     def extend(self):
#         self.currentCommand.extend()
#         self.forceTokenToString = False
# 
#     def reset(self):
#         self.currentCommand = Command()
#         self.currentCommand.extend()
#         self.forceTokenToString = False
# 
# class TokenExecption(Exception): pass
# 
# Path: vii/Command.py
# class Command:
# 
#     def __init__(self):
#         self.parts = []
# 
#     def extend(self):
#         self.parts.append(Part())
# 
#     def part(self, nr):
#         return self.parts[nr]
# 
#     def previous(self):
#         return self.parts[-2]
# 
#     def last(self):
#         return self.parts[-1]
# 
#     def multiplyAll(self):
#         result = 1
#         for i in range(len(self.parts)):
#             count = self.parts[i].count
#             count = count if count else 1
#             result *= count
#         return result
# 
#     def hasNoCounts(self):
#         result = True
#         for i in range(len(self.parts)):
#             count = self.parts[i].count
#             if count: result = False
#         return result
# 
#     """ Shortcuts to the last part """
# 
#     def lpReady(self):
#         return self.last().ready
# 
#     def lpRegister(self):
#         return self.last().register
# 
#     def lpOperator(self):
#         return self.last().operator
# 
#     def lpCount(self):
#         return self.last().count
# 
#     def lpInserts(self):
#         return self.last().inserts
# 
#     def lpInsert(self):
#         return self.last().insert()


# Path: tests/Dispatcher_Test.py
from vii.Dispatcher import Dispatcher, TokenExecption
from vii.Command import Command
from nose.tools import *

    def test_stepCommand_normal(self):
        self.fixture.reset()
        self.fixture.currentMode = "normal"
        self.fixture.stepCommand("1")
        self.fixture.stepCommand("2")
        assert self.fixture.forceTokenToString == False
        assert self.fixture.currentCommand.lpReady() == False
        assert self.fixture.currentCommand.lpCount() == 12
        self.fixture.stepCommand("a")
        assert self.fixture.forceTokenToString == True
        assert self.fixture.currentCommand.lpReady() == True
        assert self.fixture.currentCommand.lpOperator() == "a"

    def test_stepAction(self):
        pass
        # TODO

    def test_extend(self):
        self.fixture.reset()
        assert self.fixture.forceTokenToString == False
        self.fixture.forceTokenToString = True
        self.fixture.extend()
        assert self.fixture.forceTokenToString == False

    def test_reset(self):
        self.fixture.currentCommand = None
        self.fixture.forceTokenToString = True
        self.fixture.reset()
        assert self.fixture.forceTokenToString == False
        command = self.fixture.currentCommand

        assert command.__class__ == Command