Skip to content

Commit

Permalink
Allow dashes in context dimension names (#255)
Browse files Browse the repository at this point in the history
It's quite common to name multi-word keys with dashes instead of
underscores. Let's allow dashes in the context dimension names as
well.
  • Loading branch information
psss authored Jan 24, 2025
1 parent 125584f commit 3c1b7c1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/context.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ supported operators consult the following grammar outline::
expression ::= dimension binary_operator values
expression ::= dimension unary_operator
expression ::= 'true' | 'false'
dimension ::= [[:alnum:]]+
dimension ::= [[:alnum:-]]+
binary_operator ::= '==' | '!=' | '<' | '<=' | '>' | '>=' |
'~=' | '~!=' | '~<' | '~<=' | '~>' | '~>=' | '~' | '!~'
unary_operator ::= 'is defined' | 'is not defined'
Expand Down
4 changes: 2 additions & 2 deletions fmf/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,15 @@ def _op_core(self, dimension_name, values, comparator):
# Triple expression: dimension operator values
# [^=].* is necessary as .+ matches '= something'
re_expression_triple = re.compile(
r"(\w+)"
r"([\w-]+)"
+ r"\s*("
+ r"|".join(
[key for key in operator_map if key not in ["is defined", "is not defined"]])
+ r")\s*"
+ r"([^=].*)")
# Double expression: dimension operator
re_expression_double = re.compile(
r"(\w+)" + r"\s*(" + r"|".join(["is defined", "is not defined"]) + r")"
r"([\w-]+)" + r"\s*(" + r"|".join(["is defined", "is not defined"]) + r")"
)

# Simple boolean value
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ def test_split_expression(self):
assert Context.split_expression("dim < value , second") == (
"dim", "<", ["value", "second"])
assert Context.split_expression("true") == (None, True, None)
assert Context.split_expression("provision-method == local") == (
"provision-method", "==", ["local"])
assert Context.split_expression("provision-method is defined") == (
"provision-method", "is defined", None)

def test_parse_rule(self):
""" Rule parsing """
Expand Down

0 comments on commit 3c1b7c1

Please sign in to comment.