diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2021-06-01 16:58:07 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-01 16:58:07 -0400 |
| commit | 7a3c87b58de2683c077bd5341052c2e3cebeb048 (patch) | |
| tree | 8641667ebcfecd728bfe8b572822751fae1c55bd /tools/slang-test/unit-test-json.cpp | |
| parent | 67486ee516ddc33806003727682cbfc68ab1f726 (diff) | |
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 <math.h> 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.
Diffstat (limited to 'tools/slang-test/unit-test-json.cpp')
| -rw-r--r-- | tools/slang-test/unit-test-json.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
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<JSONContainer> container = new JSONContainer(nullptr); + + { + List<JSONValue> 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); |
