|
9 | 9 | from bob.stringparser import StringParser |
10 | 10 | from bob.stringparser import funEqual, funNotEqual, funNot, funOr, \ |
11 | 11 | funAnd, funMatch, funIfThenElse, funSubst, funStrip, \ |
12 | | - funSandboxEnabled, funToolDefined, funToolEnv |
| 12 | + funSandboxEnabled, funToolDefined, funToolEnv, funResubst |
13 | 13 | from bob.errors import ParseError |
14 | 14 |
|
15 | 15 | def echo(args, **options): |
@@ -197,6 +197,10 @@ def testMatch(self): |
197 | 197 | self.assertRaises(ParseError, funMatch, ["a","b","x"]) |
198 | 198 | self.assertRaises(ParseError, funMatch, ["a","b","i","y"]) |
199 | 199 |
|
| 200 | + # broken regex |
| 201 | + with self.assertRaises(ParseError): |
| 202 | + funMatch(["b", r'\c']) |
| 203 | + |
200 | 204 | def testIfThenElse(self): |
201 | 205 | self.assertRaises(ParseError, funIfThenElse, ["a", "b"]) |
202 | 206 | self.assertEqual(funIfThenElse(["true", "a", "b"]), "a") |
@@ -252,3 +256,23 @@ def testToolEnv(self): |
252 | 256 | # Get real var |
253 | 257 | self.assertEqual(funToolEnv(["foo", "bar"], __tools=tools), "baz") |
254 | 258 | self.assertEqual(funToolEnv(["foo", "bar", "def"], __tools=tools), "baz") |
| 259 | + |
| 260 | + def testResubst(self): |
| 261 | + # Wrong number of arguments |
| 262 | + with self.assertRaises(ParseError): |
| 263 | + funResubst(["foo", "bar"]) |
| 264 | + with self.assertRaises(ParseError): |
| 265 | + funResubst(["foo", "bar", "baz", "extra", "toomuch"]) |
| 266 | + |
| 267 | + # Unsupported flag |
| 268 | + with self.assertRaises(ParseError): |
| 269 | + funResubst(["a", "b", "abc", "%"]) |
| 270 | + |
| 271 | + # broken regex |
| 272 | + with self.assertRaises(ParseError): |
| 273 | + funResubst([r'\c', "b", "abc"]) |
| 274 | + |
| 275 | + self.assertEqual(funResubst(["X", "Y", "AXBXCX"]), "AYBYCY") |
| 276 | + self.assertEqual(funResubst([r"\.[^.]+$", "", "1.2.3"]), "1.2") |
| 277 | + self.assertEqual(funResubst(["[X]", "Y", "AXBx"]), "AYBx") |
| 278 | + self.assertEqual(funResubst(["[x]", "Y", "AXBx", "i"]), "AYBY") |
0 commit comments