1#ifndef SOURCEMETA_BLAZE_TEST_H_
2#define SOURCEMETA_BLAZE_TEST_H_
4#ifndef SOURCEMETA_BLAZE_TEST_EXPORT
5#include <sourcemeta/blaze/test_export.h>
8#include <sourcemeta/blaze/test_error.h>
10#include <sourcemeta/blaze/compiler.h>
11#include <sourcemeta/blaze/evaluator.h>
12#include <sourcemeta/blaze/output.h>
14#include <sourcemeta/core/json.h>
15#include <sourcemeta/core/jsonpointer.h>
16#include <sourcemeta/core/jsonschema.h>
35namespace sourcemeta::blaze {
47#pragma warning(disable : 4251)
54 sourcemeta::core::JSON
data;
56 std::optional<sourcemeta::core::JSON>
rdf;
58 sourcemeta::core::PointerPositionTracker
tracker;
60 sourcemeta::core::PointerPositionTracker::Position
position;
62#pragma warning(default : 4251)
67 parse(
const sourcemeta::core::JSON &test_case_json,
68 const sourcemeta::core::PointerPositionTracker &
tracker,
69 const std::filesystem::path &base_path,
70 const sourcemeta::core::Pointer &location,
71 const sourcemeta::core::PointerPositionTracker::Position &
position)
81#pragma warning(disable : 4251)
88 std::optional<sourcemeta::core::JSON>
rdf;
92#pragma warning(default : 4251)
106#pragma warning(disable : 4251)
114 const sourcemeta::core::SchemaFrame &
frame;
121#pragma warning(default : 4251)
130 std::function<
TestTarget(
const sourcemeta::core::JSON::String &target)>;
157#pragma warning(disable : 4251)
161 std::vector<sourcemeta::core::JSON::String>
targets;
165#pragma warning(default : 4251)
173 const sourcemeta::core::JSON::String &target, std::size_t target_index,
174 std::size_t index, std::size_t total,
const TestCase &test_case,
178 [[nodiscard]]
auto fast(std::size_t target_index)
const ->
const Template &;
321 static auto parse(
const sourcemeta::core::JSON &document,
322 const sourcemeta::core::PointerPositionTracker &tracker,
323 const std::filesystem::path &base_path,
325 const sourcemeta::core::SchemaResolver &schema_resolver,
326 const sourcemeta::core::SchemaWalker &walker,
328 const std::optional<Tweaks> &tweaks = std::nullopt)
335#pragma warning(disable : 4251)
339 struct ResolvedTarget {
340 const sourcemeta::core::JSON *document;
341 const sourcemeta::core::SchemaFrame *frame;
342 sourcemeta::core::JSON::String entrypoint;
345 [[nodiscard]]
auto compile_target(std::size_t target_index,
Mode mode)
const
348 std::vector<ResolvedTarget> resolved_targets_;
349 std::vector<Template> schemas_fast_;
350 std::vector<std::optional<Template>> schemas_exhaustive_;
351 sourcemeta::core::SchemaResolver schema_resolver_;
352 sourcemeta::core::SchemaWalker walker_;
354 std::optional<Tweaks> tweaks_fast_;
355 std::optional<Tweaks> tweaks_exhaustive_;
357#pragma warning(default : 4251)
std::function< Instructions(const KeywordContext &, const Instructions &)> Compiler
Definition compiler.h:105
Mode
Definition compiler.h:111
bool valid
The actual validity outcome of the test data against the target.
Definition test.h:86
const sourcemeta::core::JSON & document
Definition test.h:110
std::vector< TestCase > tests
The list of test cases in the suite.
Definition test.h:163
std::optional< sourcemeta::core::JSON > rdf
The actual expansion, when RDF promotion ran and succeeded.
Definition test.h:88
static auto parse(const sourcemeta::core::JSON &document, const sourcemeta::core::PointerPositionTracker &tracker, const std::filesystem::path &base_path, const TestTargetResolver &target_resolver, const sourcemeta::core::SchemaResolver &schema_resolver, const sourcemeta::core::SchemaWalker &walker, const Compiler &compiler, const std::optional< Tweaks > &tweaks=std::nullopt) -> TestSuite
sourcemeta::core::PointerPositionTracker::Position position
The position of this test case in the test suite file.
Definition test.h:60
sourcemeta::core::JSON::String entrypoint
Definition test.h:119
auto run(const Callback &callback) -> Result
auto exhaustive(std::size_t target_index) -> const Template &
std::function< void( const sourcemeta::core::JSON::String &target, std::size_t target_index, std::size_t index, std::size_t total, const TestCase &test_case, const TestOutcome &outcome, TestTimestamp start, TestTimestamp end)> Callback
A callback invoked for each test case during execution.
Definition test.h:172
std::optional< sourcemeta::core::JSON > rdf
The expected promotion of the test data to expanded-form JSON-LD.
Definition test.h:56
std::vector< sourcemeta::core::JSON::String > targets
Definition test.h:161
sourcemeta::core::JSON data
The test data to validate.
Definition test.h:54
std::optional< JSONLDResolutionError > rdf_error
The resolution error, when RDF promotion failed.
Definition test.h:90
auto fast(std::size_t target_index) const -> const Template &
The compiled schema template for fast validation of the given target.
const sourcemeta::core::SchemaFrame & frame
Definition test.h:114
static auto parse(const sourcemeta::core::JSON &test_case_json, const sourcemeta::core::PointerPositionTracker &tracker, const std::filesystem::path &base_path, const sourcemeta::core::Pointer &location, const sourcemeta::core::PointerPositionTracker::Position &position) -> TestCase
Parse a single test case.
sourcemeta::core::JSON::String description
The optional description of the test case.
Definition test.h:50
Evaluator evaluator
The evaluator instance used for validation.
Definition test.h:168
sourcemeta::core::PointerPositionTracker tracker
The position tracker for error reporting on the data.
Definition test.h:58
bool passed
Whether the test case passed overall.
Definition test.h:84
bool valid
Whether the test data is expected to be valid against the schema.
Definition test.h:52
std::chrono::steady_clock::time_point TestTimestamp
Definition test.h:39
std::function< TestTarget(const sourcemeta::core::JSON::String &target)> TestTargetResolver
Definition test.h:129