From 320129e26c4125301b90ae44ccf8210067422591 Mon Sep 17 00:00:00 2001 From: Michael Chisholm Date: Thu, 13 Aug 2020 18:45:52 -0400 Subject: [PATCH] Add another unit test to help a bit with lack of coverage of compare/comparison.py. This one tests patterns with more constant types. --- stix2/test/test_pattern_equivalence.py | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/stix2/test/test_pattern_equivalence.py b/stix2/test/test_pattern_equivalence.py index c75cc60..6fc2adf 100644 --- a/stix2/test/test_pattern_equivalence.py +++ b/stix2/test/test_pattern_equivalence.py @@ -578,6 +578,35 @@ def test_comp_special_canonicalization_win_reg_key_not_equivalent(patt1, patt2): assert not equivalent_patterns(patt1, patt2) +def test_comp_other_constant_types(): + constants = [ + "1.23", + "1", + "true", + "false", + "h'4fa2'", + "b'ZmpoZWll'", + "t'1982-12-31T02:14:17.232Z'", + ] + + pattern_template = "[a:b={}]" + for i, const1 in enumerate(constants): + for j, const2 in enumerate(constants): + patt1 = pattern_template.format(const1) + patt2 = pattern_template.format(const2) + + if i == j: + assert equivalent_patterns(patt1, patt2) + else: + assert not equivalent_patterns(patt1, patt2) + + # can't use an "=" pattern with lists... + for const in constants: + patt1 = "[a:b={}]".format(const) + patt2 = "[a:b IN (1,2,3)]" + assert not equivalent_patterns(patt1, patt2) + + # # # # # # find_equivalent_patterns() tests # # # # # #