From a21122621a47bee0442aa99760b6a8d7886e6dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0pl=C3=ADchal?= Date: Thu, 31 Oct 2024 14:22:10 +0100 Subject: [PATCH] Allow dashes in context dimension names 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. --- docs/context.rst | 2 +- fmf/context.py | 4 ++-- tests/unit/test_context.py | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/context.rst b/docs/context.rst index 5250653..1d5da02 100644 --- a/docs/context.rst +++ b/docs/context.rst @@ -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' diff --git a/fmf/context.py b/fmf/context.py index 7ba7170..d6806a3 100644 --- a/fmf/context.py +++ b/fmf/context.py @@ -397,7 +397,7 @@ 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"]]) @@ -405,7 +405,7 @@ def _op_core(self, dimension_name, values, comparator): + 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 diff --git a/tests/unit/test_context.py b/tests/unit/test_context.py index 915d57c..a7bfd55 100644 --- a/tests/unit/test_context.py +++ b/tests/unit/test_context.py @@ -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 """