import unittest
import sys
import camel
import itertools
class Test(unittest.TestCase):
def check(self,result,answer):
for r,a in itertools.izip_longest(result,answer):
if r!=a:
print('%s != %s'%(r,a))
self.assertTrue(r==a)
def test_piece_emitter(self):
tests=(("a_foobar_FooBar baz? golf_CART Foo 'food' getFooBaz",
((0,'a'),
(2,'foobar'),
(9,'FooBar'),
(16,'baz'),
(21,'golf'),
(26,'CART'),
(31,'Foo'),
(36,'food'),
(42,'getFooBaz'),
)
),
)
for text,answer in tests:
result=list(camel.piece_emitter(text))
print(result)
self.check(result,answer)
def test_camel_splitter(self):
tests=(('getFooBar',('get','Foo','Bar')),
('getFOObar',('get','FOO','bar')),
('Foo',('Foo',)),
('getFoo',('get','Foo')),
('foobar',('foobar',)),
('fooBar',('foo','Bar')),
('FooBar',('Foo','Bar')),
('a',('a',)),
('fooB',('foo','B')),
('FooB',('Foo','B')),
('FOOb',('FOO','b')),
)
for word,answer in tests:
result=camel.camel_splitter(word)
self.check(result,answer)
def test_word_emitter(self):
tests=(("a",
((0,'a'),) ),
('getFooBar',
((0,'get'),
(0,'getFoo'),
(0,'getFooBar'),
(3,'Foo'),
(3,'FooBar'),
(6,'Bar'),
)
)
)
for text,answer in tests:
result=list(camel.word_emitter(text))
print(result)
self.check(result,answer)
def test_camel_search(self):
tests=(("a_foobar_FooBar baz? golf_CART Foo 'food' getFooBaz",
("a", "foo", "bar", "baz", "golf", "cart", "fred", "food",
'FooBaz'),
((0,'a'),
(9,'Foo'),
(12,'Bar'),
(16,'baz'),
(21,'golf'),
(26,'CART'),
(36,'food'),
(45,'FooBaz'),
(None,'fred')
)
),
("\"Foo\"",('Foo',),((1,'Foo'),)),
("getFooBar",('FooBar',),((3,'FooBar'),)),
)
for text,search_words,answer in tests:
result=list(camel.camel_search(text,search_words))
print(result)
self.check(result,answer)
if __name__ == '__main__':
unittest.main(argv = unittest.sys.argv + ['--verbose'])