5"""Tests for emitter module."""
21 self.assertEqual(
''.
join(e.Fragments()), expected)
25 body = e.Emit(
'$TYPE $NAME() {\n'
30 body.Emit(
'return $VALUE;', VALUE=
'100')
31 self.
check(e,
'int foo() {\n' ' return 100;\n' '}\n')
36 b = e.Emit(
'$(A)$(!B)$(A)$(!B)')
37 except RuntimeError
as ex:
39 raise AssertionError(
'Expected error')
43 e.Emit(
'-$A+$B-$A+$B-', A=
'1', B=
'2')
44 self.
check(e,
'-1+2-1+2-')
48 r = e.Emit(
'1$(A)2$(B)3$(A)4$(B)5', A=
'x', B=
'y')
49 self.assertEqual(
None, r)
50 self.
check(e,
'1x2y3x4y5')
54 b = e.Emit(
'1$(A)2$(!B)3$(A)4$(B)5', A=
'x')
56 self.
check(e,
'1x2y3x4y5')
61 (a, b) = e.Emit(
'$!A$!B$A$B')
69 e.Emit(
'$A $?B $(C) $(?D)')
70 self.
check(e,
'$A $(C) ')
77 (a, b) = e.Emit(
'[$!A][$!B]$C$D$E', C=
'1', D=
'2')
79 self.
check(e,
'[][]12$E $A$B$C$D')
85 self.
check(e,
'[$A12][21$B]12$E $A$B$C$D')
89 self.
check(e,
'[$A12$C$D][21$B$D$C]12$E $A$B$C$D')
93 e.Emit(
'-$#A(-)-', A=
True)
98 e.Emit(
'-$#A( $#B(-$C-) )-', A=
True, B=
True, C=
'1')
99 self.
check(e,
'- -1- -')
103 e.Emit(
'-$#A( $B )-', A=
False, B=
'1')
108 e.Emit(
'-$#A( $#B(-$C-) )-', A=
False, B=
True, C=
'1')
113 e.Emit(
'-$#A( $#B(-$C-) )-', A=
True, B=
False, C=
'1')
118 e.Emit(
'-$#A(-$#B(-$C-)-)-', C=
'1')
119 self.
check(e,
'-$#A(-$#B(-1-)-)-')
123 e.Emit(
'-$#A(-$B-', A=
True, B=
'1')
124 self.
check(e,
'-$#A(-1-')
129 e.Emit(
'$#A(-)', A=
'Invalid')
131 except RuntimeError
as ex:
133 raise AssertionError(
'Expected error')
136 self.assertEqual(emitter.Format(
'$A$B', A=1, B=2),
'12')
139if __name__ ==
'__main__':
140 logging.config.fileConfig(
'logging.conf')
141 if __name__ ==
'__main__':
def testNestedTemplateMissingBindings(self)
def testTemplateErrorDuplicate(self)
def testNestedTemplatesWithFalse(self)
def check(self, e, expected)
def testNestedTemplates2(self)
def testNestedTemplates(self)
def testNestedTemplatesWithFalse3(self)
def testNestedTemplatesWithFalse2(self)
def testNestedTemplateWithNoRightParen(self)
def testNestedTemplateWithWrongBinding(self)
static SkString join(const CommandLineFlags::StringArray &)