package sterling.lang.expression;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static sterling.lang.expression.BooleanMatcher.isFalse;
import static sterling.lang.expression.ExpressionConversions.convertBoolean;
import static sterling.lang.expression.ExpressionConversions.convertInteger;
import static sterling.lang.expression.ExpressionConversions.convertString;
import static sterling.lang.expression.ExpressionConversions.convertSymbol;
import static sterling.lang.expression.ExpressionFactory.constant;
import static sterling.lang.expression.NothingConstant.NULL;

import org.junit.Test;
import sterling.lang.SterlingException;
import sterling.lang.expression.exception.UndefinedMemberException;

public class NothingConstantTest {

    @Test
    public void shouldNotBeTrue_whenConvertedToBoolean() throws SterlingException {
        assertThat(convertBoolean(NULL), isFalse());
    }

    @Test
    public void shouldBeZero_whenConvertedToInteger() throws SterlingException {
        assertThat(convertInteger(NULL), equalTo(constant(0)));
    }

    @Test
    public void shouldBeNothing_whenConvertedToString() throws SterlingException {
        assertThat(convertString(NULL), equalTo(constant("")));
    }

    @Test(expected = UndefinedMemberException.class)
    public void shouldThrowException_whenConvertedToSymbol() throws SterlingException {
        convertSymbol(NULL);
    }

    @Test
    public void shouldShowName_whenToString() {
        assertThat(NULL.toString(), equalTo("(NothingConstant)"));
    }
}
