def test_combined_condition_expression(self): script = dedent(""" Company((name ~ 'google') & !(name ~ 'microsoft')); """) exe = engine.compile_norm(script) cmd = exe.stack.pop() google = engine.BaseExpr('constant', engine.Constant('string', 'google')) microsoft = engine.BaseExpr('constant', engine.Constant('string', 'microsoft')) condition1 = engine.ConditionExpr('name', '~', google) condition2 = engine.ConditionExpr('name', '~', microsoft) condition = engine.ConditionCombinedExpr('&', condition1, engine.ConditionCombinedExpr('!', condition2, None)) self.assertEqual(cmd.type_name, engine.TypeName('Company', None)) self.assertEqual(cmd.args, engine.ListExpr([engine.ArgumentExpr(condition, None)]))
def test_property_access_expression(self): script = dedent(""" Company(name ~ 'google').founders; """) exe = engine.compile_norm(script) cmd = exe.stack.pop() google = engine.BaseExpr('constant', engine.Constant('string', 'google')) condition = engine.ConditionExpr('name', '~', google) self.assertEqual(cmd.expr, engine.EvaluationExpr(engine.TypeName('Company', None), None, engine.ListExpr([engine.ArgumentExpr(condition, None)]), None)) self.assertEqual(cmd.property, 'founders')
def test_condition_assignment_expression(self): script = dedent(""" a = Company(name ~ 'google')?*; """) exe = engine.compile_norm(script) cmd = exe.stack.pop() google = engine.BaseExpr('constant', engine.Constant('string', 'google')) condition = engine.ConditionExpr('name', '~', google) self.assertEqual(cmd.variable_name, 'a') self.assertEqual(cmd.expr, engine.EvaluationExpr(engine.TypeName('Company', None), None, engine.ListExpr([engine.ArgumentExpr(condition, None)]), engine.Projection(1000000, None)))
def test_aggregation_function_expression(self): script = dedent(""" Company(name ~ 'google')?*.Group(by="founders"); """) exe = engine.compile_norm(script) cmd = exe.stack.pop() google = engine.BaseExpr('constant', engine.Constant('string', 'google')) condition = engine.ConditionExpr('name', '~', google) assignment = engine.AssignmentExpr('by', engine.BaseExpr('constant', engine.Constant('string', 'founders'))) self.assertEqual(cmd.qexpr, engine.EvaluationExpr(engine.TypeName('Company', None), None, engine.ListExpr([engine.ArgumentExpr(condition, None)]), engine.Projection(1000000, None))) self.assertEqual(cmd.eexpr, engine.EvaluationExpr(engine.TypeName('Group', None), None, engine.ListExpr([engine.ArgumentExpr(assignment, None)]), None))
def test_combined_evaluation_expression(self): script = dedent(""" Company(name ~ 'google')?comp & Develop(comp, 'AI'); """) exe = engine.compile_norm(script) cmd = exe.stack.pop() google = engine.BaseExpr('constant', engine.Constant('string', 'google')) ai = engine.BaseExpr('constant', engine.Constant('string', 'AI')) comp = engine.BaseExpr('variable', value='comp') condition = engine.ConditionExpr('name', '~', google) expr1 = engine.EvaluationExpr(engine.TypeName('Company', None), None, engine.ListExpr([engine.ArgumentExpr(condition, None)]), engine.Projection(None, 'comp')) expr2 = engine.EvaluationExpr(engine.TypeName('Develop', None), None, engine.ListExpr([engine.ArgumentExpr(comp, None), engine.ArgumentExpr(ai, None)]), None) self.assertEqual(cmd.op, '&') self.assertEqual(cmd.expr1, expr1) self.assertEqual(cmd.expr2, expr2)