MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / applyTestOperation

Function applyTestOperation

source/core/StarJsonPatch.cpp:58–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56 }
57
58 Json applyTestOperation(Json const& base, Json const& op) {
59 String path = op.getString("path");
60 auto pointer = JsonPath::Pointer(path);
61 auto inverseTest = op.getBool("inverse", false);
62
63 try {
64 if (op.contains("search")) {
65 auto searchable = pointer.get(base);
66 auto searchValue = op.get("search");
67 bool found = findJsonMatch(searchable, searchValue, pointer);
68 if (found && inverseTest)
69 throw JsonPatchTestFail(strf("Test operation failure, expected {} to be missing.", searchValue), false);
70 else if (!found && !inverseTest)
71 throw JsonPatchTestFail(strf("Test operation failure, could not find {}.", searchValue), false);
72 return base;
73 } else {
74 auto value = op.opt("value");
75 auto testValue = pointer.get(base);
76 if (!value) {
77 if (inverseTest)
78 throw JsonPatchTestFail(strf("Test operation failure, expected {} to be missing.", path), false);
79 return base;
80 }
81
82 if ((value && (testValue == *value)) ^ inverseTest)
83 return base;
84 else
85 throw JsonPatchTestFail(strf("Test operation failure, expected {} found {}.", value, testValue), false);
86 }
87 } catch (JsonPath::TraversalException& e) {
88 if (inverseTest)
89 return base;
90 throw JsonPatchTestFail(strf("Test operation failure: {}", e.what()), false);
91 }
92 }
93
94 Json applyRemoveOperation(Json const& base, Json const& op) {
95 String path = op.getString("path");

Callers

nothing calls this directly

Calls 9

PointerClass · 0.85
findJsonMatchFunction · 0.85
strfFunction · 0.85
getStringMethod · 0.80
getBoolMethod · 0.80
containsMethod · 0.45
getMethod · 0.45
optMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected