From 3a239b0d481fa5afc15425b3ba25e7f03ce0a0cd Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Sat, 1 May 2010 14:39:31 +0000 Subject: fixed Issue_11 --- .../com/google/gwt/query/client/Properties.java | 11 +++--- .../google/gwt/query/client/GwtQueryCoreTest.java | 16 +++++++-- .../google/gwt/query/client/JreQueryCoreTest.java | 39 ++++++++++++++++++++++ 3 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/JreQueryCoreTest.java (limited to 'gwtquery-core/src') diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java index 35864c6c..a8542ae7 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java @@ -22,16 +22,19 @@ import com.google.gwt.core.client.JsArrayString; * JSO for accessing Javascript objective literals used by GwtQuery functions. */ public class Properties extends JavaScriptObject { - + public static Properties create(String properties) { - String s = properties.replaceFirst("^[({]*(.*)[})]*$", "({$1})"); - return (Properties) createImpl(s); + return (Properties) createImpl(wrapPropertiesString(properties)); } - public final static native JavaScriptObject createImpl(String properties) /*-{ + public static final native JavaScriptObject createImpl(String properties) /*-{ return eval(properties); }-*/; + protected static String wrapPropertiesString(String s) { + return "({" + s.replaceFirst("^[({]+", "").replaceFirst("[})]+", "") + "})"; + } + protected Properties() { } diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GwtQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GwtQueryCoreTest.java index dfe60135..a45226ed 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GwtQueryCoreTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GwtQueryCoreTest.java @@ -15,10 +15,12 @@ */ package com.google.gwt.query.client; +import static com.google.gwt.query.client.GQuery.$; +import static com.google.gwt.query.client.GQuery.$$; + import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.InputElement; import com.google.gwt.junit.client.GWTTestCase; -import static com.google.gwt.query.client.GQuery.$; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.HTML; @@ -96,6 +98,16 @@ public class GwtQueryCoreTest extends GWTTestCase { assertEquals("red", $("p", e).css("color")); assertEquals("", $("p", e).css("background")); } + + public void testProperties() { + Properties p = $$("border:'1px solid black'"); + assertEquals(1, p.keys().length); + assertNotNull(p.get("border")); + + p = $$("({border:'1px solid black'})"); + assertEquals(1, p.keys().length); + assertNotNull(p.get("border")); + } public void testEffectsPlugin() { $(e).html( @@ -574,7 +586,7 @@ public class GwtQueryCoreTest extends GWTTestCase { $("p", e).wrap(wrapper); assertEquals(expected, $(e).html()); - $(e).html(content+wrapper); + $(e).html(content + wrapper); expected = "

Test Paragraph.

Content
"; $("*", e).wrap(""); diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/JreQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/JreQueryCoreTest.java new file mode 100644 index 00000000..f1ae010b --- /dev/null +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/JreQueryCoreTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client; + +import com.google.gwt.junit.client.GWTTestCase; + +/** + * Test class for testing gwtquery-core api in JRE. + */ +public class JreQueryCoreTest extends GWTTestCase { + + public String getModuleName() { + return null; + } + + public void testWrapPropertiesString() { + assertEquals("({border:'1px solid black'})", Properties.wrapPropertiesString("border:'1px solid black'")); + assertEquals("({border:'1px solid black'})", Properties.wrapPropertiesString("(border:'1px solid black')")); + assertEquals("({border:'1px solid black'})", Properties.wrapPropertiesString("{border:'1px solid black'}")); + assertEquals("({border:'1px solid black'})", Properties.wrapPropertiesString("{border:'1px solid black'}")); + assertEquals("({border:'1px solid black'})", Properties.wrapPropertiesString("(border:'1px solid black')")); + assertEquals("({border:'1px solid black'})", Properties.wrapPropertiesString("{(border:'1px solid black')}")); + assertEquals("({border:'1px solid black'})", Properties.wrapPropertiesString("({border:'1px solid black'})")); + } + +} -- cgit v1.2.3