# Path: vimswitch/test/BaseTestCase.py
# class BaseTestCase(unittest.TestCase):
#     def __init__(self, *args, **kwargs):
#         unittest.TestCase.__init__(self, *args, **kwargs)
# 
#         # Python < 3.2 does not have assertNotRegex
#         if not hasattr(self, 'assertNotRegex'):
#             self.assertNotRegex = self.assertNotRegexpMatches
# 
#     def assertMultilineRegexpMatches(self, string, regexp):
#         """
#         Asserts that the entirety of `string` matches `regexp`. `regexp` can be
#         a multiline string with indentation.
#         """
#         regexp = textwrap.dedent(regexp)
#         regexp = regexp.strip()
#         regexp = '^' + regexp + '$'
#         regexp = re.compile(regexp, re.DOTALL)
# 
#         self.assertRegexpMatches(string, regexp)
# 
#     def assertStdout(self, stdout, regexp):
#         "Asserts that the `stdout` io stream matches `regexp`"
#         stdoutText = stdout.getvalue().strip()
#         self.assertMultilineRegexpMatches(stdoutText, regexp)
# 
#     def resetStdout(self, stdout):
#         stdout.seek(0)
#         stdout.truncate(0)
# 
# Path: vimswitch/CommandLineParser.py
# class CommandLineParser:
#     def __init__(self):
#         self.action = ''
#         self.profile = None
#         self.errorMessage = ''
#         self.helpText = ''
# 
#     def parse(self, argv):
#         parser = self._createParser()
#         self.helpText = parser.format_help()
# 
#         argv = argv[1:]  # Remove the program name from the arguments
#         arguments = parser.parse_args(argv)
# 
#         self._processArguments(parser, arguments, argv)
# 
#     def _createParser(self):
#         parser = CustomArgumentParser(
#             prog='vimswitch',
#             description='A utility for switching between vim profiles.')
#         parser.add_argument('profile', nargs='?')
#         parser.add_argument('-u', '--update', action='store_true',
#                             help='download profile again')
#         parser.add_argument('-v', '--version', action='store_true',
#                             help='show version')
#         return parser
# 
#     def _processArguments(self, parser, arguments, argv):
#         if parser.hasError:
#             self.errorMessage = parser.errorMessage
#             self.action = 'invalidArgs'
#         elif arguments.version:
#             self.action = 'showVersion'
#         elif arguments.update:
#             self.action = 'updateProfile'
#             profileName = arguments.profile
#             if profileName is None:
#                 self.profile = None
#             else:
#                 self.profile = Profile(profileName)
#         elif arguments.profile is not None:
#             self.action = 'switchProfile'
#             profileName = arguments.profile
#             self.profile = Profile(profileName)
#         elif len(argv) == 0:
#             self.action = 'showCurrentProfile'
# 
# Path: vimswitch/Profile.py
# class Profile:
#     def __init__(self, name):
#         self.name = name
# 
#     def getName(self):
#         return self.name
# 
#     def getDirName(self):
#         return self.name.replace('/', '.')
# 
#     def __eq__(self, other):
#         return isinstance(other, Profile) and self.name == other.name
# 
#     def __ne__(self, other):
#         return not self.__eq__(other)
# 
#     def __repr__(self):
#         return "Profile('%s')" % self.name


from .BaseTestCase import BaseTestCase
from vimswitch.CommandLineParser import CommandLineParser
from vimswitch.Profile import Profile


class TestCommandLineParser(BaseTestCase):

    def setUp(self):
        self.commandLineParser = CommandLineParser()

    def test_parse_emptyArgs_setsShowCurrentProfileAction(self):
        argv = './vimswitch'.split()
        self.commandLineParser.parse(argv)
        self.assertEqual(self.commandLineParser.action, 'showCurrentProfile')

    def test_parse_setsSwitchProfileAction(self):
        argv = './vimswitch test/vimrc'.split()

        self.commandLineParser.parse(argv)

        self.assertEqual(self.commandLineParser.action, 'switchProfile')

# Path: vimswitch/test/BaseTestCase.py
# class BaseTestCase(unittest.TestCase):
#     def __init__(self, *args, **kwargs):
#         unittest.TestCase.__init__(self, *args, **kwargs)
# 
#         # Python < 3.2 does not have assertNotRegex
#         if not hasattr(self, 'assertNotRegex'):
#             self.assertNotRegex = self.assertNotRegexpMatches
# 
#     def assertMultilineRegexpMatches(self, string, regexp):
#         """
#         Asserts that the entirety of `string` matches `regexp`. `regexp` can be
#         a multiline string with indentation.
#         """
#         regexp = textwrap.dedent(regexp)
#         regexp = regexp.strip()
#         regexp = '^' + regexp + '$'
#         regexp = re.compile(regexp, re.DOTALL)
# 
#         self.assertRegexpMatches(string, regexp)
# 
#     def assertStdout(self, stdout, regexp):
#         "Asserts that the `stdout` io stream matches `regexp`"
#         stdoutText = stdout.getvalue().strip()
#         self.assertMultilineRegexpMatches(stdoutText, regexp)
# 
#     def resetStdout(self, stdout):
#         stdout.seek(0)
#         stdout.truncate(0)
# 
# Path: vimswitch/CommandLineParser.py
# class CommandLineParser:
#     def __init__(self):
#         self.action = ''
#         self.profile = None
#         self.errorMessage = ''
#         self.helpText = ''
# 
#     def parse(self, argv):
#         parser = self._createParser()
#         self.helpText = parser.format_help()
# 
#         argv = argv[1:]  # Remove the program name from the arguments
#         arguments = parser.parse_args(argv)
# 
#         self._processArguments(parser, arguments, argv)
# 
#     def _createParser(self):
#         parser = CustomArgumentParser(
#             prog='vimswitch',
#             description='A utility for switching between vim profiles.')
#         parser.add_argument('profile', nargs='?')
#         parser.add_argument('-u', '--update', action='store_true',
#                             help='download profile again')
#         parser.add_argument('-v', '--version', action='store_true',
#                             help='show version')
#         return parser
# 
#     def _processArguments(self, parser, arguments, argv):
#         if parser.hasError:
#             self.errorMessage = parser.errorMessage
#             self.action = 'invalidArgs'
#         elif arguments.version:
#             self.action = 'showVersion'
#         elif arguments.update:
#             self.action = 'updateProfile'
#             profileName = arguments.profile
#             if profileName is None:
#                 self.profile = None
#             else:
#                 self.profile = Profile(profileName)
#         elif arguments.profile is not None:
#             self.action = 'switchProfile'
#             profileName = arguments.profile
#             self.profile = Profile(profileName)
#         elif len(argv) == 0:
#             self.action = 'showCurrentProfile'
# 
# Path: vimswitch/Profile.py
# class Profile:
#     def __init__(self, name):
#         self.name = name
# 
#     def getName(self):
#         return self.name
# 
#     def getDirName(self):
#         return self.name.replace('/', '.')
# 
#     def __eq__(self, other):
#         return isinstance(other, Profile) and self.name == other.name
# 
#     def __ne__(self, other):
#         return not self.__eq__(other)
# 
#     def __repr__(self):
#         return "Profile('%s')" % self.name


# Path: vimswitch/test/test_CommandLineParser.py
from .BaseTestCase import BaseTestCase
from vimswitch.CommandLineParser import CommandLineParser
from vimswitch.Profile import Profile



class TestCommandLineParser(BaseTestCase):

    def setUp(self):
        self.commandLineParser = CommandLineParser()

    def test_parse_emptyArgs_setsShowCurrentProfileAction(self):
        argv = './vimswitch'.split()
        self.commandLineParser.parse(argv)
        self.assertEqual(self.commandLineParser.action, 'showCurrentProfile')

    def test_parse_setsSwitchProfileAction(self):
        argv = './vimswitch test/vimrc'.split()

        self.commandLineParser.parse(argv)

        self.assertEqual(self.commandLineParser.action, 'switchProfile')

        self.assertEqual(self.commandLineParser.profile, Profile('test/vimrc'))