This file is indexed.

/usr/share/pyshared/simpleparse/tests/test_common_numbers.py is in python-simpleparse 2.1.0a1-6build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import unittest, string
from simpleparse.parser import Parser
from simpleparse.common import numbers
from simpleparse import dispatchprocessor

_data = [
	(
		"int_unsigned", numbers.IntInterpreter,
		[ # should match, value, length that should match, expected result
			("0 ", 1, 0),
			("1 ", 1, 1),
			("23 ",2, 23),
			("0x ", 1,0),
			("0. ", 1,0),
		],
		[ # should not match...
			".0",
			"a",
		],
	),
	(
		"int", numbers.IntInterpreter,
		[ # should match, value, length that should match, expected result
			("0 ", 1, 0),
			("1 ", 1, 1),
			("23 ",2, 23),
			("0x ", 1,0),
			("0. ", 1,0),
			("+0 ", 2, 0),
			("+1 ", 2, 1),
			("+23 ",3, 23),
			("+0x ", 2,0),
			("+0. ", 2,0),
			("-0 ", 2, 0),
			("-1 ", 2, -1),
			("-23 ",3, -23),
			("-0x ", 2,0),
			("-0. ", 2,0),
		],
		[ # should not match...
			".0",
			"a",
			"+.0",
			"+a",
			"-.0",
			"-a",
		],
	),
	(
		"hex", numbers.HexInterpreter,
		[ # should match, value, length that should match, expected result
			("0x0 ", 3, 0),
			("0x1 ", 3, 1),
			("0x23 ",4, 35),
			("0x0x ", 3,0),
			("0x0. ", 3,0),
			("+0x0 ", 4, 0),
			("+0x1 ", 4, 1),
			("+0x23 ",5, 35),
			("+0x0x ", 4,0),
			("+0x0. ", 4,0),
			("-0x0 ", 4, 0),
			("-0x1 ", 4, -1),
			("-0x23 ",5, -35),
			("-0x0x ", 4,0),
			("-0x0. ", 4,0),
			("0xa ", 3, 10),
			("0xaaaaaaaaaaaaaaaaa ", 19, 196765270119568550570L),
			("0xA ", 3, 10),
			("0xAAAAAAAAAAAAAAAAA ", 19, 196765270119568550570L),
		],
		[ # should not match...
			".0",
			"a",
			"+.0",
			"+a",
			"-.0",
			"-a",
			"0x ",
			"0xg",
			"0x",
		],
	),
	(
		"binary_number", numbers.BinaryInterpreter,
		[ # should match, value, length that should match, expected result
			("0b0 ", 2, 0),
			("1b0 ", 2, 1),
			("10b0 ", 3, 2),
			("10000000000b0 ", 12, 1024),
			("0B0 ", 2, 0),
			("1B0 ", 2, 1),
			("10B0 ", 3, 2),
			("10000000000B0 ", 12, 1024),
		],
		[ # should not match...
			".0",
			"a",
			"+.0",
			"+a",
			"-.0",
			"-a",
			"0x ",
			"0xg",
			"0x",
		],
	),
	(
		"float", numbers.FloatInterpreter,
		[ # should match, value, length that should match, expected result
			("0. ", 2, 0),
			("1. ", 2, 1),
			("23. ",3, 23),
			(".0 ", 2, 0),
			(".1 ", 2, .1),
			(".23 ",3, .23),
			("0.0x ", 3,0),
			("1.1x ", 3,1.1),
			("2000000.22222222x ", 16, 2000000.22222222),
			("1.1e20 ", 6, 1.1e20),
			("1.1e-20 ",7, 1.1e-20),
			("-1.1e20 ", 7, -1.1e20),
		],
		[ # should not match...
			"0x.0",
			"23",
			"-23",
			"-43*2a",
			"+23",
			"-a",
		],
	),
	(
		"float_floatexp", numbers.FloatFloatExpInterpreter,
		[ # should match, value, length that should match, expected result
			("0. ", 2, 0),
			("1. ", 2, 1),
			("23. ",3, 23),
			(".0 ", 2, 0),
			(".1 ", 2, .1),
			(".23 ",3, .23),
			("0.0x ", 3,0),
			("1.1x ", 3,1.1),
			("2000000.22222222x ", 16, 2000000.22222222),
			("1.1e20 ", 6, 1.1* (1e20)),
			("1.1e-20 ",7, 1.1* (1e-20)),
			("-1.1e20 ", 7, -1.1* (1e20)),
			("1.1e20.34 ", 9, 1.1* (10 ** 20.34)),
			("1.1e-.34 ", 8, 1.1*( 10 ** -.34)),
		],
		[ # should not match...
			"0x.0",
			"23",
			"-23",
			"-43*2a",
			"+23",
			"-a",
		],
	),
]		
	 

class CommonTests(unittest.TestCase):
	def testBasic( self ):
		for production, processor, yestable, notable in _data:
			p = Parser( "x := %s"%production, 'x')
			proc = dispatchprocessor.DispatchProcessor()
			setattr(proc, production, processor())
			for data, length, value in yestable:
				success, results, next = p.parse( data, processor = proc)
				assert next == length, """Did not parse string %s of %s as a %s result=%s"""%( repr(data[:length]), repr(data), production, (success, results, next))
				assert results[0] == value, """Didn't get expected value from processing value %s, expected %s, got %s"""%( data[:length], value, results[0])
				
			for data in notable:
				success, results, next = p.parse( data)
				assert not success, """Parsed %s of %s as a %s result=%s"""%( repr(data[:length]), repr(data), production, (success, results, next))
				
		
		
def getSuite():
	return unittest.makeSuite(CommonTests, 'test')

if __name__ == "__main__":
	unittest.main(defaultTest="getSuite")