Skip to content

Commit

Permalink
support quoted values in conditions (#295)
Browse files Browse the repository at this point in the history
* support quoted values in conditions

* add test cases for quoted values
  • Loading branch information
dirk-thomas authored Sep 28, 2020
1 parent 333ea7e commit 0660801
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/catkin_pkg/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ def _get_condition_expression():
value = pp.Word(pp.alphanums + '_-').setName('value')
value.setParseAction(_Value)

comparison_term = identifier | value
double_quoted_value = pp.QuotedString('"').setName(
'double_quoted_value')
double_quoted_value.setParseAction(_Value)
single_quoted_value = pp.QuotedString("'").setName(
'single_quoted_value')
single_quoted_value.setParseAction(_Value)

comparison_term = identifier | value | double_quoted_value | \
single_quoted_value

condition = pp.Group(comparison_term + operator + comparison_term).setName('condition')
condition.setParseAction(_Condition)
Expand Down
16 changes: 16 additions & 0 deletions test/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ def test_init_dependency(self):
dep = Dependency('foo', condition='foo <= bar or bar >= baz')
self.assertFalse(dep.evaluate_condition({}))

dep = Dependency('foo', condition='$foo == ""')
self.assertTrue(dep.evaluate_condition({}))
self.assertFalse(dep.evaluate_condition({'foo': 'foo'}))

dep = Dependency('foo', condition='$foo == "foo \' bar"')
self.assertTrue(dep.evaluate_condition({'foo': "foo ' bar"}))
self.assertFalse(dep.evaluate_condition({}))

dep = Dependency('foo', condition="$foo == ''")
self.assertTrue(dep.evaluate_condition({}))
self.assertFalse(dep.evaluate_condition({'foo': 'foo'}))

dep = Dependency('foo', condition="$foo == 'foo \" bar'")
self.assertTrue(dep.evaluate_condition({'foo': 'foo " bar'}))
self.assertFalse(dep.evaluate_condition({}))

# Testing for more than 1 conditions
dep = Dependency('foo', condition='foo > bar and bar < baz and foo > bar')
self.assertTrue(dep.evaluate_condition({}))
Expand Down

0 comments on commit 0660801

Please sign in to comment.