Package lepl :: Package matchers :: Package _test :: Module combine
[hide private]
[frames] | no frames]

Source Code for Module lepl.matchers._test.combine

  1  # The contents of this file are subject to the Mozilla Public License 
  2  # (MPL) Version 1.1 (the "License"); you may not use this file except 
  3  # in compliance with the License. You may obtain a copy of the License 
  4  # at http://www.mozilla.org/MPL/ 
  5  # 
  6  # Software distributed under the License is distributed on an "AS IS" 
  7  # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
  8  # the License for the specific language governing rights and 
  9  # limitations under the License. 
 10  # 
 11  # The Original Code is LEPL (http://www.acooke.org/lepl) 
 12  # The Initial Developer of the Original Code is Andrew Cooke. 
 13  # Portions created by the Initial Developer are Copyright (C) 2009-2010 
 14  # Andrew Cooke (andrew@acooke.org). All Rights Reserved. 
 15  # 
 16  # Alternatively, the contents of this file may be used under the terms 
 17  # of the LGPL license (the GNU Lesser General Public License, 
 18  # http://www.gnu.org/licenses/lgpl.html), in which case the provisions 
 19  # of the LGPL License are applicable instead of those above. 
 20  # 
 21  # If you wish to allow use of your version of this file only under the 
 22  # terms of the LGPL License and not to allow others to use your version 
 23  # of this file under the MPL, indicate your decision by deleting the 
 24  # provisions above and replace them with the notice and other provisions 
 25  # required by the LGPL License.  If you do not delete the provisions 
 26  # above, a recipient may use your version of this file under either the 
 27  # MPL or the LGPL License. 
 28   
 29  ''' 
 30  Tests for the combining matchers. 
 31  ''' 
 32   
 33  #from logging import basicConfig, DEBUG 
 34  from unittest import TestCase 
 35   
 36  from lepl.matchers.combine import DepthFirst, BreadthFirst, Difference, Limit 
 37  from lepl.matchers.core import Any 
 38  from lepl.matchers.derived import Integer, Real 
 39  from lepl._test.base import BaseTest 
 40   
 41   
42 -class DirectionTest1(TestCase):
43
44 - def matcher(self):
45 return Any()
46
47 - def test_depth(self):
48 #basicConfig(level=DEBUG) 49 matcher = DepthFirst(self.matcher(), 1, 2) 50 matcher.config.no_full_first_match() 51 matcher = matcher.get_match() 52 results = list(map(''.join, map(lambda x: x[0], matcher('123')))) 53 assert results == ['12', '1'], results
54
55 - def test_breadth(self):
56 matcher = BreadthFirst(self.matcher(), 1, 2) 57 matcher.config.no_full_first_match() 58 matcher = matcher.get_match() 59 results = list(map(''.join, map(lambda x: x[0], matcher('123')))) 60 assert results == ['1', '12'], results
61 62
63 -class DirectionTest2(TestCase):
64
65 - def matcher(self):
66 return ~Any()[:] & Any()
67
68 - def test_depth(self):
69 matcher = DepthFirst(self.matcher(), 1, 2) 70 matcher.config.no_full_first_match() 71 matcher = matcher.get_match() 72 results = list(map(''.join, map(lambda x: x[0], matcher('123')))) 73 assert results == ['3', '23', '2', '13', '12', '1'], results
74
75 - def test_breadth(self):
76 matcher = BreadthFirst(self.matcher(), 1, 2) 77 matcher.config.no_full_first_match() 78 matcher = matcher.get_match() 79 results = list(map(''.join, map(lambda x: x[0], matcher('123')))) 80 assert results == ['3', '2', '1', '23', '13', '12'], results
81 82
83 -class DifferenceTest(BaseTest):
84
85 - def test_difference(self):
86 #basicConfig(level=DEBUG) 87 matcher = Difference(Real(), Integer()) 88 self.assert_direct('12.3', matcher, [['12.3'], ['12.']])
89
90 - def test_count(self):
91 #basicConfig(level=DEBUG) 92 matcher = Difference(Real(), Integer(), count=1) 93 self.assert_direct('12.3', matcher, [['12.3'], ['12.'], ['1']])
94 95
96 -class LimitTest(BaseTest):
97
98 - def test_limit(self):
99 self.assert_direct('1.2', Real(), [['1.2'], ['1.'], ['1']]) 100 self.assert_direct('1.2', Limit(Real(), 1), [['1.2']]) 101 self.assert_direct('1.2', Limit(Real(), 2), [['1.2'], ['1.']]) 102 self.assert_direct('1.2', Limit(Real(), 0), [])
103