package net.happygiraffe.jslint;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.ScriptableObject;

import junit.framework.TestCase;

/**
 * @author dom
 * @version $Id$
 */
public class UtilTest extends TestCase {

    private Context cx;

    private ScriptableObject scope;

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        cx = Context.enter();
        cx.setLanguageVersion(Context.VERSION_1_5);
        scope = cx.initStandardObjects();
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();

        Context.exit();
    }

    public void testBooleanValueFromJava() throws Exception {
        scope.put("ok", scope, new Boolean(true));
        assertEquals(true, Util.booleanValue("ok", scope));
    }

    public void testBooleanValueFromJavaScript() throws Exception {
        cx.evaluateString(scope, "var ok = true", "-", 1, null);
        assertEquals(true, Util.booleanValue("ok", scope));
    }

    public void testBooleanValueOfUndefined() throws Exception {
        assertEquals(false, Util.booleanValue("ok", scope));
    }

    public void testIntValueFromJava() throws Exception {
        scope.put("foo", scope, new Integer(42));
        assertEquals(42, Util.intValue("foo", scope));
    }

    public void testIntValueFromJavaScript() throws Exception {
        cx.evaluateString(scope, "var foo = 42", "-", 1, null);
        assertEquals(42, Util.intValue("foo", scope));
    }

    public void testIntValueOfUndefined() {
        assertEquals(0, Util.intValue("foo", scope));
    }

    public void testStringValueFromJava() throws Exception {
        scope.put("foo", scope, "bar");
        assertEquals("bar", Util.stringValue("foo", scope));
    }
    
    public void testStringValueFromJavaScript() throws Exception {
        cx.evaluateString(scope, "var foo = 'bar'", "-", 1, null);
        assertEquals("bar", Util.stringValue("foo", scope));
    }

    public void testStringValueOfUndefined() {
        assertEquals(null, Util.stringValue("foo", scope));
    }
}

@@ -23,24 +23,73 @@
 fe.jslint;%0A%0A
+import java.util.EnumSet;%0Aimport java.util.Set;%0A%0A
 import org.m
@@ -1648,32 +1648,882 @@
 scope));%0A    %7D%0A%0A
+    public void testOptionSetToObjectLiteralWithNoOptions() throws Exception %7B%0A        Set%3COption%3E opts = EnumSet.noneOf(Option.class);%0A        assertEquals(%22%7B%7D%22, Util.optionSetToObjectLiteral(opts));%0A    %7D%0A%0A    public void testOptionSetToObjectLiteralWithOneOption() throws Exception %7B%0A        Set%3COption%3E opts = EnumSet.of(Option.EVIL);%0A        assertEquals(%22%7Bevil:true%7D%22, Util.optionSetToObjectLiteral(opts));%0A    %7D%0A%0A    public void testOptionSetToObjectLiteralWithTwoOptions() throws Exception %7B%0A        Set%3COption%3E opts = EnumSet.of(Option.EVIL, Option.ADSAFE);%0A        // NB: This test may break if not using EnumSet. That guarantees that%0A        // everything comes out in ordinal order, which we defined as%0A        // alphabetic...%0A        assertEquals(%22%7Badsafe:true,evil:true%7D%22, Util%0A                .optionSetToObjectLiteral(opts));%0A    %7D%0A%0A
     public void 
@@ -2559,32 +2559,32 @@
 ows Exception %7B%0A
-
         scope.pu
@@ -2674,20 +2674,16 @@
 ;%0A    %7D%0A
-    
 %0A    pub

Add in some tests for optionSetToObjectLiteral().