def test_double_quoted_strings(self): out = self._parse('foo="bar"') expect = ast.Query( ast.Comparison('=', ast.IdentifierPath([ ast.Identifier('foo'), ]), ast.Literal('bar'))) self.assertEqual(repr(out), repr(expect))
def test_logical_operators(self): out = self._parse('foo=1 or (bar=2 and baz=3)') expect = ast.Query( ast.OrExpression( ast.Comparison('=', ast.IdentifierPath([ast.Identifier('foo')]), ast.Literal(1)), ast.ParenthesizedExpression( ast.AndExpression( ast.Comparison( '=', ast.IdentifierPath([ast.Identifier('bar')]), ast.Literal(2)), ast.Comparison( '=', ast.IdentifierPath([ast.Identifier('baz')]), ast.Literal(3)))))) self.assertEqual(repr(out), repr(expect))
def test_negate_expression(self): out = self._parse('not foo=bar') expect = ast.Query( ast.NotExpression( ast.Comparison('=', ast.IdentifierPath([ast.Identifier('foo')]), ast.Literal('bar')))) self.assertEqual(repr(out), repr(expect))
def test_resource_queries_with_type_title_and_parameters(self): out = self._parse('file[foo]{bar=baz}') expect = ast.Query( ast.Resource( 'file', ast.Identifier('foo'), False, ast.BlockExpression( ast.Comparison('=', ast.IdentifierPath([ast.Identifier('bar')]), ast.Literal('baz'))))) self.assertEqual(repr(out), repr(expect))
def test_dates_in_queries(self): out = self._parse('#node.report_timestamp<@"Sep 9, 2014"') expect = ast.Query( ast.Subquery( 'node', ast.Comparison( '<', ast.IdentifierPath([ast.Identifier('report_timestamp')]), ast.Date('Sep 9, 2014')))) self.assertEqual(repr(out), repr(expect))
def test_node_subqueries(self): out = self._parse('#node.catalog_environment=production') expect = ast.Query( ast.Subquery( 'node', ast.Comparison( '=', ast.IdentifierPath([ast.Identifier('catalog_environment') ]), ast.Literal('production')))) self.assertEqual(repr(out), repr(expect))
def test_structured_facts_with_wildcard_operator(self): out = self._parse('foo.bar.*=baz') expect = ast.Query( ast.Comparison( '=', ast.IdentifierPath([ ast.Identifier('foo'), ast.Identifier('bar'), ast.RegexpIdentifier('.*') ]), ast.Literal('baz'))) self.assertEqual(repr(out), repr(expect))
def test_node_subqueries_with_block_of_conditions(self): out = self._parse('#node { catalog_environment=production }') expect = ast.Query( ast.Subquery( 'node', ast.BlockExpression( ast.Comparison( '=', ast.IdentifierPath( [ast.Identifier('catalog_environment')]), ast.Literal('production'))))) self.assertEqual(repr(out), repr(expect))
def test_float_values(self): out = self._parse('foo=1.024') expect = ast.Query( ast.Comparison('=', ast.IdentifierPath([ast.Identifier('foo')]), ast.Literal(1.024))) self.assertEqual(repr(out), repr(expect))
def test_boolean_values(self): out = self._parse('foo=true') expect = ast.Query( ast.Comparison('=', ast.IdentifierPath([ast.Identifier('foo')]), ast.Literal(True))) self.assertEqual(repr(out), repr(expect))