# -*- coding: utf-8 -*-
'''
HeaderUpdater class test
========================
'''

import unittest
from tests.testutils import print_testtitle, validate_with_fail
from builder.commands.scode import SCode, SCmd
from builder.containers.chapter import Chapter
from builder.containers.episode import Episode
from builder.containers.scene import Scene
from builder.containers.story import Story
from builder.core import headerupdater as hd


class HeaderUpdaterTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        print_testtitle(hd.__name__, 'HeaderUpdater class')

    def test_instance(self):
        tmp = hd.HeaderUpdater()
        self.assertIsInstance(tmp, hd.HeaderUpdater)

    def test_title_of(self):
        data = [
                # (src, expect, exp_opt)
                (True, Story('test',), ('test',), 1),
                ]
        def checker(src, expect, exp_opt):
            tmp = hd.HeaderUpdater()._title_of(src)
            self.assertIsInstance(tmp, SCode)
            self.assertEqual(tmp.cmd, SCmd.TAG_TITLE)
            self.assertEqual(tmp.script, expect)
            self.assertEqual(tmp.option, exp_opt)
        validate_with_fail(self, 'title_of', checker, data)

    def test_outline_of(self):
        data = [
                # (src, expect)
                (True, Story('test',outline='apple'), ('apple',)),
                ]
        def checker(src, expect):
            tmp = hd.HeaderUpdater()._outline_of(src)
            self.assertIsInstance(tmp, SCode)
            self.assertEqual(tmp.cmd, SCmd.TAG_COMMENT)
            self.assertEqual(tmp.script, expect)
        validate_with_fail(self, 'outline_of', checker, data)

    def test_end_of(self):
        data = [
                # (src, expect)
                (True, Chapter('test',), SCmd.END_CHAPTER),
                ]
        validate_with_fail(self, 'end_of',
                lambda src, expect: self.assertEqual(
                    hd.HeaderUpdater()._end_of(src).cmd, expect),
                data)

[((21, 8, 21, 59), 'tests.testutils.print_testtitle', 'print_testtitle', ({(21, 24, 21, 35): 'hd.__name__', (21, 37, 21, 58): '"""HeaderUpdater class"""'}, {}), "(hd.__name__, 'HeaderUpdater class')", False, 'from tests.testutils import print_testtitle, validate_with_fail\n'), ((24, 14, 24, 32), 'builder.core.headerupdater.HeaderUpdater', 'hd.HeaderUpdater', ({}, {}), '()', True, 'from builder.core import headerupdater as hd\n'), ((38, 8, 38, 59), 'tests.testutils.validate_with_fail', 'validate_with_fail', ({(38, 27, 38, 31): 'self', (38, 33, 38, 43): '"""title_of"""', (38, 45, 38, 52): 'checker', (38, 54, 38, 58): 'data'}, {}), "(self, 'title_of', checker, data)", False, 'from tests.testutils import print_testtitle, validate_with_fail\n'), ((50, 8, 50, 61), 'tests.testutils.validate_with_fail', 'validate_with_fail', ({(50, 27, 50, 31): 'self', (50, 33, 50, 45): '"""outline_of"""', (50, 47, 50, 54): 'checker', (50, 56, 50, 60): 'data'}, {}), "(self, 'outline_of', checker, data)", False, 'from tests.testutils import print_testtitle, validate_with_fail\n'), ((30, 23, 30, 37), 'builder.containers.story.Story', 'Story', ({(30, 29, 30, 35): '"""test"""'}, {}), "('test')", False, 'from builder.containers.story import Story\n'), ((43, 23, 43, 52), 'builder.containers.story.Story', 'Story', (), '', False, 'from builder.containers.story import Story\n'), ((55, 23, 55, 39), 'builder.containers.chapter.Chapter', 'Chapter', ({(55, 31, 55, 37): '"""test"""'}, {}), "('test')", False, 'from builder.containers.chapter import Chapter\n'), ((33, 18, 33, 36), 'builder.core.headerupdater.HeaderUpdater', 'hd.HeaderUpdater', ({}, {}), '()', True, 'from builder.core import headerupdater as hd\n'), ((46, 18, 46, 36), 'builder.core.headerupdater.HeaderUpdater', 'hd.HeaderUpdater', ({}, {}), '()', True, 'from builder.core import headerupdater as hd\n'), ((59, 20, 59, 38), 'builder.core.headerupdater.HeaderUpdater', 'hd.HeaderUpdater', ({}, {}), '()', True, 'from builder.core import headerupdater as hd\n')]