aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/API/python_api
diff options
context:
space:
mode:
authorMed Ismail Bennani <ismail@bennani.ma>2024-08-07 11:21:27 -0700
committerGitHub <noreply@github.com>2024-08-07 11:21:27 -0700
commit585523750e2bbe374d1cb3bf4ff9d53de29b9593 (patch)
tree725f81c96cdddda3f20b71cc52d7ec7b917bbbb5 /lldb/test/API/python_api
parent04e7eaf91f3e9b6830feb2e08bb5b0ddb14c3174 (diff)
downloadllvm-585523750e2bbe374d1cb3bf4ff9d53de29b9593.zip
llvm-585523750e2bbe374d1cb3bf4ff9d53de29b9593.tar.gz
llvm-585523750e2bbe374d1cb3bf4ff9d53de29b9593.tar.bz2
[lldb/API] Fix SBStructuredData support any JSON type (#101929)
This patch loosen the parsing requirement to allow parsing not only JSON dictionaries but also valid JSON type (integer, float, string, bool, array, null). Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
Diffstat (limited to 'lldb/test/API/python_api')
-rw-r--r--lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py b/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py
index b3db3bc6..21256d6 100644
--- a/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py
+++ b/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py
@@ -110,6 +110,37 @@ class TestStructuredDataAPI(TestBase):
self.assertTrue(my_random_class)
self.assertEqual(my_random_class.payload, MyRandomClass.payload)
+ example = lldb.SBStructuredData()
+ self.assertSuccess(example.SetFromJSON("1"))
+ self.assertEqual(example.GetType(), lldb.eStructuredDataTypeInteger)
+ self.assertEqual(example.GetIntegerValue(), 1)
+
+ self.assertSuccess(example.SetFromJSON("4.19"))
+ self.assertEqual(example.GetType(), lldb.eStructuredDataTypeFloat)
+ self.assertEqual(example.GetFloatValue(), 4.19)
+
+ self.assertSuccess(example.SetFromJSON('"Bonjour, 123!"'))
+ self.assertEqual(example.GetType(), lldb.eStructuredDataTypeString)
+ self.assertEqual(example.GetStringValue(42), "Bonjour, 123!")
+
+ self.assertSuccess(example.SetFromJSON("true"))
+ self.assertEqual(example.GetType(), lldb.eStructuredDataTypeBoolean)
+ self.assertTrue(example.GetBooleanValue())
+
+ self.assertSuccess(example.SetFromJSON("null"))
+ self.assertEqual(example.GetType(), lldb.eStructuredDataTypeNull)
+
+ example_arr = [1, 2.3, "4", {"5": False}]
+ arr_str = json.dumps(example_arr)
+ s.Clear()
+ s.Print(arr_str)
+ self.assertSuccess(example.SetFromJSON(s))
+
+ s.Clear()
+ self.assertSuccess(example.GetAsJSON(s))
+ sb_data = json.loads(s.GetData())
+ self.assertEqual(sb_data, example_arr)
+
def invalid_struct_test(self, example):
invalid_struct = lldb.SBStructuredData()
invalid_struct = example.GetValueForKey("invalid_key")