@@ -55,6 +55,56 @@ def test_template_basic_creation(self):
55
55
self .assertEqual (len (t .interpolations ), 0 )
56
56
self .assertEqual (f (t ), "Hello,\n world" )
57
57
58
+ def test_template_creation_interleaving (self ):
59
+ # Should add strings on either side
60
+ t = Template (Interpolation ("Maria" , "name" , None , "" ))
61
+ self .assertEqual (t .strings , ("" , "" ))
62
+ self .assertEqual (t .interpolations [0 ].value , "Maria" )
63
+ self .assertEqual (t .interpolations [0 ].expression , "name" )
64
+ self .assertEqual (t .interpolations [0 ].conversion , None )
65
+ self .assertEqual (t .interpolations [0 ].format_spec , "" )
66
+ self .assertEqual (f (t ), "Maria" )
67
+
68
+ # Should prepend empty string
69
+ t = Template (Interpolation ("Maria" , "name" , None , "" ), " is my name" )
70
+ self .assertEqual (t .strings , ("" , " is my name" ))
71
+ self .assertEqual (t .interpolations [0 ].value , "Maria" )
72
+ self .assertEqual (t .interpolations [0 ].expression , "name" )
73
+ self .assertEqual (t .interpolations [0 ].conversion , None )
74
+ self .assertEqual (t .interpolations [0 ].format_spec , "" )
75
+ self .assertEqual (f (t ), "Maria is my name" )
76
+
77
+ # Should append empty string
78
+ t = Template ("Hello, " , Interpolation ("Maria" , "name" , None , "" ))
79
+ self .assertEqual (t .strings , ("Hello, " , "" ))
80
+ self .assertEqual (t .interpolations [0 ].value , "Maria" )
81
+ self .assertEqual (t .interpolations [0 ].expression , "name" )
82
+ self .assertEqual (t .interpolations [0 ].conversion , None )
83
+ self .assertEqual (t .interpolations [0 ].format_spec , "" )
84
+ self .assertEqual (f (t ), "Hello, Maria" )
85
+
86
+ # Should concatenate strings
87
+ t = Template ("Hello" , ", " , Interpolation ("Maria" , "name" , None , "" ), "!" )
88
+ self .assertEqual (t .strings , ("Hello, " , "!" ))
89
+ self .assertEqual (t .interpolations [0 ].value , "Maria" )
90
+ self .assertEqual (t .interpolations [0 ].expression , "name" )
91
+ self .assertEqual (t .interpolations [0 ].conversion , None )
92
+ self .assertEqual (t .interpolations [0 ].format_spec , "" )
93
+ self .assertEqual (f (t ), "Hello, Maria!" )
94
+
95
+ # Should add strings on either side and in between
96
+ t = Template (Interpolation ("Maria" , "name" , None , "" ), Interpolation ("Python" , "language" , None , "" ))
97
+ self .assertEqual (t .strings , ("" , "" , "" ))
98
+ self .assertEqual (t .interpolations [0 ].value , "Maria" )
99
+ self .assertEqual (t .interpolations [0 ].expression , "name" )
100
+ self .assertEqual (t .interpolations [0 ].conversion , None )
101
+ self .assertEqual (t .interpolations [0 ].format_spec , "" )
102
+ self .assertEqual (t .interpolations [1 ].value , "Python" )
103
+ self .assertEqual (t .interpolations [1 ].expression , "language" )
104
+ self .assertEqual (t .interpolations [1 ].conversion , None )
105
+ self .assertEqual (t .interpolations [1 ].format_spec , "" )
106
+ self .assertEqual (f (t ), "MariaPython" )
107
+
58
108
def test_string_representation (self ):
59
109
# Test __repr__
60
110
t = t "Hello"
0 commit comments