def setUp(self):
     self.replacer = ThriftConstReplacer()
class ThriftConstReplacerTestCase(unittest.TestCase):
    def setUp(self):
        self.replacer = ThriftConstReplacer()

    def test_parse_line_SimpleLine_ReturnAsIsNoConstsSet(self):
        line = "// abcdefg"
        output = self.replacer.parse_line(line)
        self.assertEqual(line, output)
        self.assertEqual({}, self.replacer.get_consts())

    def test_parse_line_ConstantDeclaration_ConstsSet(self):
        const = '"abc"'
        line = "const string a = " + const + ";"
        output = self.replacer.parse_line(line)
        self.assertEqual(line, output)
        self.assertEqual({'a': const}, self.replacer.get_consts())

    def test_parse_line_ConstantDeclarationThenUsed_ConstReplaced(self):
        const = '"abc"'
        line = "const string a = " + const
        self.replacer.parse_line(line)

        line2 = "a + xyz"
        output = self.replacer.parse_line(line2)
        self.assertEqual('"abc" + xyz', output)

    def test_parse_line_ConstantDeclarationThenUsedWithCommas_ConstReplaced(
        self
    ):
        const = '"abc"'
        line = "const string a = " + const
        self.replacer.parse_line(line)

        line2 = "a, + xyz"
        output = self.replacer.parse_line(line2)
        self.assertEqual('"abc", + xyz', output)

    def test_parse_line_ValueHasSpace_ConstReplaced(self):
        const = '"abc def"'
        line = "const string a = " + const
        self.replacer.parse_line(line)

        line2 = "a + xyz"
        output = self.replacer.parse_line(line2)
        self.assertEqual('"abc def" + xyz', output)

    def test_parse_line_ValueAtSeparateLine_ConstReplaced(self):
        const = '"abc def"'
        line1 = "const string a ="
        line2 = const
        self.replacer.parse_line(line1)
        self.replacer.parse_line(line2)

        line3 = "a + xyz"
        output = self.replacer.parse_line(line3)
        self.assertEqual('"abc def" + xyz', output)