Permalink
Browse files

Clutch simplejson hacking.

  • Loading branch information...
ralphbean committed Mar 21, 2012
1 parent be23347 commit fb7c06b661fa57cb0fe24a0f9d6f82dc987e1a5d
Showing with 4 additions and 14 deletions.
  1. +3 −14 tests/test_js.py
  2. +1 −0 tw2/core/js.py
@@ -11,25 +11,14 @@ def setUp(self):
mw = twc.make_middleware(lambda *args, **kw: "I'm an app, lol!")
testapi.request(1, mw=mw)
# Deprecated Test
#def test_js_function(self):
# obj = self.encode({"onLoad": js_function("do_something")("param")})
# assert obj == '{"onLoad": do_something(\\"param\\")}'
def test_js_function(self):
json = self.encode({"onLoad": js_function("do_something")("param")})
eq_(json, '{"onLoad": do_something(\\"param\\")}')
def test_js_symbol(self):
obj = self.encode({"onLoad": js_symbol("param")})
eq_(obj, '{"onLoad": param}')
# Deprecated Test
#def test_mark_for_escape(self):
# obj = 'MyObject'
# assert self.twe.mark_for_escape(obj) == '*#*MyObject*#*'
# Deprecated Test
#def test_unescape_marked(self):
# obj = '"*#*MyObject*#*"'
# assert self.twe.unescape_marked(obj) == 'MyObject'
def test_js_callback(self):
eq_(str(js_callback("update_div")), 'update_div')
eq_(str(js_callback(js_function('foo')(1,2,3))), 'function(){foo(1, 2, 3)}')
@@ -39,6 +39,7 @@ class TWEncoder(simplejson.encoder.JSONEncoder):
"""
def __init__(self, *args, **kw):
kw['namedtuple_as_object'] = False
self.pass_through = (_js_call, js_callback, js_symbol, js_function)
super(TWEncoder, self).__init__(*args, **kw)

0 comments on commit fb7c06b

Please sign in to comment.