diff options
author | Manolo Carrasco <manolo@apache.org> | 2010-05-01 14:39:31 +0000 |
---|---|---|
committer | Manolo Carrasco <manolo@apache.org> | 2010-05-01 14:39:31 +0000 |
commit | 3a239b0d481fa5afc15425b3ba25e7f03ce0a0cd (patch) | |
tree | c5db383e0cb79ccf04e9c36c48e0b4ddb09411f8 /gwtquery-core/src | |
parent | 8f5eac8b54d8fb2045b33f08def0a1e6a6336bbf (diff) | |
download | gwtquery-3a239b0d481fa5afc15425b3ba25e7f03ce0a0cd.tar.gz gwtquery-3a239b0d481fa5afc15425b3ba25e7f03ce0a0cd.zip |
fixed Issue_11
Diffstat (limited to 'gwtquery-core/src')
3 files changed, 60 insertions, 6 deletions
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 = "<b><p>Test Paragraph.</p></b><b><div id=\"content\">Content</div></b>"; $("*", e).wrap("<b></b>"); 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'})")); + } + +} |