def testDescendShorthand(self): query = "ProcessParent.ProcessParent.ProcessName" expected = expression.Let( expression.Binding("ProcessParent"), expression.Let( expression.Binding("ProcessParent"), expression.Binding("ProcessName"))) self.assertQueryMatches(query, expected)
def testLetSingle(self): query = "Process/parent->Process/command is 'init'" expected = expression.Let( expression.Binding("Process/parent"), expression.Equivalence(expression.Binding("Process/command"), expression.Literal("init"))) self.assertQueryMatches(query, expected)
def testLetSubexpr(self): query = ("Process/parent matches (Process/command is 'init' and " "Process/pid is 1)") expected = expression.Let( expression.Binding("Process/parent"), expression.Intersection( expression.Equivalence(expression.Binding("Process/command"), expression.Literal("init")), expression.Equivalence(expression.Binding("Process/pid"), expression.Literal(1)))) self.assertQueryMatches(query, expected)
def testRealExample(self): original = expression.Intersection( expression.Let( expression.Let(expression.Binding('MemoryDescriptor'), expression.Binding('process')), expression.Equivalence( expression.Let(expression.Binding('Process'), expression.Binding('command')), expression.Literal('Adium'))), expression.Intersection( expression.Membership( expression.Literal('execute'), expression.Let(expression.Binding('MemoryDescriptor'), expression.Binding('permissions'))), expression.Membership( expression.Literal('write'), expression.Let(expression.Binding('MemoryDescriptor'), expression.Binding('permissions'))))) # Two binary intersections become one variadic intersection and the # let-forms now have a Binding as their LHS whenever possible. expected = expression.Intersection( expression.Let( expression.Binding('MemoryDescriptor'), expression.Let( expression.Binding('process'), expression.Equivalence( expression.Let(expression.Binding('Process'), expression.Binding('command')), expression.Literal('Adium')))), expression.Membership( expression.Literal('execute'), expression.Let(expression.Binding('MemoryDescriptor'), expression.Binding('permissions'))), expression.Membership( expression.Literal('write'), expression.Let(expression.Binding('MemoryDescriptor'), expression.Binding('permissions')))) self.assertResult(original, expected)
def testDescendQuery(self): query = "with ProcessParent evaluate (ProcessName)" expected = expression.Let( expression.Binding("ProcessParent"), expression.Binding("ProcessName")) self.assertQueryMatches(query, expected)