MCPcopy Create free account
hub / github.com/Snapchat/Valdi / deserializeTestCases

Function deserializeTestCases

tsn/src/test262/shared/Test262Serialization.cpp:58–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58Result<map<string, TestCaseData>> deserializeTestCases(const fs::path& inputFile) {
59 auto testCasesResult = DiskUtils::load(Path(inputFile.string()));
60 if (!testCasesResult) {
61 return TEST262_ERROR("Failed to save file {} with error {}", inputFile, testCasesResult.error().getMessage());
62 }
63 const auto testCasesData = testCasesResult.moveValue();
64 auto testCasesValueResult = jsonToValue(testCasesData.data(), testCasesResult.value().size());
65 if (!testCasesValueResult) {
66 return TEST262_ERROR(
67 "Failed to parse file {} with error {}", inputFile, testCasesValueResult.error().getMessage());
68 }
69 const auto testCasesValue = testCasesValueResult.moveValue();
70 if (!testCasesValue.isMap()) {
71 return TEST262_ERROR("Parsed file {} expected top level map", inputFile);
72 }
73
74 map<string, TestCaseData> retval;
75 for (const auto& testCase : *testCasesValue.getMapRef()) {
76 TestCaseData data;
77 if (!testCase.second.isMap()) {
78 return TEST262_ERROR("Test case data for {} is not a map", testCase.first);
79 }
80
81 const auto isNegativeValue = testCase.second.getMapValue(kIsNegative);
82 const auto negativePhaseValue = testCase.second.getMapValue(kNegativePhase);
83 const auto negativeTypeValue = testCase.second.getMapValue(kNegativeType);
84 const auto onlyStrictValue = testCase.second.getMapValue(kOnlyStrict);
85 const auto noStrictValue = testCase.second.getMapValue(kNoStrict);
86 const auto moduleValue = testCase.second.getMapValue(kModule);
87 const auto rawValue = testCase.second.getMapValue(kRaw);
88 const auto asyncValue = testCase.second.getMapValue(kAsync);
89 const auto includesValue = testCase.second.getMapValue(kIncludes);
90
91 bool boolValueCheck = isNegativeValue.isBool() && onlyStrictValue.isBool() && noStrictValue.isBool() &&
92 moduleValue.isBool() && rawValue.isBool() && asyncValue.isBool();
93 if (!boolValueCheck) {
94 return TEST262_ERROR("Test case data for {} expected bool type", testCase.first);
95 }
96 bool stringValueCheck = negativePhaseValue.isString() && negativeTypeValue.isString();
97 if (!stringValueCheck) {
98 return TEST262_ERROR("Test case data for {} expected string type", testCase.first);
99 }
100 bool arrayValueCheck = includesValue.isArray();
101 if (!arrayValueCheck) {
102 return TEST262_ERROR("Test case data for {} expected array type", testCase.first);
103 }
104
105 data.isNegative = isNegativeValue.toBool();
106 data.onlyStrict = onlyStrictValue.toBool();
107 data.noStrict = noStrictValue.toBool();
108 data.module = moduleValue.toBool();
109 data.async = asyncValue.toBool();
110
111 data.negativePhase = negativePhaseValue.toString();
112 data.negativeType = negativeTypeValue.toString();
113
114 data.includes.reserve(includesValue.getArrayRef()->size());
115 for (const auto& element : *includesValue.getArrayRef()) {

Callers 1

runTestCasesFunction · 0.85

Calls 15

loadFunction · 0.85
getMapRefMethod · 0.80
getMapValueMethod · 0.80
isBoolMethod · 0.80
getArrayRefMethod · 0.80
slowToStringMethod · 0.80
getMessageMethod · 0.65
errorMethod · 0.65
valueMethod · 0.65
toStringMethod · 0.65
PathClass · 0.50
jsonToValueFunction · 0.50

Tested by

no test coverage detected