# -*- coding: utf-8 -*-
"""test class"""
import unittest

from plasoscaffolder.bll.mappings.mapping_helper import MappingHelper
from tests.test_helper import path_helper


class MappingHelperTest(unittest.TestCase):
  """ Class representing a test case for the mapping helper functions. """

  def setUp(self):
    self.template_path = path_helper.TestTemplatePath()
    yapf_path = path_helper.YapfStyleFilePath()
    self.plugin_name = "the_one_and_only"
    self.file = "test_template.jinja2"
    self.helper = MappingHelper(self.template_path, yapf_path)

  def testRender(self):
    """test the render """
    context = {'plugin_name': self.plugin_name}
    actual = self.helper.RenderTemplate(self.file, context)
    expected = "# -*- coding: utf-8 -*-\n\"\"\"{0}\"\"\"\n".format(
        self.plugin_name)
    self.assertEqual(expected, actual)

  def testGenerateClassName(self):
    """Test the generation of the classname from the pluginname"""
    name = "this_is_a_test"
    expected = "ThisIsATest"
    actual = self.helper.GenerateClassName(name)
    self.assertEqual(expected, actual)



  def testRemoveEscapeErrorWithSpacesLikeInTemplate(self):
    """Tests the removing of an escape error"""
    string_with_error = 'u\'the first line\\\'\n        u\'\\the second line'
    string_without_error = 'u\'the first line\'\n        u\'\\\\the second line'
    actual = self.helper._RemoveEscapeError(string_with_error)
    self.assertEqual(string_without_error, actual)

  def testRemoveEscapeErrorWithNoEscape(self):
    """Tests the removing of an escape error"""
    string_without_error = 'u\'the first line\\\\\'\n        u\'the second line'
    actual = self.helper._RemoveEscapeError(string_without_error)
    self.assertEqual(string_without_error, actual)

  def testRemoveBlanksAtEndOfLineForTwoBlanks(self):
    """Tests the removing of blanks at the end of a line"""
    string_with_blank = 'somestuff  \n'
    string_without_blank = 'somestuff\n'
    actual = self.helper._RemoveBlanksAtEndOfLine(string_with_blank)
    self.assertEqual(string_without_blank, actual)

  def testRemoveBlanksAtEndOfLineForFourBlanks(self):
    """Tests the removing of blanks at the end of a line"""
    string_with_blank = '    \n'
    string_without_blank = '\n'
    actual = self.helper._RemoveBlanksAtEndOfLine(string_with_blank)
    self.assertEqual(string_without_blank, actual)

  def testRemoveBlanksAtEndOfLineFor12Blanks(self):
    """Tests the removing of blanks at the end of a line"""
    string_with_blank = 'somestuff            \n'
    string_without_blank = 'somestuff\n'
    actual = self.helper._RemoveBlanksAtEndOfLine(string_with_blank)
    self.assertEqual(string_without_blank, actual)

  def testRemoveYapfCommentOnlyTheEnable(self):
    """Tests the removing of the yapf enable comment"""
    string_with_yapf_enable = 'something\n# yapf: enable\notherline'
    string_without_yapf_enable = 'something\notherline'
    actual = self.helper._RemoveYapfComment(string_with_yapf_enable)
    self.assertEqual(string_without_yapf_enable, actual)

  def testRemoveYapfCommentOnlyTheDisable(self):
    """Tests the removing of the yapf enable comment"""
    string_with_yapf_enable = 'something\n# yapf: disable\notherline'
    string_without_yapf_enable = 'something\notherline'
    actual = self.helper._RemoveYapfComment(string_with_yapf_enable)
    self.assertEqual(string_without_yapf_enable, actual)

  def testRemoveYapfCommentOnlyTheEnableAndDisable(self):
    """Tests the removing of the yapf enable comment"""
    string_with_yapf_enable = (
    'something\n# yapf: disable\notherline\n# yapf: enable\nlastline')
    string_without_yapf_enable = 'something\notherline\nlastline'
    actual = self.helper._RemoveYapfComment(string_with_yapf_enable)
    self.assertEqual(string_without_yapf_enable, actual)


if __name__ == '__main__':
  unittest.main()

@@ -431,17 +431,17 @@
 _name = 
-%22
+'
 the_one_
@@ -448,17 +448,17 @@
 and_only
-%22
+'
 %0A    sel
@@ -466,17 +466,17 @@
 .file = 
-%22
+'
 test_tem
@@ -487,17 +487,17 @@
 e.jinja2
-%22
+'
 %0A    sel
@@ -727,17 +727,17 @@
 ected = 
-%22
+'
 # -*- co
@@ -757,26 +757,20 @@
 *-%5Cn
-%5C%22%5C%22%5C%22%7B0%7D%5C%22%5C%22%5C%22%5Cn%22
+%22%22%22%7B0%7D%22%22%22%5Cn'
 .for
@@ -953,17 +953,17 @@
  name = 
-%22
+'
 this_is_
@@ -968,17 +968,17 @@
 s_a_test
-%22
+'
 %0A    exp
@@ -985,17 +985,17 @@
 ected = 
-%22
+'
 ThisIsAT
@@ -997,17 +997,17 @@
 sIsATest
-%22
+'
 %0A    act

change double quotes to single