Fix several bugs in lslbasefuncs; change InternalJsonScanMatching strategy.

Fix bug: add(Key, Key) is not valid.
Fix bug: llList2CSV was raising an exception always.
Fix bug in test program: llDumpList2String requires Unicode separator.
Patch test program to not output the passed tests.
This commit is contained in:
Sei Lisa 2014-07-31 19:18:26 +02:00
parent e620c9f305
commit f03466629f
3 changed files with 16 additions and 25 deletions

View file

@ -476,7 +476,7 @@ def add(a, b, f32=True):
if ta == tb in (list, unicode):
return a + b
# string + key, key + string are allowed here
if ta in (unicode, Key) and tb in (unicode, Key):
if ta in (unicode, Key) and tb in (unicode, Key) and not (ta == tb == Key):
return a + b
if ta == list:
return a + [b]
@ -931,7 +931,7 @@ def llIntegerToBase64(x):
def llList2CSV(lst):
assert islist(lst)
ret = []
for elem in val:
for elem in lst:
# This always uses LSO rules for float to string.
if type(elem) == float:
ret.append(u'%.6f' % elem)

View file

@ -143,19 +143,11 @@ def InternalJsonF2S(f):
def InternalJsonScanMatching(json, idx):
"""Shortcut: scan for a matching pair of {} or [] with proper nesting
and string handling, with no validity check other than well-formedness,
meaning all {} and [] must match.
meaning all {} or [] must match.
"""
# TODO: InternalJsonScanMatching: Decide whether to use two nesting level variables rather than a stack.
# That would mean that a nested malformed string like [{]} would be valid. SL may accept that.
# (Or maybe even just ONE nesting level variable for the current element,
# disregarding the nesting of the other, e.g. if we're on an object,
# the [] are not tracked thus {[} would be valid. That sounds like LSL.
# Or track [] and {} as the same, distinguishing whether
# the one at nesting level 0 matches the first (e.g. {[{}}} would be valid)
# Or just track the current one and screw the other (e.g. {{]]][]{}][}}
# would be valid). That sounds even more like LSL.
# Experiments are advisable.
stk = [json[idx]]
matching = json[idx]
matching += '}' if json[idx] == '{' else ']'
level = 1
str = False
esc = False
for i in xrange(idx+1, len(json)):
@ -169,13 +161,12 @@ def InternalJsonScanMatching(json, idx):
str = False
elif c == u'"':
str = True
elif c in u'{[':
stk.append(c)
elif c in u']}':
if stk[-1] != (u'{' if c == u'}' else u'['):
return None # bad nesting
stk = stk[:-1]
if stk == []:
elif c in matching:
if c == matching[0]:
level += 1
else:
level -= 1
if not level:
return i+1
return None

View file

@ -62,7 +62,7 @@ def test(fn, expected):
errors += 1
#raise ETestFailed
else:
sys.stdout.write("PASSED! %s == %s\n" % (fn, repr(expected)))
pass#sys.stdout.write("PASSED! %s == %s\n" % (fn, repr(expected)))
def shouldexcept(txt, exc):
global tests
@ -78,7 +78,7 @@ def shouldexcept(txt, exc):
try:
eval(txt)
except exc:
sys.stdout.write("PASSED! %s on %s\n" % (exc.__name__, txt))
#sys.stdout.write("PASSED! %s on %s\n" % (exc.__name__, txt))
return
werr = sys.stderr.write
@ -130,7 +130,7 @@ def verify(msg, result, expected):
werr("Expect: " + repr(expected) + '\n')
#return 0
else:
sys.stdout.write("PASSED! %s, expect=actual=%s\n" % (msg, repr(expected)))
pass#sys.stdout.write("PASSED! %s, expect=actual=%s\n" % (msg, repr(expected)))
#return 1
def verify_list(msg, result, expected):
@ -642,7 +642,7 @@ def do_tests():
u"9999999933815812510711506376257961984.000000, "
u"99999996802856924650656260769173209088.000000")
test('llDumpList2String([F32(1e11)], "/")', u'100000000000.000000')
test('llDumpList2String([F32(1e11)], u"/")', u'100000000000.000000')
# Inputs
inp = [F32(i) for i in [1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14,