package org.musetest.builtins.condition;

import org.musetest.core.*;
import org.musetest.core.context.*;
import org.musetest.core.events.*;
import org.musetest.core.resource.*;
import org.musetest.core.steptest.*;
import org.musetest.core.values.*;
import org.musetest.core.values.descriptor.*;

import java.util.*;

/**
 * @author Christopher L Merrill (see LICENSE.txt for license details)
 */
@MuseTypeId("equals")
@MuseValueSourceName("Equals (=)")
@MuseValueSourceInstanceDescription("{source(left)} = {source(right)}")
@MuseValueSourceTypeGroup("Math")
@MuseValueSourceShortDescription("Compare two sources for equality")
@MuseValueSourceLongDescription("Compare two sources, return true if equal. Object.equals() is used for the comparison.")
public class EqualityCondition extends BinaryCondition
    {
    @SuppressWarnings("unused")  // used via reflection
    public EqualityCondition(ValueSourceConfiguration config, MuseProject project) throws MuseInstantiationException
        {
        super(config, project);
        }

    @Override
    public Boolean resolveValue(StepExecutionContext context) throws StepConfigurationError
        {
        Object value1 = _left.resolveValue(context);
        Object value2 = _right.resolveValue(context);
        boolean result = Objects.equals(value1, value2);

        context.getTestExecutionContext().raiseEvent(new ConditionEvaluatedEvent(String.format("Condition (%s=%s) is %b", value1, value2, result)));
        return result;
        }

    @Override
    public String getDescription()
        {
        return String.format("%s = %s", _left.getDescription(), _right.getDescription());
        }

    public final static String TYPE_ID = EqualityCondition.class.getAnnotation(MuseTypeId.class).value();
    }



@@ -443,16 +443,17 @@
 quals (=
+=
 )%22)%0A@Mus
@@ -501,16 +501,17 @@
 left)%7D =
+=
  %7Bsource
@@ -1423,17 +1423,20 @@
 tion (%25s
-=
+ == 
 %25s) is %25
@@ -1593,16 +1593,17 @@
 at(%22%25s =
+=
  %25s%22, _l

add support for binary expressions