mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2024-11-21 14:18:57 -07:00
All tests pass now
This commit is contained in:
parent
16d8c4c9d1
commit
e1bcccb979
5 changed files with 315 additions and 265 deletions
6
main.py
6
main.py
|
@ -60,7 +60,7 @@ def ReportError(script, e):
|
|||
# Write the whole line in the target encoding.
|
||||
err_line = script[linestart:lineend] + '\n'
|
||||
werr(err_line)
|
||||
werr(" " * cno + "^\n")
|
||||
werr(u" " * cno + u"^\n")
|
||||
werr(e.args[0] + u"\n")
|
||||
|
||||
class UniConvScript(object):
|
||||
|
@ -84,6 +84,8 @@ class UniConvScript(object):
|
|||
try:
|
||||
self.script = self.script.decode('utf8')
|
||||
except UnicodeDecodeError as e:
|
||||
# EParse requires str
|
||||
self.script = b2str(self.script, 'utf8')
|
||||
self.errorpos = e.start
|
||||
raise EParse(self, u"Invalid UTF-8 in script")
|
||||
return self.script
|
||||
|
@ -753,7 +755,7 @@ def main(argv):
|
|||
resource.setrlimit(resource.RLIMIT_AS, (81001000, 81001000))
|
||||
if raise_exception:
|
||||
raise
|
||||
werr(e.__class__.__name__ + ': ' + str(e) + '\n')
|
||||
werr(e.__class__.__name__ + u': ' + str(e) + u'\n')
|
||||
return 1
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
60
run-tests.py
60
run-tests.py
|
@ -202,6 +202,7 @@ def tryRead(fn, Binary = True):
|
|||
# In StringIO, mixing unicode and str causes problems with non-ASCII chars.
|
||||
# Avoid it by overriding the write method, to always encode unicode as UTF-8.
|
||||
class StrUTF8IO(StringStream):
|
||||
encoding = 'utf8'
|
||||
def write(self, s):
|
||||
StringStream.write(self, any2b(s))
|
||||
|
||||
|
@ -309,25 +310,60 @@ class UnitTestRegression(UnitTestCase):
|
|||
from unit_tests import json
|
||||
# Patch llJsonSetValue, to allow running the test.
|
||||
json.llJsonSetValue = lambda x, y, z: u"***"
|
||||
sys.stderr.write('\nRunning JSON test module: ')
|
||||
werr('\nRunning JSON test module: ')
|
||||
save_stdout = sys.stdout
|
||||
save_stderr = sys.stderr
|
||||
stdout_output = False
|
||||
stderr_output = False
|
||||
actual_stdout = False
|
||||
actual_stderr = False
|
||||
try:
|
||||
sys.stdout = StringStream()
|
||||
sys.stdout.encoding = 'utf8'
|
||||
sys.stderr = StringStream()
|
||||
sys.stderr.encoding = 'utf8'
|
||||
sys.stdout = StrUTF8IO()
|
||||
sys.stderr = StrUTF8IO()
|
||||
errs = json.run_tests()
|
||||
stdout_output = sys.stdout.getvalue()
|
||||
stderr_output = sys.stderr.getvalue()
|
||||
actual_stdout = sys.stdout.getvalue()
|
||||
actual_stderr = sys.stderr.getvalue()
|
||||
finally:
|
||||
sys.stdout = save_stdout
|
||||
sys.stderr = save_stderr
|
||||
self.assertLessEqual(errs, 138)
|
||||
self.assertEqual(stdout_output, tryRead('unit_tests/json.out'))
|
||||
self.assertEqual(stderr_output, tryRead('unit_tests/json.err'))
|
||||
|
||||
expected_stdout = tryRead('unit_tests/json.out')
|
||||
expected_stderr = tryRead('unit_tests/json.err')
|
||||
try:
|
||||
self.assertTrue(actual_stdout == expected_stdout)
|
||||
except AssertionError:
|
||||
werr(u'Failed'
|
||||
u'\n************ expected stdout:\n')
|
||||
werr(expected_stdout)
|
||||
werr(u'\n************ actual stdout:\n')
|
||||
werr(actual_stdout)
|
||||
if difflib and expected_stdout and actual_stdout \
|
||||
and not expected_stdout.startswith(b'REGEX\n'):
|
||||
werr(u'\n************ diff:\n'
|
||||
+ u'\n'.join(difflib.unified_diff(
|
||||
b2u(expected_stdout).split(u'\n'),
|
||||
b2u(actual_stdout).split(u'\n'),
|
||||
'expected', 'actual', lineterm=''
|
||||
)))
|
||||
werr(u'\n************ ')
|
||||
raise
|
||||
try:
|
||||
self.assertTrue(actual_stderr == expected_stderr)
|
||||
except AssertionError:
|
||||
werr(u'Failed'
|
||||
u'\n************ expected stderr:\n')
|
||||
werr(expected_stderr)
|
||||
werr(u'\n************ actual stderr:\n')
|
||||
werr(actual_stderr)
|
||||
if difflib and expected_stderr and actual_stderr \
|
||||
and not expected_stderr.startswith(b'REGEX\n'):
|
||||
werr(u'\n************ diff:\n'
|
||||
+ u'\n'.join(difflib.unified_diff(
|
||||
b2u(expected_stderr).split(u'\n'),
|
||||
b2u(actual_stderr).split(u'\n'),
|
||||
'expected', 'actual', lineterm=''
|
||||
)))
|
||||
werr(u'\n************ ')
|
||||
raise
|
||||
assert 'unit_tests.json' in sys.modules
|
||||
del sys.modules['unit_tests.json']
|
||||
|
||||
|
@ -734,7 +770,6 @@ def generateScriptTests():
|
|||
werr(expected_stderr)
|
||||
werr(u'\n************ actual stderr:\n')
|
||||
werr(actual_stderr)
|
||||
# werr(('1' if difflib else '0')+('1' if expected_stderr else '0') + ('1' if actual_stderr else '0'))
|
||||
if difflib and expected_stderr and actual_stderr \
|
||||
and not expected_stderr.startswith(b'REGEX\n'):
|
||||
werr(u'\n************ diff:\n'
|
||||
|
@ -806,4 +841,3 @@ def generateScriptTests():
|
|||
generateScriptTests()
|
||||
if __name__ == '__main__':
|
||||
unittest.main(argv = sys.argv)
|
||||
#UnitTestRegression().test_Regression__multiline_string()
|
||||
|
|
|
@ -140,16 +140,16 @@ Expect: u'\ufdd0'
|
|||
Test failed: llJsonSetValue fail to insert data into invalid array index (MAINT-2675)
|
||||
Actual: u'***'
|
||||
Expect: u'\ufdd0'
|
||||
PASSED! llJson2List first, expect=actual='[u\'[1,2,3]\', u\'{"a":3,"b":[true,"test",6]}\']'
|
||||
PASSED! llJson2List l,0, expect=actual='[1, 2, 3]'
|
||||
PASSED! llJson2List l,1, expect=actual='[u\'a\', 3, u\'b\', u\'[true,"test",6]\']'
|
||||
PASSED! llJson2List n,3, expect=actual="[u'\\ufdd6', u'test', 6]"
|
||||
PASSED! llJson2List n,1, expect=actual="[u'test']"
|
||||
PASSED! Empty JSON string becomes empty list, expect=actual='[]'
|
||||
PASSED! Empty JSON array becomes empty list (MAINT-2678), expect=actual='[]'
|
||||
PASSED! Empty JSON object becomes empty list (MAINT-2678), expect=actual='[]'
|
||||
PASSED! llJson2List for non-JSON string is stored as a single object, expect=actual="[u'Non-JSON string, with comma']"
|
||||
PASSED! llJson2List, malformed input, expect=actual="[u'[malformed}']"
|
||||
PASSED! llJson2List first, expect=actual=u'[u\'[1,2,3]\', u\'{"a":3,"b":[true,"test",6]}\']'
|
||||
PASSED! llJson2List l,0, expect=actual=u'[1, 2, 3]'
|
||||
PASSED! llJson2List l,1, expect=actual=u'[u\'a\', 3, u\'b\', u\'[true,"test",6]\']'
|
||||
PASSED! llJson2List n,3, expect=actual=u"[u'\\ufdd6', u'test', 6]"
|
||||
PASSED! llJson2List n,1, expect=actual=u"[u'test']"
|
||||
PASSED! Empty JSON string becomes empty list, expect=actual=u'[]'
|
||||
PASSED! Empty JSON array becomes empty list (MAINT-2678), expect=actual=u'[]'
|
||||
PASSED! Empty JSON object becomes empty list (MAINT-2678), expect=actual=u'[]'
|
||||
PASSED! llJson2List for non-JSON string is stored as a single object, expect=actual=u"[u'Non-JSON string, with comma']"
|
||||
PASSED! llJson2List, malformed input, expect=actual=u"[u'[malformed}']"
|
||||
PASSED! llList2Json, json object, expect=actual=u'{"a":1,"b":2.500000,"c":"test","d":true,"e":[1,2,3]}'
|
||||
PASSED! llList2Json, json array, expect=actual=u'[1,2.500000,"test",true,[1,2,3]]'
|
||||
PASSED! llList2Json, json array, alternative true representation, expect=actual=u'[1,2.500000,"test",true,[1,2,3]]'
|
||||
|
@ -159,7 +159,7 @@ PASSED! llList2Json, json object, truncated, expect=actual=u'\ufdd0'
|
|||
PASSED! llList2Json, json object, non-string in one of the first stride values, expect=actual=u'\ufdd0'
|
||||
PASSED! llList2Json, json invalid type, expect=actual=u'\ufdd0'
|
||||
PASSED! Type of string with escaped char (for MAINT-2698), 'quote in middle', expect=actual=u'\ufdd4'
|
||||
PASSED! llJsonGetValue [1,"funky\"string"] (for MAINT-2698), 'quote in middle', expect=actual='3'
|
||||
PASSED! llJsonGetValue [1,"funky\"string"] (for MAINT-2698), 'quote in middle', expect=actual=u'3'
|
||||
PASSED! llJsonGetValue [1,"b"] (for MAINT-2698), 'quote in middle', expect=actual=u'funky"stringvalue'
|
||||
Test failed: llJsonSetValue with escaped string as value (for MAINT-2698), 'quote in middle'
|
||||
Actual: u'***'
|
||||
|
@ -171,11 +171,11 @@ Test failed: llJsonSetValue with escaped string as key's value (for MAINT-2698),
|
|||
Actual: u'***'
|
||||
Expect: u'[{"funky\\"string":"funky\\"stringvalue"},{"funky\\"string":3,"b":"funky\\"stringvalue"}]'
|
||||
Test failed: llJson2List extracting object containing escaped string (for MAINT-2698), 'quote in middle'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'{"funky\\\\"string":"funky\\\\"stringvalue"}\', u\'{"funky\\\\"string":3,"b":"funky\\\\"stringvalue"}\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'{"funky\\\\"string":"funky\\\\"stringvalue"}\', u\'{"funky\\\\"string":3,"b":"funky\\\\"stringvalue"}\']'
|
||||
Test failed: llJson2List extracting escaped strings (for MAINT-2698), 'quote in middle'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'funky"string\', u\'funky"stringvalue\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'funky"string\', u\'funky"stringvalue\']'
|
||||
Test failed: llList2Json from escaped-containing string to array (for MAINT-2698), 'quote in middle'
|
||||
Actual: u'["***"]'
|
||||
Expect: u'["funky\\"string","funky\\"stringvalue"]'
|
||||
|
@ -183,7 +183,7 @@ Test failed: llList2Json from escaped-containing string to object (for MAINT-269
|
|||
Actual: u'{}'
|
||||
Expect: u'{"funky\\"string":"funky\\"stringvalue"}'
|
||||
PASSED! Type of string with escaped char (for MAINT-2698), 'quote in middle, other position', expect=actual=u'\ufdd4'
|
||||
PASSED! llJsonGetValue [1,"funkystr\"ing"] (for MAINT-2698), 'quote in middle, other position', expect=actual='3'
|
||||
PASSED! llJsonGetValue [1,"funkystr\"ing"] (for MAINT-2698), 'quote in middle, other position', expect=actual=u'3'
|
||||
PASSED! llJsonGetValue [1,"b"] (for MAINT-2698), 'quote in middle, other position', expect=actual=u'funkystr"ingvalue'
|
||||
Test failed: llJsonSetValue with escaped string as value (for MAINT-2698), 'quote in middle, other position'
|
||||
Actual: u'***'
|
||||
|
@ -195,11 +195,11 @@ Test failed: llJsonSetValue with escaped string as key's value (for MAINT-2698),
|
|||
Actual: u'***'
|
||||
Expect: u'[{"funkystr\\"ing":"funkystr\\"ingvalue"},{"funkystr\\"ing":3,"b":"funkystr\\"ingvalue"}]'
|
||||
Test failed: llJson2List extracting object containing escaped string (for MAINT-2698), 'quote in middle, other position'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'{"funkystr\\\\"ing":"funkystr\\\\"ingvalue"}\', u\'{"funkystr\\\\"ing":3,"b":"funkystr\\\\"ingvalue"}\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'{"funkystr\\\\"ing":"funkystr\\\\"ingvalue"}\', u\'{"funkystr\\\\"ing":3,"b":"funkystr\\\\"ingvalue"}\']'
|
||||
Test failed: llJson2List extracting escaped strings (for MAINT-2698), 'quote in middle, other position'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'funkystr"ing\', u\'funkystr"ingvalue\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'funkystr"ing\', u\'funkystr"ingvalue\']'
|
||||
Test failed: llList2Json from escaped-containing string to array (for MAINT-2698), 'quote in middle, other position'
|
||||
Actual: u'["***"]'
|
||||
Expect: u'["funkystr\\"ing","funkystr\\"ingvalue"]'
|
||||
|
@ -207,7 +207,7 @@ Test failed: llList2Json from escaped-containing string to object (for MAINT-269
|
|||
Actual: u'{}'
|
||||
Expect: u'{"funkystr\\"ing":"funkystr\\"ingvalue"}'
|
||||
PASSED! Type of string with escaped char (for MAINT-2698), 'backslashes in middle', expect=actual=u'\ufdd4'
|
||||
PASSED! llJsonGetValue [1,"funky\\string"] (for MAINT-2698), 'backslashes in middle', expect=actual='3'
|
||||
PASSED! llJsonGetValue [1,"funky\\string"] (for MAINT-2698), 'backslashes in middle', expect=actual=u'3'
|
||||
PASSED! llJsonGetValue [1,"b"] (for MAINT-2698), 'backslashes in middle', expect=actual=u'funky\\stringvalue'
|
||||
Test failed: llJsonSetValue with escaped string as value (for MAINT-2698), 'backslashes in middle'
|
||||
Actual: u'***'
|
||||
|
@ -219,11 +219,11 @@ Test failed: llJsonSetValue with escaped string as key's value (for MAINT-2698),
|
|||
Actual: u'***'
|
||||
Expect: u'[{"funky\\\\string":"funky\\\\stringvalue"},{"funky\\\\string":3,"b":"funky\\\\stringvalue"}]'
|
||||
Test failed: llJson2List extracting object containing escaped string (for MAINT-2698), 'backslashes in middle'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'{"funky\\\\\\\\string":"funky\\\\\\\\stringvalue"}\', u\'{"funky\\\\\\\\string":3,"b":"funky\\\\\\\\stringvalue"}\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'{"funky\\\\\\\\string":"funky\\\\\\\\stringvalue"}\', u\'{"funky\\\\\\\\string":3,"b":"funky\\\\\\\\stringvalue"}\']'
|
||||
Test failed: llJson2List extracting escaped strings (for MAINT-2698), 'backslashes in middle'
|
||||
Actual: "[u'***']"
|
||||
Expect: "[u'funky\\\\string', u'funky\\\\stringvalue']"
|
||||
Actual: u"[u'***']"
|
||||
Expect: u"[u'funky\\\\string', u'funky\\\\stringvalue']"
|
||||
Test failed: llList2Json from escaped-containing string to array (for MAINT-2698), 'backslashes in middle'
|
||||
Actual: u'["***"]'
|
||||
Expect: u'["funky\\\\string","funky\\\\stringvalue"]'
|
||||
|
@ -231,7 +231,7 @@ Test failed: llList2Json from escaped-containing string to object (for MAINT-269
|
|||
Actual: u'{}'
|
||||
Expect: u'{"funky\\\\string":"funky\\\\stringvalue"}'
|
||||
PASSED! Type of string with escaped char (for MAINT-2698), 'backslashes at beginning', expect=actual=u'\ufdd4'
|
||||
PASSED! llJsonGetValue [1,"\\funkystring"] (for MAINT-2698), 'backslashes at beginning', expect=actual='3'
|
||||
PASSED! llJsonGetValue [1,"\\funkystring"] (for MAINT-2698), 'backslashes at beginning', expect=actual=u'3'
|
||||
PASSED! llJsonGetValue [1,"b"] (for MAINT-2698), 'backslashes at beginning', expect=actual=u'\\funkystringvalue'
|
||||
Test failed: llJsonSetValue with escaped string as value (for MAINT-2698), 'backslashes at beginning'
|
||||
Actual: u'***'
|
||||
|
@ -243,11 +243,11 @@ Test failed: llJsonSetValue with escaped string as key's value (for MAINT-2698),
|
|||
Actual: u'***'
|
||||
Expect: u'[{"\\\\funkystring":"\\\\funkystringvalue"},{"\\\\funkystring":3,"b":"\\\\funkystringvalue"}]'
|
||||
Test failed: llJson2List extracting object containing escaped string (for MAINT-2698), 'backslashes at beginning'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'{"\\\\\\\\funkystring":"\\\\\\\\funkystringvalue"}\', u\'{"\\\\\\\\funkystring":3,"b":"\\\\\\\\funkystringvalue"}\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'{"\\\\\\\\funkystring":"\\\\\\\\funkystringvalue"}\', u\'{"\\\\\\\\funkystring":3,"b":"\\\\\\\\funkystringvalue"}\']'
|
||||
Test failed: llJson2List extracting escaped strings (for MAINT-2698), 'backslashes at beginning'
|
||||
Actual: "[u'***']"
|
||||
Expect: "[u'\\\\funkystring', u'\\\\funkystringvalue']"
|
||||
Actual: u"[u'***']"
|
||||
Expect: u"[u'\\\\funkystring', u'\\\\funkystringvalue']"
|
||||
Test failed: llList2Json from escaped-containing string to array (for MAINT-2698), 'backslashes at beginning'
|
||||
Actual: u'["***"]'
|
||||
Expect: u'["\\\\funkystring","\\\\funkystringvalue"]'
|
||||
|
@ -255,7 +255,7 @@ Test failed: llList2Json from escaped-containing string to object (for MAINT-269
|
|||
Actual: u'{}'
|
||||
Expect: u'{"\\\\funkystring":"\\\\funkystringvalue"}'
|
||||
PASSED! Type of string with escaped char (for MAINT-2698), 'newline in string', expect=actual=u'\ufdd4'
|
||||
PASSED! llJsonGetValue [1,"funky\nstring"] (for MAINT-2698), 'newline in string', expect=actual='3'
|
||||
PASSED! llJsonGetValue [1,"funky\nstring"] (for MAINT-2698), 'newline in string', expect=actual=u'3'
|
||||
PASSED! llJsonGetValue [1,"b"] (for MAINT-2698), 'newline in string', expect=actual=u'funky\nstringvalue'
|
||||
Test failed: llJsonSetValue with escaped string as value (for MAINT-2698), 'newline in string'
|
||||
Actual: u'***'
|
||||
|
@ -267,11 +267,11 @@ Test failed: llJsonSetValue with escaped string as key's value (for MAINT-2698),
|
|||
Actual: u'***'
|
||||
Expect: u'[{"funky\\nstring":"funky\\nstringvalue"},{"funky\\nstring":3,"b":"funky\\nstringvalue"}]'
|
||||
Test failed: llJson2List extracting object containing escaped string (for MAINT-2698), 'newline in string'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'{"funky\\\\nstring":"funky\\\\nstringvalue"}\', u\'{"funky\\\\nstring":3,"b":"funky\\\\nstringvalue"}\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'{"funky\\\\nstring":"funky\\\\nstringvalue"}\', u\'{"funky\\\\nstring":3,"b":"funky\\\\nstringvalue"}\']'
|
||||
Test failed: llJson2List extracting escaped strings (for MAINT-2698), 'newline in string'
|
||||
Actual: "[u'***']"
|
||||
Expect: "[u'funky\\nstring', u'funky\\nstringvalue']"
|
||||
Actual: u"[u'***']"
|
||||
Expect: u"[u'funky\\nstring', u'funky\\nstringvalue']"
|
||||
Test failed: llList2Json from escaped-containing string to array (for MAINT-2698), 'newline in string'
|
||||
Actual: u'["***"]'
|
||||
Expect: u'["funky\\nstring","funky\\nstringvalue"]'
|
||||
|
@ -279,7 +279,7 @@ Test failed: llList2Json from escaped-containing string to object (for MAINT-269
|
|||
Actual: u'{}'
|
||||
Expect: u'{"funky\\nstring":"funky\\nstringvalue"}'
|
||||
PASSED! Type of string with escaped char (for MAINT-2698), 'forward slash in string', expect=actual=u'\ufdd4'
|
||||
PASSED! llJsonGetValue [1,"funky\/string"] (for MAINT-2698), 'forward slash in string', expect=actual='3'
|
||||
PASSED! llJsonGetValue [1,"funky\/string"] (for MAINT-2698), 'forward slash in string', expect=actual=u'3'
|
||||
PASSED! llJsonGetValue [1,"b"] (for MAINT-2698), 'forward slash in string', expect=actual=u'funky/stringvalue'
|
||||
Test failed: llJsonSetValue with escaped string as value (for MAINT-2698), 'forward slash in string'
|
||||
Actual: u'***'
|
||||
|
@ -291,11 +291,11 @@ Test failed: llJsonSetValue with escaped string as key's value (for MAINT-2698),
|
|||
Actual: u'***'
|
||||
Expect: u'[{"funky\\/string":"funky\\/stringvalue"},{"funky\\/string":3,"b":"funky\\/stringvalue"}]'
|
||||
Test failed: llJson2List extracting object containing escaped string (for MAINT-2698), 'forward slash in string'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'{"funky\\\\/string":"funky\\\\/stringvalue"}\', u\'{"funky\\\\/string":3,"b":"funky\\\\/stringvalue"}\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'{"funky\\\\/string":"funky\\\\/stringvalue"}\', u\'{"funky\\\\/string":3,"b":"funky\\\\/stringvalue"}\']'
|
||||
Test failed: llJson2List extracting escaped strings (for MAINT-2698), 'forward slash in string'
|
||||
Actual: "[u'***']"
|
||||
Expect: "[u'funky/string', u'funky/stringvalue']"
|
||||
Actual: u"[u'***']"
|
||||
Expect: u"[u'funky/string', u'funky/stringvalue']"
|
||||
Test failed: llList2Json from escaped-containing string to array (for MAINT-2698), 'forward slash in string'
|
||||
Actual: u'["***"]'
|
||||
Expect: u'["funky\\/string","funky\\/stringvalue"]'
|
||||
|
@ -303,7 +303,7 @@ Test failed: llList2Json from escaped-containing string to object (for MAINT-269
|
|||
Actual: u'{}'
|
||||
Expect: u'{"funky\\/string":"funky\\/stringvalue"}'
|
||||
PASSED! Type of string with escaped char (for MAINT-2698), 'tab in string', expect=actual=u'\ufdd4'
|
||||
PASSED! llJsonGetValue [1,"funky\tstring"] (for MAINT-2698), 'tab in string', expect=actual='3'
|
||||
PASSED! llJsonGetValue [1,"funky\tstring"] (for MAINT-2698), 'tab in string', expect=actual=u'3'
|
||||
PASSED! llJsonGetValue [1,"b"] (for MAINT-2698), 'tab in string', expect=actual=u'funky\tstringvalue'
|
||||
Test failed: llJsonSetValue with escaped string as value (for MAINT-2698), 'tab in string'
|
||||
Actual: u'***'
|
||||
|
@ -315,11 +315,11 @@ Test failed: llJsonSetValue with escaped string as key's value (for MAINT-2698),
|
|||
Actual: u'***'
|
||||
Expect: u'[{"funky\\tstring":"funky\\tstringvalue"},{"funky\\tstring":3,"b":"funky\\tstringvalue"}]'
|
||||
Test failed: llJson2List extracting object containing escaped string (for MAINT-2698), 'tab in string'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'{"funky\\\\tstring":"funky\\\\tstringvalue"}\', u\'{"funky\\\\tstring":3,"b":"funky\\\\tstringvalue"}\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'{"funky\\\\tstring":"funky\\\\tstringvalue"}\', u\'{"funky\\\\tstring":3,"b":"funky\\\\tstringvalue"}\']'
|
||||
Test failed: llJson2List extracting escaped strings (for MAINT-2698), 'tab in string'
|
||||
Actual: "[u'***']"
|
||||
Expect: "[u'funky\\tstring', u'funky\\tstringvalue']"
|
||||
Actual: u"[u'***']"
|
||||
Expect: u"[u'funky\\tstring', u'funky\\tstringvalue']"
|
||||
Test failed: llList2Json from escaped-containing string to array (for MAINT-2698), 'tab in string'
|
||||
Actual: u'["***"]'
|
||||
Expect: u'["funky\\tstring","funky\\tstringvalue"]'
|
||||
|
@ -327,7 +327,7 @@ Test failed: llList2Json from escaped-containing string to object (for MAINT-269
|
|||
Actual: u'{}'
|
||||
Expect: u'{"funky\\tstring":"funky\\tstringvalue"}'
|
||||
PASSED! Type of string with escaped char (for MAINT-2698), 'backspace in middle', expect=actual=u'\ufdd4'
|
||||
PASSED! llJsonGetValue [1,"funky\bstring"] (for MAINT-2698), 'backspace in middle', expect=actual='3'
|
||||
PASSED! llJsonGetValue [1,"funky\bstring"] (for MAINT-2698), 'backspace in middle', expect=actual=u'3'
|
||||
PASSED! llJsonGetValue [1,"b"] (for MAINT-2698), 'backspace in middle', expect=actual=u'funky\x08stringvalue'
|
||||
Test failed: llJsonSetValue with escaped string as value (for MAINT-2698), 'backspace in middle'
|
||||
Actual: u'***'
|
||||
|
@ -339,11 +339,11 @@ Test failed: llJsonSetValue with escaped string as key's value (for MAINT-2698),
|
|||
Actual: u'***'
|
||||
Expect: u'[{"funky\\bstring":"funky\\bstringvalue"},{"funky\\bstring":3,"b":"funky\\bstringvalue"}]'
|
||||
Test failed: llJson2List extracting object containing escaped string (for MAINT-2698), 'backspace in middle'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'{"funky\\\\bstring":"funky\\\\bstringvalue"}\', u\'{"funky\\\\bstring":3,"b":"funky\\\\bstringvalue"}\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'{"funky\\\\bstring":"funky\\\\bstringvalue"}\', u\'{"funky\\\\bstring":3,"b":"funky\\\\bstringvalue"}\']'
|
||||
Test failed: llJson2List extracting escaped strings (for MAINT-2698), 'backspace in middle'
|
||||
Actual: "[u'***']"
|
||||
Expect: "[u'funky\\x08string', u'funky\\x08stringvalue']"
|
||||
Actual: u"[u'***']"
|
||||
Expect: u"[u'funky\\x08string', u'funky\\x08stringvalue']"
|
||||
Test failed: llList2Json from escaped-containing string to array (for MAINT-2698), 'backspace in middle'
|
||||
Actual: u'["***"]'
|
||||
Expect: u'["funky\\bstring","funky\\bstringvalue"]'
|
||||
|
@ -351,7 +351,7 @@ Test failed: llList2Json from escaped-containing string to object (for MAINT-269
|
|||
Actual: u'{}'
|
||||
Expect: u'{"funky\\bstring":"funky\\bstringvalue"}'
|
||||
PASSED! Type of string with escaped char (for MAINT-2698), 'form feed in middle', expect=actual=u'\ufdd4'
|
||||
PASSED! llJsonGetValue [1,"funky\fstring"] (for MAINT-2698), 'form feed in middle', expect=actual='3'
|
||||
PASSED! llJsonGetValue [1,"funky\fstring"] (for MAINT-2698), 'form feed in middle', expect=actual=u'3'
|
||||
PASSED! llJsonGetValue [1,"b"] (for MAINT-2698), 'form feed in middle', expect=actual=u'funky\x0cstringvalue'
|
||||
Test failed: llJsonSetValue with escaped string as value (for MAINT-2698), 'form feed in middle'
|
||||
Actual: u'***'
|
||||
|
@ -363,11 +363,11 @@ Test failed: llJsonSetValue with escaped string as key's value (for MAINT-2698),
|
|||
Actual: u'***'
|
||||
Expect: u'[{"funky\\fstring":"funky\\fstringvalue"},{"funky\\fstring":3,"b":"funky\\fstringvalue"}]'
|
||||
Test failed: llJson2List extracting object containing escaped string (for MAINT-2698), 'form feed in middle'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'{"funky\\\\fstring":"funky\\\\fstringvalue"}\', u\'{"funky\\\\fstring":3,"b":"funky\\\\fstringvalue"}\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'{"funky\\\\fstring":"funky\\\\fstringvalue"}\', u\'{"funky\\\\fstring":3,"b":"funky\\\\fstringvalue"}\']'
|
||||
Test failed: llJson2List extracting escaped strings (for MAINT-2698), 'form feed in middle'
|
||||
Actual: "[u'***']"
|
||||
Expect: "[u'funky\\x0cstring', u'funky\\x0cstringvalue']"
|
||||
Actual: u"[u'***']"
|
||||
Expect: u"[u'funky\\x0cstring', u'funky\\x0cstringvalue']"
|
||||
Test failed: llList2Json from escaped-containing string to array (for MAINT-2698), 'form feed in middle'
|
||||
Actual: u'["***"]'
|
||||
Expect: u'["funky\\fstring","funky\\fstringvalue"]'
|
||||
|
@ -375,7 +375,7 @@ Test failed: llList2Json from escaped-containing string to object (for MAINT-269
|
|||
Actual: u'{}'
|
||||
Expect: u'{"funky\\fstring":"funky\\fstringvalue"}'
|
||||
PASSED! Type of string with escaped char (for MAINT-2698), 'carriage return in string', expect=actual=u'\ufdd4'
|
||||
PASSED! llJsonGetValue [1,"funky\rstring"] (for MAINT-2698), 'carriage return in string', expect=actual='3'
|
||||
PASSED! llJsonGetValue [1,"funky\rstring"] (for MAINT-2698), 'carriage return in string', expect=actual=u'3'
|
||||
PASSED! llJsonGetValue [1,"b"] (for MAINT-2698), 'carriage return in string', expect=actual=u'funky\rstringvalue'
|
||||
Test failed: llJsonSetValue with escaped string as value (for MAINT-2698), 'carriage return in string'
|
||||
Actual: u'***'
|
||||
|
@ -387,11 +387,11 @@ Test failed: llJsonSetValue with escaped string as key's value (for MAINT-2698),
|
|||
Actual: u'***'
|
||||
Expect: u'[{"funky\\rstring":"funky\\rstringvalue"},{"funky\\rstring":3,"b":"funky\\rstringvalue"}]'
|
||||
Test failed: llJson2List extracting object containing escaped string (for MAINT-2698), 'carriage return in string'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'{"funky\\\\rstring":"funky\\\\rstringvalue"}\', u\'{"funky\\\\rstring":3,"b":"funky\\\\rstringvalue"}\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'{"funky\\\\rstring":"funky\\\\rstringvalue"}\', u\'{"funky\\\\rstring":3,"b":"funky\\\\rstringvalue"}\']'
|
||||
Test failed: llJson2List extracting escaped strings (for MAINT-2698), 'carriage return in string'
|
||||
Actual: "[u'***']"
|
||||
Expect: "[u'funky\\rstring', u'funky\\rstringvalue']"
|
||||
Actual: u"[u'***']"
|
||||
Expect: u"[u'funky\\rstring', u'funky\\rstringvalue']"
|
||||
Test failed: llList2Json from escaped-containing string to array (for MAINT-2698), 'carriage return in string'
|
||||
Actual: u'["***"]'
|
||||
Expect: u'["funky\\rstring","funky\\rstringvalue"]'
|
||||
|
@ -399,7 +399,7 @@ Test failed: llList2Json from escaped-containing string to object (for MAINT-269
|
|||
Actual: u'{}'
|
||||
Expect: u'{"funky\\rstring":"funky\\rstringvalue"}'
|
||||
PASSED! Type of string with escaped char (for MAINT-2698), 'quote in beginning', expect=actual=u'\ufdd4'
|
||||
PASSED! llJsonGetValue [1,"\"funkystring"] (for MAINT-2698), 'quote in beginning', expect=actual='3'
|
||||
PASSED! llJsonGetValue [1,"\"funkystring"] (for MAINT-2698), 'quote in beginning', expect=actual=u'3'
|
||||
PASSED! llJsonGetValue [1,"b"] (for MAINT-2698), 'quote in beginning', expect=actual=u'"funkystringvalue'
|
||||
Test failed: llJsonSetValue with escaped string as value (for MAINT-2698), 'quote in beginning'
|
||||
Actual: u'***'
|
||||
|
@ -411,11 +411,11 @@ Test failed: llJsonSetValue with escaped string as key's value (for MAINT-2698),
|
|||
Actual: u'***'
|
||||
Expect: u'[{"\\"funkystring":"\\"funkystringvalue"},{"\\"funkystring":3,"b":"\\"funkystringvalue"}]'
|
||||
Test failed: llJson2List extracting object containing escaped string (for MAINT-2698), 'quote in beginning'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'{"\\\\"funkystring":"\\\\"funkystringvalue"}\', u\'{"\\\\"funkystring":3,"b":"\\\\"funkystringvalue"}\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'{"\\\\"funkystring":"\\\\"funkystringvalue"}\', u\'{"\\\\"funkystring":3,"b":"\\\\"funkystringvalue"}\']'
|
||||
Test failed: llJson2List extracting escaped strings (for MAINT-2698), 'quote in beginning'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'"funkystring\', u\'"funkystringvalue\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'"funkystring\', u\'"funkystringvalue\']'
|
||||
Test failed: llList2Json from escaped-containing string to array (for MAINT-2698), 'quote in beginning'
|
||||
Actual: u'["***"]'
|
||||
Expect: u'["\\"funkystring","\\"funkystringvalue"]'
|
||||
|
@ -423,7 +423,7 @@ Test failed: llList2Json from escaped-containing string to object (for MAINT-269
|
|||
Actual: u'{}'
|
||||
Expect: u'{"\\"funkystring":"\\"funkystringvalue"}'
|
||||
PASSED! Type of string with escaped char (for MAINT-2698), 'nothing that needs to be escaped..', expect=actual=u'\ufdd4'
|
||||
PASSED! llJsonGetValue [1,"vanilla string"] (for MAINT-2698), 'nothing that needs to be escaped..', expect=actual='3'
|
||||
PASSED! llJsonGetValue [1,"vanilla string"] (for MAINT-2698), 'nothing that needs to be escaped..', expect=actual=u'3'
|
||||
PASSED! llJsonGetValue [1,"b"] (for MAINT-2698), 'nothing that needs to be escaped..', expect=actual=u'vanilla stringvalue'
|
||||
Test failed: llJsonSetValue with escaped string as value (for MAINT-2698), 'nothing that needs to be escaped..'
|
||||
Actual: u'***'
|
||||
|
@ -435,11 +435,11 @@ Test failed: llJsonSetValue with escaped string as key's value (for MAINT-2698),
|
|||
Actual: u'***'
|
||||
Expect: u'[{"vanilla string":"vanilla stringvalue"},{"vanilla string":3,"b":"vanilla stringvalue"}]'
|
||||
Test failed: llJson2List extracting object containing escaped string (for MAINT-2698), 'nothing that needs to be escaped..'
|
||||
Actual: "[u'***']"
|
||||
Expect: '[u\'{"vanilla string":"vanilla stringvalue"}\', u\'{"vanilla string":3,"b":"vanilla stringvalue"}\']'
|
||||
Actual: u"[u'***']"
|
||||
Expect: u'[u\'{"vanilla string":"vanilla stringvalue"}\', u\'{"vanilla string":3,"b":"vanilla stringvalue"}\']'
|
||||
Test failed: llJson2List extracting escaped strings (for MAINT-2698), 'nothing that needs to be escaped..'
|
||||
Actual: "[u'***']"
|
||||
Expect: "[u'vanilla string', u'vanilla stringvalue']"
|
||||
Actual: u"[u'***']"
|
||||
Expect: u"[u'vanilla string', u'vanilla stringvalue']"
|
||||
Test failed: llList2Json from escaped-containing string to array (for MAINT-2698), 'nothing that needs to be escaped..'
|
||||
Actual: u'["***"]'
|
||||
Expect: u'["vanilla string","vanilla stringvalue"]'
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import sys
|
||||
from strutil import *
|
||||
from lslopt.lslfuncs import *
|
||||
|
||||
|
@ -6,344 +5,358 @@ tests = 0
|
|||
errors = 0
|
||||
|
||||
# Begin JSON tests from http://wiki.secondlife.com/wiki/Json_usage_in_LSL/TestScript
|
||||
|
||||
def xrepr(x):
|
||||
if python3:
|
||||
if type(x) == unicode:
|
||||
return 'u' + repr(x)
|
||||
if type(x) == list:
|
||||
return '[' + ', '.join(xrepr(i) for i in x) + ']'
|
||||
elif python2:
|
||||
if type(x) == bytes:
|
||||
return 'b' + repr(x)
|
||||
if type(x) == list:
|
||||
return '[' + ', '.join(xrepr(i) for i in x) + ']'
|
||||
return repr(x)
|
||||
|
||||
def verify(msg, result, expected):
|
||||
global tests
|
||||
tests += 1
|
||||
if expected != result:
|
||||
global errors
|
||||
errors += 1
|
||||
werr("Test failed: " + msg + '\n')
|
||||
werr("Actual: " + repr(result) + '\n')
|
||||
werr("Expect: " + repr(expected) + '\n')
|
||||
werr(u"Test failed: " + msg + u'\n')
|
||||
werr(u"Actual: " + str2u(xrepr(result)) + u'\n')
|
||||
werr(u"Expect: " + str2u(xrepr(expected)) + u'\n')
|
||||
#return 0
|
||||
else:
|
||||
werr("PASSED! %s, expect=actual=%s\n" % (msg, repr(expected)))
|
||||
werr("PASSED! %s, expect=actual=%s\n" % (msg, xrepr(expected)))
|
||||
#return 1
|
||||
|
||||
def verify_list(msg, result, expected):
|
||||
verify(msg, repr(result), repr(expected))
|
||||
verify(msg, str2u(xrepr(result)), str2u(xrepr(expected)))
|
||||
|
||||
def test_types():
|
||||
verify("Type of string",llJsonValueType(u"\"test\"",[]),JSON_STRING);
|
||||
verify("Type of string, unquoted",llJsonValueType(u"test",[]),JSON_INVALID);
|
||||
verify("Type of invalid",llJsonValueType(u"test",[]),JSON_INVALID);
|
||||
verify("Type of integer",llJsonValueType(u"12",[]),JSON_NUMBER);
|
||||
verify("Type of float",llJsonValueType(u"12.300000",[]),JSON_NUMBER);
|
||||
verify("Type of Inf (is unsupported by JSON standard)",llJsonValueType(u"Inf",[]),JSON_INVALID);
|
||||
verify("Type of NaN (is unsupported by JSON standard)",llJsonValueType(u"NaN",[]),JSON_INVALID);
|
||||
verify("Type of number",llJsonValueType(u"-123.4e-5",[]),JSON_NUMBER);
|
||||
verify("Type of object",llJsonValueType(u"{\"a\":\"b\"}",[]),JSON_OBJECT);
|
||||
verify(u"Type of string",llJsonValueType(u"\"test\"",[]),JSON_STRING);
|
||||
verify(u"Type of string, unquoted",llJsonValueType(u"test",[]),JSON_INVALID);
|
||||
verify(u"Type of invalid",llJsonValueType(u"test",[]),JSON_INVALID);
|
||||
verify(u"Type of integer",llJsonValueType(u"12",[]),JSON_NUMBER);
|
||||
verify(u"Type of float",llJsonValueType(u"12.300000",[]),JSON_NUMBER);
|
||||
verify(u"Type of Inf (is unsupported by JSON standard)",llJsonValueType(u"Inf",[]),JSON_INVALID);
|
||||
verify(u"Type of NaN (is unsupported by JSON standard)",llJsonValueType(u"NaN",[]),JSON_INVALID);
|
||||
verify(u"Type of number",llJsonValueType(u"-123.4e-5",[]),JSON_NUMBER);
|
||||
verify(u"Type of object",llJsonValueType(u"{\"a\":\"b\"}",[]),JSON_OBJECT);
|
||||
# Expected to be OBJECT, since we don't do deep validation on input
|
||||
#verify("Type of object, invalid/unquoted key",llJsonValueType(u"{a:\"b\"}",[]),JSON_INVALID);
|
||||
#verify(u"Type of object, invalid/unquoted key",llJsonValueType(u"{a:\"b\"}",[]),JSON_INVALID);
|
||||
\
|
||||
verify("Type of object, invalid/unquoted key",llJsonValueType(u"{a:\"b\"}",[]),JSON_OBJECT) # check so
|
||||
verify(u"Type of object, invalid/unquoted key",llJsonValueType(u"{a:\"b\"}",[]),JSON_OBJECT) # check so
|
||||
# Expected to be OBJECT, since we don't do deep validation on input
|
||||
#verify("Type of object, invalid/unquoted value",llJsonValueType(u"{\"a\":b}",[]),JSON_INVALID);
|
||||
#verify(u"Type of object, invalid/unquoted value",llJsonValueType(u"{\"a\":b}",[]),JSON_INVALID);
|
||||
\
|
||||
verify("Type of object, invalid/unquoted value",llJsonValueType(u"{\"a\":b}",[]),JSON_OBJECT) # check so
|
||||
verify("Type of array",llJsonValueType(u"[1,2,3]",[]),JSON_ARRAY);
|
||||
verify("Type of array padded front",llJsonValueType(u" [1,2,3]",[]),JSON_ARRAY);
|
||||
verify("Type of array padded back",llJsonValueType(u"[1,2,3] ",[]),JSON_ARRAY);
|
||||
verify("Type of array padded",llJsonValueType(u" [1,2,3] ",[]),JSON_ARRAY);
|
||||
verify("Type of true",llJsonValueType(u"true",[]),JSON_TRUE);
|
||||
verify("Type of false",llJsonValueType(u"false",[]),JSON_FALSE);
|
||||
verify("Type of null",llJsonValueType(u"null",[]),JSON_NULL);
|
||||
verify(u"Type of object, invalid/unquoted value",llJsonValueType(u"{\"a\":b}",[]),JSON_OBJECT) # check so
|
||||
verify(u"Type of array",llJsonValueType(u"[1,2,3]",[]),JSON_ARRAY);
|
||||
verify(u"Type of array padded front",llJsonValueType(u" [1,2,3]",[]),JSON_ARRAY);
|
||||
verify(u"Type of array padded back",llJsonValueType(u"[1,2,3] ",[]),JSON_ARRAY);
|
||||
verify(u"Type of array padded",llJsonValueType(u" [1,2,3] ",[]),JSON_ARRAY);
|
||||
verify(u"Type of true",llJsonValueType(u"true",[]),JSON_TRUE);
|
||||
verify(u"Type of false",llJsonValueType(u"false",[]),JSON_FALSE);
|
||||
verify(u"Type of null",llJsonValueType(u"null",[]),JSON_NULL);
|
||||
|
||||
# test traversal of llJsonValueType
|
||||
json = u"[[1,2,3],{\"a\":3,\"b\":[true,\"test\",6],\"c\":\"true\",\"d\":false}]";
|
||||
verify("Type of [0]",llJsonValueType(json,[0]),JSON_ARRAY);
|
||||
verify("Type of [0,1]",llJsonValueType(json,[0,1]),JSON_NUMBER);
|
||||
verify("Type of [1]",llJsonValueType(json,[1]),JSON_OBJECT);
|
||||
verify("Type of [1,\"b\"]",llJsonValueType(json,[1,u"b"]),JSON_ARRAY);
|
||||
verify("Type of [1,\"b\",0]",llJsonValueType(json,[1,u"b",0]),JSON_TRUE);
|
||||
verify("Type of [1,\"b\",1]",llJsonValueType(json,[1,u"b",1]),JSON_STRING);
|
||||
verify("Type of [1,\"b\",2]",llJsonValueType(json,[1,u"b",2]),JSON_NUMBER);
|
||||
verify("Type of [1,\"c\"]",llJsonValueType(json,[1,u"c"]),JSON_STRING);
|
||||
verify("Type of [1,\"d\"]",llJsonValueType(json,[1,u"d"]),JSON_FALSE);
|
||||
verify("Type of [3] (invalid index at level 0)",llJsonValueType(json,[3]),JSON_INVALID);
|
||||
verify("Type of [-1] (invalid index at level 0)",llJsonValueType(json,[-1]),JSON_INVALID);
|
||||
verify("Type of [1,\"c\",3] (invalid index at level 1), MAINT-2670",llJsonValueType(json,[1,u"c",3]),JSON_INVALID);
|
||||
verify(u"Type of [0]",llJsonValueType(json,[0]),JSON_ARRAY);
|
||||
verify(u"Type of [0,1]",llJsonValueType(json,[0,1]),JSON_NUMBER);
|
||||
verify(u"Type of [1]",llJsonValueType(json,[1]),JSON_OBJECT);
|
||||
verify(u"Type of [1,\"b\"]",llJsonValueType(json,[1,u"b"]),JSON_ARRAY);
|
||||
verify(u"Type of [1,\"b\",0]",llJsonValueType(json,[1,u"b",0]),JSON_TRUE);
|
||||
verify(u"Type of [1,\"b\",1]",llJsonValueType(json,[1,u"b",1]),JSON_STRING);
|
||||
verify(u"Type of [1,\"b\",2]",llJsonValueType(json,[1,u"b",2]),JSON_NUMBER);
|
||||
verify(u"Type of [1,\"c\"]",llJsonValueType(json,[1,u"c"]),JSON_STRING);
|
||||
verify(u"Type of [1,\"d\"]",llJsonValueType(json,[1,u"d"]),JSON_FALSE);
|
||||
verify(u"Type of [3] (invalid index at level 0)",llJsonValueType(json,[3]),JSON_INVALID);
|
||||
verify(u"Type of [-1] (invalid index at level 0)",llJsonValueType(json,[-1]),JSON_INVALID);
|
||||
verify(u"Type of [1,\"c\",3] (invalid index at level 1), MAINT-2670",llJsonValueType(json,[1,u"c",3]),JSON_INVALID);
|
||||
\
|
||||
verify("Type of [1,\"c\",0] (first element of non-nested object)",llJsonValueType(json,[1,u"c",0]),JSON_INVALID);
|
||||
verify(u"Type of [1,\"c\",0] (first element of non-nested object)",llJsonValueType(json,[1,u"c",0]),JSON_INVALID);
|
||||
# added by us
|
||||
verify("Type of [1,\"b\",3] (invalid index at level 2)",llJsonValueType(json,[1,u"b",3]),JSON_INVALID);
|
||||
verify("Type of [1,\"b\",2,0,1] (invalid index at level 3) MAINT-2670",llJsonValueType(json,[1,u"b",2, 0, 1]),JSON_INVALID);
|
||||
verify(u"Type of [1,\"b\",3] (invalid index at level 2)",llJsonValueType(json,[1,u"b",3]),JSON_INVALID);
|
||||
verify(u"Type of [1,\"b\",2,0,1] (invalid index at level 3) MAINT-2670",llJsonValueType(json,[1,u"b",2, 0, 1]),JSON_INVALID);
|
||||
|
||||
# some invalid cases where keys are uncoded
|
||||
json = u"[[1,2,3],{a:3,b:[true,\"test\",6],c:\"true\",\"d\":false}]";
|
||||
verify("Type of [1,\"a\"] where key is unquoted",llJsonValueType(json,[1,u"a"]),JSON_INVALID);
|
||||
verify("Type of [1,\"b\"] where key is unquoted",llJsonValueType(json,[1,u"b"]),JSON_INVALID);
|
||||
verify("Type of [1,\"c\"] where key is unquoted",llJsonValueType(json,[1,u"c"]),JSON_INVALID);
|
||||
verify(u"Type of [1,\"a\"] where key is unquoted",llJsonValueType(json,[1,u"a"]),JSON_INVALID);
|
||||
verify(u"Type of [1,\"b\"] where key is unquoted",llJsonValueType(json,[1,u"b"]),JSON_INVALID);
|
||||
verify(u"Type of [1,\"c\"] where key is unquoted",llJsonValueType(json,[1,u"c"]),JSON_INVALID);
|
||||
|
||||
|
||||
def test_get_value():
|
||||
json = u"[[1,2,3,4.0],{\"a\":3,\"b\":[true,\"test\",6]}]";
|
||||
verify("llJsonGetValue [0]",llJsonGetValue(json,[0]),u"[1,2,3,4.0]");
|
||||
verify("llJsonGetValue [0,1]",llJsonGetValue(json,[0,1]),u"2");
|
||||
verify("llJsonGetValue [1]",llJsonGetValue(json,[1]),u"{\"a\":3,\"b\":[true,\"test\",6]}");
|
||||
verify("llJsonGetValue [1,\"b\"]",llJsonGetValue(json,[1,u"b"]),u"[true,\"test\",6]");
|
||||
verify("llJsonGetValue [1,\"b\",0]",llJsonGetValue(json,[1,u"b",0]),JSON_TRUE);
|
||||
verify("llJsonGetValue [1,\"b\",1]",llJsonGetValue(json,[1,u"b",1]),u"test");
|
||||
verify("llJsonGetValue [1,\"b\",2]",llJsonGetValue(json,[1,u"b",2]),u"6");
|
||||
verify("llJsonGetValue [0,3]",llJsonGetValue(json,[0,3]), u"4.0");
|
||||
verify("llJsonGetValue [2] (invalid index at level 0)",llJsonGetValue(json,[2]),JSON_INVALID);
|
||||
verify("llJsonGetValue [-1] (invalid index at level 0)",llJsonGetValue(json,[-1]),JSON_INVALID);
|
||||
verify("llJsonGetValue [0,4] (invalid index within array)",llJsonGetValue(json,[0,4]),JSON_INVALID);
|
||||
verify("llJsonGetValue [\"f\"] (look for missing object within array, depth=0) MAINT-2671",llJsonGetValue(json,[u"f"]),JSON_INVALID);
|
||||
verify("llJsonGetValue [0,\"f\"] (look for missing object within array, depth=1) MAINT-2671",llJsonGetValue(json,[0,u"f"]),JSON_INVALID);
|
||||
verify("llJsonGetValue [1,2] (specify index within object - disallowed)",llJsonGetValue(json,[1,2]),JSON_INVALID);
|
||||
verify(u"llJsonGetValue [0]",llJsonGetValue(json,[0]),u"[1,2,3,4.0]");
|
||||
verify(u"llJsonGetValue [0,1]",llJsonGetValue(json,[0,1]),u"2");
|
||||
verify(u"llJsonGetValue [1]",llJsonGetValue(json,[1]),u"{\"a\":3,\"b\":[true,\"test\",6]}");
|
||||
verify(u"llJsonGetValue [1,\"b\"]",llJsonGetValue(json,[1,u"b"]),u"[true,\"test\",6]");
|
||||
verify(u"llJsonGetValue [1,\"b\",0]",llJsonGetValue(json,[1,u"b",0]),JSON_TRUE);
|
||||
verify(u"llJsonGetValue [1,\"b\",1]",llJsonGetValue(json,[1,u"b",1]),u"test");
|
||||
verify(u"llJsonGetValue [1,\"b\",2]",llJsonGetValue(json,[1,u"b",2]),u"6");
|
||||
verify(u"llJsonGetValue [0,3]",llJsonGetValue(json,[0,3]), u"4.0");
|
||||
verify(u"llJsonGetValue [2] (invalid index at level 0)",llJsonGetValue(json,[2]),JSON_INVALID);
|
||||
verify(u"llJsonGetValue [-1] (invalid index at level 0)",llJsonGetValue(json,[-1]),JSON_INVALID);
|
||||
verify(u"llJsonGetValue [0,4] (invalid index within array)",llJsonGetValue(json,[0,4]),JSON_INVALID);
|
||||
verify(u"llJsonGetValue [\"f\"] (look for missing object within array, depth=0) MAINT-2671",llJsonGetValue(json,[u"f"]),JSON_INVALID);
|
||||
verify(u"llJsonGetValue [0,\"f\"] (look for missing object within array, depth=1) MAINT-2671",llJsonGetValue(json,[0,u"f"]),JSON_INVALID);
|
||||
verify(u"llJsonGetValue [1,2] (specify index within object - disallowed)",llJsonGetValue(json,[1,2]),JSON_INVALID);
|
||||
|
||||
# invalid input json - missing quotes around 'a' and 'test'
|
||||
json = u"[[1,2,3,4.0],{a:3,\"b\":[true,test,6]}]";
|
||||
verify("llJsonGetValue [1,\"b\",1], unquoted/invalid string value",llJsonGetValue(json,[1,u"b",1]),JSON_INVALID);
|
||||
verify("llJsonGetValue [1,\"a\"], unquoted/invalid string for key",llJsonGetValue(json,[1,u"a"]),JSON_INVALID);
|
||||
verify(u"llJsonGetValue [1,\"b\",1], unquoted/invalid string value",llJsonGetValue(json,[1,u"b",1]),JSON_INVALID);
|
||||
verify(u"llJsonGetValue [1,\"a\"], unquoted/invalid string for key",llJsonGetValue(json,[1,u"a"]),JSON_INVALID);
|
||||
|
||||
def test_set_value():
|
||||
# Test building from scratch
|
||||
json = u""
|
||||
json = llJsonSetValue(json,[0,0],u"1");
|
||||
verify("llJsonSetValue build json",json,u"[[1]]");
|
||||
verify(u"llJsonSetValue build json",json,u"[[1]]");
|
||||
json = llJsonSetValue(json,[0,1],u"2");
|
||||
verify("llJsonSetValue build json",json,u"[[1,2]]");
|
||||
verify(u"llJsonSetValue build json",json,u"[[1,2]]");
|
||||
json = llJsonSetValue(json,[0,2],u"3");
|
||||
verify("llJsonSetValue build json",json,u"[[1,2,3]]");
|
||||
verify(u"llJsonSetValue build json",json,u"[[1,2,3]]");
|
||||
json = llJsonSetValue(json,[1,u"a"],u"3");
|
||||
verify("llJsonSetValue build json",json,u"[[1,2,3],{\"a\":3}]");
|
||||
verify(u"llJsonSetValue build json",json,u"[[1,2,3],{\"a\":3}]");
|
||||
json = llJsonSetValue(json,[1,u"b",0],JSON_TRUE);
|
||||
verify("llJsonSetValue build json",json,u"[[1,2,3],{\"a\":3,\"b\":[true]}]");
|
||||
verify(u"llJsonSetValue build json",json,u"[[1,2,3],{\"a\":3,\"b\":[true]}]");
|
||||
json = llJsonSetValue(json,[1,u"b",1],u"test");
|
||||
verify("llJsonSetValue build json",json,u"[[1,2,3],{\"a\":3,\"b\":[true,\"test\"]}]");
|
||||
verify(u"llJsonSetValue build json",json,u"[[1,2,3],{\"a\":3,\"b\":[true,\"test\"]}]");
|
||||
json = llJsonSetValue(json,[1,u"b",2],u"6");
|
||||
verify("llJsonSetValue completed json",json,u"[[1,2,3],{\"a\":3,\"b\":[true,\"test\",6]}]");
|
||||
verify(u"llJsonSetValue completed json",json,u"[[1,2,3],{\"a\":3,\"b\":[true,\"test\",6]}]");
|
||||
|
||||
# Test replacing
|
||||
json = llJsonSetValue(json,[1,u"b",1],u"foo");
|
||||
verify("llJsonSetValue completed json",json,u"[[1,2,3],{\"a\":3,\"b\":[true,\"foo\",6]}]");
|
||||
verify(u"llJsonSetValue completed json",json,u"[[1,2,3],{\"a\":3,\"b\":[true,\"foo\",6]}]");
|
||||
json = llJsonSetValue(json,[1,u"b"],JSON_TRUE);
|
||||
verify("llJsonSetValue completed json, true",json,u"[[1,2,3],{\"a\":3,\"b\":true}]");
|
||||
verify(u"llJsonSetValue completed json, true",json,u"[[1,2,3],{\"a\":3,\"b\":true}]");
|
||||
json = llJsonSetValue(json,[1,u"b"],u"true");
|
||||
verify("llJsonSetValue completed json, alt true",json,u"[[1,2,3],{\"a\":3,\"b\":true}]");
|
||||
verify(u"llJsonSetValue completed json, alt true",json,u"[[1,2,3],{\"a\":3,\"b\":true}]");
|
||||
json = llJsonSetValue(json,[1,0,0],JSON_FALSE);
|
||||
verify("llJsonSetValue completed json",json,u"[[1,2,3],[[false]]]");
|
||||
verify(u"llJsonSetValue completed json",json,u"[[1,2,3],[[false]]]");
|
||||
|
||||
# Test appending
|
||||
json = llJsonSetValue(u"[[1,2,3],{\"a\":3,\"b\":[true,\"test\",6]}]",[0,JSON_APPEND], u"4.0");
|
||||
verify("llJsonSetValue append to first array",json,u"[[1,2,3,4.0],{\"a\":3,\"b\":[true,\"test\",6]}]");
|
||||
verify(u"llJsonSetValue append to first array",json,u"[[1,2,3,4.0],{\"a\":3,\"b\":[true,\"test\",6]}]");
|
||||
json = llJsonSetValue(json,[1,u"b",JSON_APPEND], u"5.0");
|
||||
verify("llJsonSetValue append to array withhin object",json,u"[[1,2,3,4.0],{\"a\":3,\"b\":[true,\"test\",6,5.0]}]");
|
||||
verify(u"llJsonSetValue append to array withhin object",json,u"[[1,2,3,4.0],{\"a\":3,\"b\":[true,\"test\",6,5.0]}]");
|
||||
json = llJsonSetValue(json,[JSON_APPEND], u"6.0");
|
||||
verify("llJsonSetValue append to outer array",json,u"[[1,2,3,4.0],{\"a\":3,\"b\":[true,\"test\",6,5.0]},6.0]");
|
||||
verify(u"llJsonSetValue append to outer array",json,u"[[1,2,3,4.0],{\"a\":3,\"b\":[true,\"test\",6,5.0]},6.0]");
|
||||
json = llJsonSetValue(u"[]",[JSON_APPEND], u"\"alone\"");
|
||||
verify("llJsonSetValue append to empty array (MAINT-2684)",json,u"[\"alone\"]");
|
||||
verify(u"llJsonSetValue append to empty array (MAINT-2684)",json,u"[\"alone\"]");
|
||||
json = llJsonSetValue(u"[]",[1], u"\"alone\"");
|
||||
verify("llJsonSetValue append to empty array at invalid index (MAINT-2684)",json,JSON_INVALID);
|
||||
verify(u"llJsonSetValue append to empty array at invalid index (MAINT-2684)",json,JSON_INVALID);
|
||||
json = llJsonSetValue(u"[]",[0], u"\"alone\"");
|
||||
verify("llJsonSetValue append to empty array at first index (MAINT-2684)",json,u"[\"alone\"]");
|
||||
verify(u"llJsonSetValue append to empty array at first index (MAINT-2684)",json,u"[\"alone\"]");
|
||||
|
||||
# Test deleting
|
||||
json = u"[[1,2,3],{\"a\":3,\"b\":[true,\"test\",6,null]}]";
|
||||
json = llJsonSetValue(json,[1,u"b",1],JSON_DELETE);
|
||||
verify("llJsonSetValue deleting string in middle of array",json,u"[[1,2,3],{\"a\":3,\"b\":[true,6,null]}]");
|
||||
verify(u"llJsonSetValue deleting string in middle of array",json,u"[[1,2,3],{\"a\":3,\"b\":[true,6,null]}]");
|
||||
json = llJsonSetValue(json,[1,u"b",2],JSON_DELETE);
|
||||
verify("llJsonSetValue deleting null at end of array",json,u"[[1,2,3],{\"a\":3,\"b\":[true,6]}]");
|
||||
verify(u"llJsonSetValue deleting null at end of array",json,u"[[1,2,3],{\"a\":3,\"b\":[true,6]}]");
|
||||
json = llJsonSetValue(json,[1,u"b"],JSON_DELETE);
|
||||
verify("llJsonSetValue deleting key-value",json,u"[[1,2,3],{\"a\":3}]");
|
||||
verify(u"llJsonSetValue deleting key-value",json,u"[[1,2,3],{\"a\":3}]");
|
||||
json = llJsonSetValue(json,[1],JSON_DELETE);
|
||||
verify("llJsonSetValue deleting object in array",json,u"[[1,2,3]]");
|
||||
verify(u"llJsonSetValue deleting object in array",json,u"[[1,2,3]]");
|
||||
json = u"[[1,2,3],4]";
|
||||
json = llJsonSetValue(json,[0],JSON_DELETE);
|
||||
verify("llJsonSetValue deleting array (which is first index in array)",json,u"[4]");
|
||||
verify(u"llJsonSetValue deleting array (which is first index in array)",json,u"[4]");
|
||||
json = llJsonSetValue(json,[0],JSON_DELETE);
|
||||
verify("llJsonSetValue deleting last element in array",json,u"[]");
|
||||
verify(u"llJsonSetValue deleting last element in array",json,u"[]");
|
||||
json = u"[[1]]";
|
||||
json = llJsonSetValue(json,[0,0],JSON_DELETE);
|
||||
verify("llJsonSetValue deleting last element in array",json,u"[[]]");
|
||||
verify(u"llJsonSetValue deleting last element in array",json,u"[[]]");
|
||||
json = llJsonSetValue(json,[0],JSON_DELETE);
|
||||
verify("llJsonSetValue deleting array within array",json,u"[]");
|
||||
verify(u"llJsonSetValue deleting array within array",json,u"[]");
|
||||
|
||||
# Test failures in deleting
|
||||
json = u"[[1,2,3],{\"a\":3,\"b\":[true,\"test\",6,null]}]";
|
||||
verify("llJsonSetValue deleting undefined key-value in object",llJsonSetValue(json,[1,u"d"],JSON_DELETE),JSON_INVALID);
|
||||
verify("llJsonSetValue deleting out-of-range index in array",llJsonSetValue(json,[2],JSON_DELETE),JSON_INVALID);
|
||||
verify("llJsonSetValue deleting depth within object that doesn't exist",llJsonSetValue(json,[1,u"a",u"unicorn"],JSON_DELETE),JSON_INVALID);
|
||||
verify("llJsonSetValue deleting depth within array that doesn't exist",llJsonSetValue(json,[0,1,1],JSON_DELETE),JSON_INVALID);
|
||||
verify(u"llJsonSetValue deleting undefined key-value in object",llJsonSetValue(json,[1,u"d"],JSON_DELETE),JSON_INVALID);
|
||||
verify(u"llJsonSetValue deleting out-of-range index in array",llJsonSetValue(json,[2],JSON_DELETE),JSON_INVALID);
|
||||
verify(u"llJsonSetValue deleting depth within object that doesn't exist",llJsonSetValue(json,[1,u"a",u"unicorn"],JSON_DELETE),JSON_INVALID);
|
||||
verify(u"llJsonSetValue deleting depth within array that doesn't exist",llJsonSetValue(json,[0,1,1],JSON_DELETE),JSON_INVALID);
|
||||
|
||||
# this is the only failure mode that should exist.
|
||||
json = u"[[1,2,3],{\"a\":3,\"b\":[true,\"foo\",6]}]";
|
||||
json = llJsonSetValue(json,[3],JSON_FALSE);
|
||||
verify("llJsonSetValue fail to insert data into invalid array index (MAINT-2675)",json,JSON_INVALID);
|
||||
verify(u"llJsonSetValue fail to insert data into invalid array index (MAINT-2675)",json,JSON_INVALID);
|
||||
|
||||
def test_json_to_list():
|
||||
l = llJson2List(u"[[1,2,3],{\"a\":3,\"b\":[true,\"test\",6]}]");
|
||||
verify_list("llJson2List first",l,[u"[1,2,3]",u"{\"a\":3,\"b\":[true,\"test\",6]}"]);
|
||||
verify_list(u"llJson2List first",l,[u"[1,2,3]",u"{\"a\":3,\"b\":[true,\"test\",6]}"]);
|
||||
n = llJson2List(llList2String(l,0));
|
||||
verify_list("llJson2List l,0",n,[1,2,3]);
|
||||
verify_list(u"llJson2List l,0",n,[1,2,3]);
|
||||
n = llJson2List(llList2String(l,1));
|
||||
verify_list("llJson2List l,1",n,[u"a",3,u"b",u"[true,\"test\",6]"]);
|
||||
verify_list(u"llJson2List l,1",n,[u"a",3,u"b",u"[true,\"test\",6]"]);
|
||||
n = llJson2List(llList2String(n,3));
|
||||
verify_list("llJson2List n,3",n,[JSON_TRUE, u"test", 6]);
|
||||
verify_list(u"llJson2List n,3",n,[JSON_TRUE, u"test", 6]);
|
||||
n = llJson2List(llList2String(n,1));
|
||||
verify_list("llJson2List n,1",n,[u"test"]);
|
||||
verify_list(u"llJson2List n,1",n,[u"test"]);
|
||||
n = llJson2List(u"");
|
||||
verify_list("Empty JSON string becomes empty list",n,[]);
|
||||
verify_list(u"Empty JSON string becomes empty list",n,[]);
|
||||
n = llJson2List(u"[]");
|
||||
verify_list("Empty JSON array becomes empty list (MAINT-2678)",n,[]);
|
||||
verify_list(u"Empty JSON array becomes empty list (MAINT-2678)",n,[]);
|
||||
n = llJson2List(u"{}");
|
||||
verify_list("Empty JSON object becomes empty list (MAINT-2678)",n,[]);
|
||||
verify_list(u"Empty JSON object becomes empty list (MAINT-2678)",n,[]);
|
||||
n = llJson2List(u"Non-JSON string, with comma");
|
||||
verify_list("llJson2List for non-JSON string is stored as a single object",n,[u"Non-JSON string, with comma"]);
|
||||
verify_list(u"llJson2List for non-JSON string is stored as a single object",n,[u"Non-JSON string, with comma"]);
|
||||
n = llJson2List(u"[malformed}");
|
||||
verify_list("llJson2List, malformed input",n,[u"[malformed}"]);
|
||||
verify_list(u"llJson2List, malformed input",n,[u"[malformed}"]);
|
||||
|
||||
def test_list_to_json():
|
||||
TRUE=1
|
||||
# test objects
|
||||
json = llList2Json(JSON_OBJECT,[u"a",1,u"b",2.5,u"c",u"test",u"d",u"true",u"e",u"[1,2,3]"]);
|
||||
verify("llList2Json, json object",json,u"{\"a\":1,\"b\":2.500000,\"c\":\"test\",\"d\":true,\"e\":[1,2,3]}");
|
||||
verify(u"llList2Json, json object",json,u"{\"a\":1,\"b\":2.500000,\"c\":\"test\",\"d\":true,\"e\":[1,2,3]}");
|
||||
|
||||
# test arrays
|
||||
json = llList2Json(JSON_ARRAY,[1,2.5,u"test",u"true",u"[1,2,3]"]);
|
||||
verify("llList2Json, json array",json,u"[1,2.500000,\"test\",true,[1,2,3]]");
|
||||
verify(u"llList2Json, json array",json,u"[1,2.500000,\"test\",true,[1,2,3]]");
|
||||
|
||||
# test arrays
|
||||
json = llList2Json(JSON_ARRAY,[1,2.5,u"test",JSON_TRUE,u"[1,2,3]"]);
|
||||
verify("llList2Json, json array, alternative true representation",json,u"[1,2.500000,\"test\",true,[1,2,3]]");
|
||||
verify(u"llList2Json, json array, alternative true representation",json,u"[1,2.500000,\"test\",true,[1,2,3]]");
|
||||
|
||||
# test objects, with empty input
|
||||
json = llList2Json(JSON_OBJECT,[]);
|
||||
verify("llList2Json, json object with empty input (MAINT-2681)",json,u"{}");
|
||||
verify(u"llList2Json, json object with empty input (MAINT-2681)",json,u"{}");
|
||||
|
||||
# test arrays, with empty input
|
||||
json = llList2Json(JSON_ARRAY,[]);
|
||||
verify("llList2Json, json array with empty input (MAINT-2681)",json,u"[]");
|
||||
verify(u"llList2Json, json array with empty input (MAINT-2681)",json,u"[]");
|
||||
|
||||
# test objects which are truncated
|
||||
json = llList2Json(JSON_OBJECT,[u"a",1,u"b",2.5,u"c",u"test",u"d",u"true",u"e"]);
|
||||
verify("llList2Json, json object, truncated",json,JSON_INVALID);
|
||||
verify(u"llList2Json, json object, truncated",json,JSON_INVALID);
|
||||
|
||||
# test objects which has a non-string identifier somewhere
|
||||
json = llList2Json(JSON_OBJECT,[u"a",1,TRUE,2.5,u"c",u"test",u"d",u"true",u"e"]);
|
||||
verify("llList2Json, json object, non-string in one of the first stride values",json,JSON_INVALID);
|
||||
verify(u"llList2Json, json object, non-string in one of the first stride values",json,JSON_INVALID);
|
||||
|
||||
# test invalid type
|
||||
json = llList2Json(u"foo",[u"a",1,u"b",2.5,u"c",u"test",u"d",u"true",u"e",u"[1,2,3]"]);
|
||||
verify("llList2Json, json invalid type",json,JSON_INVALID);
|
||||
verify(u"llList2Json, json invalid type",json,JSON_INVALID);
|
||||
|
||||
def test_strings_with_escaped_chars():
|
||||
escaped_pairs = [
|
||||
(u"funky\"string", u"funky\\\"string", "quote in middle"),
|
||||
(u"funkystr\"ing", u"funkystr\\\"ing", "quote in middle, other position"),
|
||||
(u"funky\"string", u"funky\\\"string", u"quote in middle"),
|
||||
(u"funkystr\"ing", u"funkystr\\\"ing", u"quote in middle, other position"),
|
||||
# note that we have to double-up backslashes to assign them to strings..
|
||||
(u"funky\\string", u"funky\\\\string", "backslashes in middle"),
|
||||
(u"\\funkystring", u"\\\\funkystring", "backslashes at beginning"),
|
||||
(u"funky\nstring", u"funky\\nstring", "newline in string"),
|
||||
(u"funky/string", u"funky\\/string", "forward slash in string"),
|
||||
(u"funky\\string", u"funky\\\\string", u"backslashes in middle"),
|
||||
(u"\\funkystring", u"\\\\funkystring", u"backslashes at beginning"),
|
||||
(u"funky\nstring", u"funky\\nstring", u"newline in string"),
|
||||
(u"funky/string", u"funky\\/string", u"forward slash in string"),
|
||||
# TAB (\t) fails, because it seems that LSL automatically converts any tab into 4 consecutive spaces.
|
||||
(u"funky\tstring", u"funky\\tstring", "tab in string"), # we enable it, with some mods
|
||||
(u"funky\tstring", u"funky\\tstring", u"tab in string"), # we enable it, with some mods
|
||||
# these cases fail; it seems that LSL doesn't support these characters, and strips the '\'
|
||||
(u"funky\x08string", u"funky\\bstring", "backspace in middle"), # we enable it, with some mods
|
||||
(u"funky\x0Cstring", u"funky\\fstring", "form feed in middle"), # we enable it, with some mods
|
||||
(u"funky\rstring", "funky\\rstring", "carriage return in string"), # we enable it, with some mods
|
||||
(u"funky\x08string", u"funky\\bstring", u"backspace in middle"), # we enable it, with some mods
|
||||
(u"funky\x0Cstring", u"funky\\fstring", u"form feed in middle"), # we enable it, with some mods
|
||||
(u"funky\rstring", "funky\\rstring", u"carriage return in string"), # we enable it, with some mods
|
||||
# note that the following case can't be supported, since strings starting with \" can't be escaped
|
||||
(u"\"funkystring", u"\\\"funkystring", "quote in beginning"), # we enable it as it's supported
|
||||
(u"vanilla string", u"vanilla string", "nothing that needs to be escaped..")
|
||||
(u"\"funkystring", u"\\\"funkystring", u"quote in beginning"), # we enable it as it's supported
|
||||
(u"vanilla string", u"vanilla string", u"nothing that needs to be escaped..")
|
||||
];
|
||||
for funky_string, funky_string_escaped, escaped_desc1 in escaped_pairs:
|
||||
escaped_desc = " '" + escaped_desc1 + "'"
|
||||
escaped_desc = u" '" + escaped_desc1 + u"'"
|
||||
|
||||
verify("Type of string with escaped char (for MAINT-2698),"+escaped_desc,llJsonValueType(u"\""+funky_string_escaped+u"\"",[]),JSON_STRING);
|
||||
verify(u"Type of string with escaped char (for MAINT-2698),"+escaped_desc,llJsonValueType(u"\""+funky_string_escaped+u"\"",[]),JSON_STRING);
|
||||
|
||||
json = u"[[1,2,3,4.0],{\""+funky_string_escaped+u"\":3,\"b\":\""+funky_string_escaped+u"value\"}]";
|
||||
verify("llJsonGetValue [1,\""+str(funky_string_escaped)+"\"] (for MAINT-2698),"+escaped_desc,
|
||||
llJsonGetValue(json,[1,funky_string]),"3");
|
||||
verify("llJsonGetValue [1,\"b\"] (for MAINT-2698),"+escaped_desc,llJsonGetValue(json,[1,u"b"]),funky_string+u"value");
|
||||
verify(u"llJsonGetValue [1,\""+funky_string_escaped+"\"] (for MAINT-2698),"+escaped_desc,
|
||||
llJsonGetValue(json,[1,funky_string]),u"3");
|
||||
verify(u"llJsonGetValue [1,\"b\"] (for MAINT-2698),"+escaped_desc,llJsonGetValue(json,[1,u"b"]),funky_string+u"value");
|
||||
|
||||
#llSay(0, "DEBU G: '" + llEscapeURL(json) + "' is input for test " + escaped_desc);
|
||||
json = llJsonSetValue(json,[0],funky_string);
|
||||
verify("llJsonSetValue with escaped string as value (for MAINT-2698),"+escaped_desc,json,
|
||||
verify(u"llJsonSetValue with escaped string as value (for MAINT-2698),"+escaped_desc,json,
|
||||
u"[\""+funky_string_escaped+u"\",{\""+funky_string_escaped+u"\":3,\"b\":\""+funky_string_escaped+u"value\"}]");
|
||||
|
||||
json = llJsonSetValue(json,[0],funky_string);
|
||||
verify("llJsonSetValue with escaped string as value (for MAINT-2698),"+escaped_desc,json,
|
||||
verify(u"llJsonSetValue with escaped string as value (for MAINT-2698),"+escaped_desc,json,
|
||||
u"[\""+funky_string_escaped+u"\",{\""+funky_string_escaped+u"\":3,\"b\":\""+funky_string_escaped+u"value\"}]");
|
||||
|
||||
json = llJsonSetValue(json,[0,funky_string], funky_string+u"value");
|
||||
verify("llJsonSetValue with escaped string as key's value (for MAINT-2698),"+escaped_desc,json,
|
||||
verify(u"llJsonSetValue with escaped string as key's value (for MAINT-2698),"+escaped_desc,json,
|
||||
u"[{\""+funky_string_escaped+u"\":\""+funky_string_escaped+u"value\"},{\""+funky_string_escaped+u"\":3,\"b\":\""+funky_string_escaped+u"value\"}]");
|
||||
|
||||
l = llJson2List(json);
|
||||
verify_list("llJson2List extracting object containing escaped string (for MAINT-2698),"+escaped_desc, l,
|
||||
verify_list(u"llJson2List extracting object containing escaped string (for MAINT-2698),"+escaped_desc, l,
|
||||
[u"{\""+funky_string_escaped+u"\":\""+funky_string_escaped+u"value\"}",u"{\""+funky_string_escaped+u"\":3,\"b\":\""+funky_string_escaped+u"value\"}"]);
|
||||
n = llJson2List(llList2String(l, 0));
|
||||
verify_list("llJson2List extracting escaped strings (for MAINT-2698),"+escaped_desc, n,
|
||||
verify_list(u"llJson2List extracting escaped strings (for MAINT-2698),"+escaped_desc, n,
|
||||
[funky_string,funky_string+u"value"]);
|
||||
|
||||
json = llList2Json(JSON_ARRAY,n);
|
||||
verify("llList2Json from escaped-containing string to array (for MAINT-2698),"+escaped_desc,json,
|
||||
verify(u"llList2Json from escaped-containing string to array (for MAINT-2698),"+escaped_desc,json,
|
||||
u"[\""+funky_string_escaped+u"\",\""+funky_string_escaped+u"value\"]");
|
||||
|
||||
json = llList2Json(JSON_OBJECT,n);
|
||||
verify("llList2Json from escaped-containing string to object (for MAINT-2698),"+escaped_desc,json,
|
||||
verify(u"llList2Json from escaped-containing string to object (for MAINT-2698),"+escaped_desc,json,
|
||||
u"{\""+funky_string_escaped+u"\":\""+funky_string_escaped+u"value\"}");
|
||||
|
||||
def maint3070():
|
||||
verify("Set value 'messa[g]e'", llJsonSetValue(u"",[u"toast"],u"messa[g]e"), u"{\"toast\":\"messa[g]e\"}");
|
||||
verify("Set value 'messag[e]'", llJsonSetValue(u"",[u"toast"],u"messag[e]"), u"{\"toast\":\"messag[e]\"}");
|
||||
#verify("Set value 'messag\[e\]'", llJsonSetValue(u"",[u"toast"],u"messag\[e\]"), u"{\"toast\":\"messag[e]\"}");
|
||||
verify(u"Set value 'messa[g]e'", llJsonSetValue(u"",[u"toast"],u"messa[g]e"), u"{\"toast\":\"messa[g]e\"}");
|
||||
verify(u"Set value 'messag[e]'", llJsonSetValue(u"",[u"toast"],u"messag[e]"), u"{\"toast\":\"messag[e]\"}");
|
||||
#verify(u"Set value 'messag\[e\]'", llJsonSetValue(u"",[u"toast"],u"messag\[e\]"), u"{\"toast\":\"messag[e]\"}");
|
||||
# ^^ BROKEN!!!!! LSL does not include the backslashes in the strings, so the above test is redundant.
|
||||
# Python does, thus making that test would break it. We include our own test tho:
|
||||
\
|
||||
verify("Set value 'messag\\[e\\]'", llJsonSetValue(u"",[u"toast"],u"messag\\[e\\]"), u"{\"toast\":\"messag\\\\[e\\\\]\"}");
|
||||
verify(u"Set value 'messag\\[e\\]'", llJsonSetValue(u"",[u"toast"],u"messag\\[e\\]"), u"{\"toast\":\"messag\\\\[e\\\\]\"}");
|
||||
|
||||
def maint4187():
|
||||
verify("Valid json number with + before exponent", llJsonValueType(u"1.0e+1", []), JSON_NUMBER);
|
||||
verify("Valid json number with - before exponent", llJsonValueType(u"1.0e-1", []), JSON_NUMBER);
|
||||
verify("Valid json number with - before exponent and mantissa", llJsonValueType(u"-1.0e-1", []), JSON_NUMBER);
|
||||
verify("Valid json number with unsigned exponent", llJsonValueType(u"1.0e1", []), JSON_NUMBER);
|
||||
verify("Invalid json number due to + before mantissa", llJsonValueType(u"+1.0e1", []), JSON_INVALID);
|
||||
verify(u"Valid json number with + before exponent", llJsonValueType(u"1.0e+1", []), JSON_NUMBER);
|
||||
verify(u"Valid json number with - before exponent", llJsonValueType(u"1.0e-1", []), JSON_NUMBER);
|
||||
verify(u"Valid json number with - before exponent and mantissa", llJsonValueType(u"-1.0e-1", []), JSON_NUMBER);
|
||||
verify(u"Valid json number with unsigned exponent", llJsonValueType(u"1.0e1", []), JSON_NUMBER);
|
||||
verify(u"Invalid json number due to + before mantissa", llJsonValueType(u"+1.0e1", []), JSON_INVALID);
|
||||
|
||||
verify("Invalid json number due to leading e", llJsonValueType(u"e1", []), JSON_INVALID);
|
||||
verify("Invalid json number due to leading 0", llJsonValueType(u"01", []), JSON_INVALID);
|
||||
verify("Invalid json number due to leading -0", llJsonValueType(u"-01", []), JSON_INVALID);
|
||||
verify("Valid json number with 0 immediately before .", llJsonValueType(u"0.01", []), JSON_NUMBER);
|
||||
verify("Valid json number with -0 immediately before .", llJsonValueType(u"-0.01", []), JSON_NUMBER);
|
||||
verify(u"Invalid json number due to leading e", llJsonValueType(u"e1", []), JSON_INVALID);
|
||||
verify(u"Invalid json number due to leading 0", llJsonValueType(u"01", []), JSON_INVALID);
|
||||
verify(u"Invalid json number due to leading -0", llJsonValueType(u"-01", []), JSON_INVALID);
|
||||
verify(u"Valid json number with 0 immediately before .", llJsonValueType(u"0.01", []), JSON_NUMBER);
|
||||
verify(u"Valid json number with -0 immediately before .", llJsonValueType(u"-0.01", []), JSON_NUMBER);
|
||||
|
||||
def maint3053():
|
||||
jT1 = u"[1, 2]"; # A JSON array
|
||||
verify("llJsonSetValue(jT1,[2],\"t\")",llJsonSetValue(jT1,[2],u"t"),u"[1,2,\"t\"]");
|
||||
verify("llJsonSetValue(jT1,[3],\"t\")",llJsonSetValue(jT1,[3],u"t"),JSON_INVALID);
|
||||
verify("llJsonSetValue(jT1,[0, 0],\"t\")",llJsonSetValue(jT1,[0, 0],u"t"),u"[[\"t\"],2]");
|
||||
verify("llJsonSetValue(jT1,[0, 0, 2, \"t\", 75],\"t\")",llJsonSetValue(jT1,[0, 0, 2, u"t", 75],u"t"),JSON_INVALID);
|
||||
verify("llJsonSetValue(jT1,[0, 1],\"t\")",llJsonSetValue(jT1,[0, 1],u"t"),JSON_INVALID);
|
||||
verify("llJsonSetValue(jT1,[0, 1, 2, \"t\", 75],\"t\")",llJsonSetValue(jT1,[0, 1, 2, u"t", 75],u"t"),JSON_INVALID);
|
||||
verify(u"llJsonSetValue(jT1,[2],\"t\")",llJsonSetValue(jT1,[2],u"t"),u"[1,2,\"t\"]");
|
||||
verify(u"llJsonSetValue(jT1,[3],\"t\")",llJsonSetValue(jT1,[3],u"t"),JSON_INVALID);
|
||||
verify(u"llJsonSetValue(jT1,[0, 0],\"t\")",llJsonSetValue(jT1,[0, 0],u"t"),u"[[\"t\"],2]");
|
||||
verify(u"llJsonSetValue(jT1,[0, 0, 2, \"t\", 75],\"t\")",llJsonSetValue(jT1,[0, 0, 2, u"t", 75],u"t"),JSON_INVALID);
|
||||
verify(u"llJsonSetValue(jT1,[0, 1],\"t\")",llJsonSetValue(jT1,[0, 1],u"t"),JSON_INVALID);
|
||||
verify(u"llJsonSetValue(jT1,[0, 1, 2, \"t\", 75],\"t\")",llJsonSetValue(jT1,[0, 1, 2, u"t", 75],u"t"),JSON_INVALID);
|
||||
|
||||
jT2 = u"[ [\"A\", \"B\", \"C\"], 2]";
|
||||
verify("llJsonSetValue(jT2,[0, 3],\"t\")",llJsonSetValue(jT2,[0, 3],u"t"),u"[[\"A\",\"B\",\"C\",\"t\"],2]");
|
||||
verify("llJsonSetValue(jT2,[0, 4],\"t\")",llJsonSetValue(jT2,[0, 4],u"t"),JSON_INVALID);
|
||||
verify("llJsonSetValue(jT2,[0, 1, 0],\"t\")",llJsonSetValue(jT2,[0, 1, 0],u"t"),u"[[\"A\",[\"t\"],\"C\"],2]");
|
||||
verify("llJsonSetValue(jT2,[0, 1, 1],\"t\")",llJsonSetValue(jT2,[0, 1, 1],u"t"),JSON_INVALID);
|
||||
verify(u"llJsonSetValue(jT2,[0, 3],\"t\")",llJsonSetValue(jT2,[0, 3],u"t"),u"[[\"A\",\"B\",\"C\",\"t\"],2]");
|
||||
verify(u"llJsonSetValue(jT2,[0, 4],\"t\")",llJsonSetValue(jT2,[0, 4],u"t"),JSON_INVALID);
|
||||
verify(u"llJsonSetValue(jT2,[0, 1, 0],\"t\")",llJsonSetValue(jT2,[0, 1, 0],u"t"),u"[[\"A\",[\"t\"],\"C\"],2]");
|
||||
verify(u"llJsonSetValue(jT2,[0, 1, 1],\"t\")",llJsonSetValue(jT2,[0, 1, 1],u"t"),JSON_INVALID);
|
||||
|
||||
jT3 = u"{\"1\":2}";
|
||||
verify("llJsonSetValue(jT3,[\"1\"],\"t\")",llJsonSetValue(jT3,[u"1"],u"t"),u"{\"1\":\"t\"}");
|
||||
verify("llJsonSetValue(jT3,[\"1\",0],\"t\")",llJsonSetValue(jT3,[u"1",0],u"t"),u"{\"1\":[\"t\"]}");
|
||||
verify("llJsonSetValue(jT3,[\"1\",1],\"t\")",llJsonSetValue(jT3,[u"1",1],u"t"),JSON_INVALID);
|
||||
verify(u"llJsonSetValue(jT3,[\"1\"],\"t\")",llJsonSetValue(jT3,[u"1"],u"t"),u"{\"1\":\"t\"}");
|
||||
verify(u"llJsonSetValue(jT3,[\"1\",0],\"t\")",llJsonSetValue(jT3,[u"1",0],u"t"),u"{\"1\":[\"t\"]}");
|
||||
verify(u"llJsonSetValue(jT3,[\"1\",1],\"t\")",llJsonSetValue(jT3,[u"1",1],u"t"),JSON_INVALID);
|
||||
|
||||
jGood = u"[null, 2]";
|
||||
verify("llJsonValueType(jGood, [0])",llJsonValueType(jGood, [0]),JSON_NULL);
|
||||
verify("llJsonValueType(jGood, [0, 0])",llJsonValueType(jGood, [0, 0]),JSON_INVALID);
|
||||
verify(u"llJsonValueType(jGood, [0])",llJsonValueType(jGood, [0]),JSON_NULL);
|
||||
verify(u"llJsonValueType(jGood, [0, 0])",llJsonValueType(jGood, [0, 0]),JSON_INVALID);
|
||||
|
||||
jBad = u"[, 2]";
|
||||
verify("llJsonValueType(jBad,[0])",llJsonValueType(jBad,[0]),JSON_INVALID);
|
||||
verify("llJsonValueType(jBad,[0, 0, 2, \"t\", 75])",llJsonValueType(jBad,[0, 0, 2, u"t", 75]),JSON_INVALID);
|
||||
verify("llJsonGetValue(jBad,[1, 0, 2, \"t\", 75])",llJsonGetValue(jBad,[1, 0, 2, u"t", 75]),JSON_INVALID);
|
||||
verify(u"llJsonValueType(jBad,[0])",llJsonValueType(jBad,[0]),JSON_INVALID);
|
||||
verify(u"llJsonValueType(jBad,[0, 0, 2, \"t\", 75])",llJsonValueType(jBad,[0, 0, 2, u"t", 75]),JSON_INVALID);
|
||||
verify(u"llJsonGetValue(jBad,[1, 0, 2, \"t\", 75])",llJsonGetValue(jBad,[1, 0, 2, u"t", 75]),JSON_INVALID);
|
||||
|
||||
def maint3081():
|
||||
verify("llJsonSetValue blank string",llJsonSetValue(u"",[u"test"],u""),u"{\"test\":\"\"}");
|
||||
verify("llJsonSetValue JSON_NULL",llJsonSetValue(u"",[u"test"],JSON_NULL),u"{\"test\":null}");
|
||||
verify("llJsonGetValue blank string",llJsonGetValue(u"{\"test\":\"\"}",[u"test"]),u"");
|
||||
verify("llJsonGetValue JSON_NULL",llJsonGetValue(u"{\"test\":null}",[u"test"]),JSON_NULL);
|
||||
verify("Identity (set->get) blank string",llJsonGetValue(llJsonSetValue(u"",[u"test"],u""),[u"test"]),u"");
|
||||
verify("Identity (set->get) JSON_NULL",llJsonGetValue(llJsonSetValue(u"",[u"test"],JSON_NULL),[u"test"]),JSON_NULL);
|
||||
verify(u"llJsonSetValue blank string",llJsonSetValue(u"",[u"test"],u""),u"{\"test\":\"\"}");
|
||||
verify(u"llJsonSetValue JSON_NULL",llJsonSetValue(u"",[u"test"],JSON_NULL),u"{\"test\":null}");
|
||||
verify(u"llJsonGetValue blank string",llJsonGetValue(u"{\"test\":\"\"}",[u"test"]),u"");
|
||||
verify(u"llJsonGetValue JSON_NULL",llJsonGetValue(u"{\"test\":null}",[u"test"]),JSON_NULL);
|
||||
verify(u"Identity (set->get) blank string",llJsonGetValue(llJsonSetValue(u"",[u"test"],u""),[u"test"]),u"");
|
||||
verify(u"Identity (set->get) JSON_NULL",llJsonGetValue(llJsonSetValue(u"",[u"test"],JSON_NULL),[u"test"]),JSON_NULL);
|
||||
|
||||
def test_jira_fixes():
|
||||
# FIXME: llJsonSetValue pending
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
REGEX
|
||||
default
|
||||
{
|
||||
touch(integer LslLibrary)
|
||||
{
|
||||
\{
|
||||
touch\(integer ([a-zA-Z]+)\)
|
||||
\{
|
||||
integer loc____ret__00001;
|
||||
{
|
||||
{
|
||||
\{
|
||||
\{
|
||||
loc____ret__00001 = 3;
|
||||
;
|
||||
}
|
||||
}
|
||||
\}
|
||||
\}
|
||||
@___rtl__00001;
|
||||
loc____ret__00001;
|
||||
LslLibrary++;
|
||||
}
|
||||
}
|
||||
\1\+\+;
|
||||
\}
|
||||
\}
|
||||
|
|
Loading…
Reference in a new issue