package com.atlassian.stash.internal.web.soy.functions;

import org.junit.Test;

import java.util.Date;

import static org.junit.Assert.assertEquals;

public class ToIntFunctionTest {

    @Test
    public void testNumbers() {
        assertEquals(new ToIntFunction().apply("1"), new Integer(1));
        assertEquals(new ToIntFunction().apply("0"), new Integer(0));
        assertEquals(new ToIntFunction().apply("-1"), new Integer(-1));
        assertEquals(new ToIntFunction().apply("100"), new Integer(100));
        assertEquals(new ToIntFunction().apply(100), new Integer(100));
        assertEquals(new ToIntFunction().apply(Integer.MAX_VALUE), new Integer(Integer.MAX_VALUE));
        assertEquals(new ToIntFunction().apply(Integer.MIN_VALUE), new Integer(Integer.MIN_VALUE));
    }

    @Test(expected = NullPointerException.class)
    public void testNull() {
        new ToIntFunction().apply(null);
    }

    @Test(expected = NumberFormatException.class)
    public void testNonNumberStringInput() {
        new ToIntFunction().apply("Not a number");
    }

    @Test(expected = NumberFormatException.class)
    public void testNonStringInput() {
        new ToIntFunction().apply(new Date());
    }

}
