PageRenderTime 36ms CodeModel.GetById 13ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/libtest/StringTest.py

http://pyjamas.googlecode.com/
Python | 88 lines | 76 code | 12 blank | 0 comment | 0 complexity | 5acfae9d0caf7085ace820efeba38ef3 MD5 | raw file
 1from UnitTest import UnitTest
 2
 3class StringTest(UnitTest):
 4	def __init__(self):
 5		UnitTest.__init__(self)
 6
 7	def getName(self):
 8		return "String"
 9
10	def testReplace(self):
11		text="this is a rather long string"
12		expected_result1="th--- --- a rather long string"
13		expected_result2="thi-- is a rather long string"
14		expected_result3="this_is_a_rather_long_string"
15		
16		result=text.replace("is", "---")
17		self.assertEquals(result, expected_result1)
18
19		result=text.replace("s", "--", 1)
20		self.assertEquals(result, expected_result2)
21
22		result=text.replace(" ", "_")
23		self.assertEquals(result, expected_result3)
24		
25	def testFind(self):
26		text="this is a rather long string"
27
28		result=text.find("not found")
29		self.assertEquals(result, -1)
30
31		result=text.find("is")
32		self.assertEquals(result, 2)
33		
34		result=text.find("is", 3)
35		self.assertEquals(result, 5)
36		
37		result=text.find("is", 2, 3)
38		self.assertEquals(result, -1)
39
40	def testJoin(self):
41		data="this is a rather long string"
42		data=data.split(" ")
43		sep1=", "
44		sep2=""
45		expected_result1="this, is, a, rather, long, string"
46		expected_result2="thisisaratherlongstring"
47		
48		result=sep1.join(data)
49		self.assertEquals(result, expected_result1)
50		
51		result=sep2.join(data)
52		self.assertEquals(result, expected_result2)
53
54	def testSplit(self):
55		text=" this is  a rather long string  "
56		space=" "
57		empty=""
58		expected_result1=" this is  a rather long string "
59		expected_result2="thisis  a rather long string  "
60		expected_result3="this is a rather long string"
61		
62		result=space.join(text.split(space))
63		self.assertEquals(result, expected_result1)
64		
65		result=empty.join(text.split(space, 2))
66		self.assertEquals(result, expected_result2)
67		
68		result=space.join(text.split())
69		self.assertEquals(result, expected_result3)
70		
71		result=empty.split()
72		self.assertEquals(len(result), 0)
73		
74	def testStrip(self):
75		text=" this is  a rather long string  "
76		expected_result1="this is  a rather long string"
77		expected_result2="a rather long string"
78		
79		result=text.strip()
80		self.assertEquals(result, expected_result1)
81		
82		result=text.strip(" sthi")
83		self.assertEquals(result, expected_result2)
84
85		
86		
87		
88