#!/usr/bin/env python
# -*- coding: utf-8 mode: python -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8

__all__ = ('suite',
           )

from base import TC
from utools.base.args import split_args, join_args, build_options

class ClassTest(TC):
    def test_split_args(self):
        eq = self.assertEqual
        eq(None, split_args(None))
        eq([], split_args(""))
        eq([], split_args(" "))
        eq(["a"], split_args(" a"))
        eq(["a"], split_args("a "))
        eq(["a"], split_args(" a "))
        eq(['a', 'b c', "'d", "e'", 'a"b'],
           split_args(r'''a "b c" 'd e' "a\"b"'''))

    def test_join_args(self):
        eq = self.assertEqual
        eq(None, join_args(None))
        eq('', join_args([]))
        eq('a', join_args(["a"]))
        eq('" a"', join_args([" a"]))
        eq('"a "', join_args(["a "]))
        eq('" a "', join_args([" a "]))
        eq(r'''a "b c" 'd e' "a\"b"''',
           join_args(['a', 'b c', "'d", "e'", 'a"b']))

    def test_build_options(self):
        eq = self.assertEqual
        eq(('ab:c', ['aaa', 'bbb=', 'cc', 'ccc']),
           build_options([('a', 'aaa', 'whatever'),
                          ('b:', 'bbb=', None),
                          ('c', ['cc', 'ccc'], None),
                          ]))

def suite():
    from base import TestLoader
    return TestLoader().loadTestsFromTestCase(ClassTest)

if __name__ == '__main__':
    from base import main
    main()
