From 7a3c87b58de2683c077bd5341052c2e3cebeb048 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 1 Jun 2021 16:58:07 -0400 Subject: JSONValue / Container (#1864) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP JSONWriter/JSONParser. * Checking different Layout styles for JSON. * Add slang-json-parser.h/.cpp * WIP JSONValue. * Added JSONValue::destroy/Recursive. * Improvement to JSONValue. * Improve text double conversion precision. Testing. * Simplify double parsing (just use atof). JSON comparison More testing of conversions and start of JSONValue. * Add for isnan, isinf etc. * Small improvement with object comparison. * Fix typo in getArgsByName. * Removed use of isnan and isinf as includes don't work on linux. * Improve JSON unit test. * Added asInteger/asFloat/asBool to JSONValue. * Change comment to trigger CI build. --- tools/slang-test/unit-test-json.cpp | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'tools/slang-test/unit-test-json.cpp') diff --git a/tools/slang-test/unit-test-json.cpp b/tools/slang-test/unit-test-json.cpp index 5a59cdcc3..bcd5bf1f0 100644 --- a/tools/slang-test/unit-test-json.cpp +++ b/tools/slang-test/unit-test-json.cpp @@ -2,6 +2,7 @@ #include "../../source/compiler-core/slang-json-lexer.h" #include "../../source/core/slang-string-escape-util.h" #include "../../source/compiler-core/slang-json-parser.h" +#include "../../source/compiler-core/slang-json-value.h" #include "test-context.h" @@ -221,6 +222,50 @@ static void jsonUnitTest() } } + + + { + JSONValue value; + + value = JSONValue::makeBool(true); + + // Only need a SourceManager if we are going to store lexemes + RefPtr container = new JSONContainer(nullptr); + + { + List values; + + for (Int i = 0; i < 100; ++i) + { + + values.add(JSONValue::makeInt(i)); + values.add(JSONValue::makeFloat(-double(i))); + } + + JSONValue array = container->createArray(values.getBuffer(), values.getCount()); + + auto arrayView = container->getArray(array); + + SLANG_CHECK(arrayView.getCount() == values.getCount()); + + // Check the values are the same + SLANG_CHECK(container->areEqual(arrayView.getBuffer(), values.getBuffer(), arrayView.getCount())); + } + { + JSONValue obj = JSONValue::makeEmptyObject(); + + JSONKey key = container->getKey(UnownedStringSlice::fromLiteral("Hello")); + + container->setKeyValue(obj, key, JSONValue::makeNull()); + container->setKeyValue(obj, key, JSONValue::makeInt(10)); + + auto objView = container->getObject(obj); + + SLANG_CHECK(objView.getCount() == 1); + + SLANG_CHECK(objView[0].value.asInteger() == 10); + } + } } SLANG_UNIT_TEST("JSON", jsonUnitTest); -- cgit v1.2.3