Skip to content

Commit

Permalink
feat: serde support for JsonPathQuery and MainEngine
Browse files Browse the repository at this point in the history
Implemented `serde::Serialize` and `serde::Deserialize`
for `MainEngine` in rsonpath-lib, and `JsonPathQuery`
in rsonpath-syntax with all of its constituent substructs.
The `serde` dependency is guarded behind an optional feature.

To properly proptest this feature `rsonpath-lib` needs access
to the arbitrary query generation from `rsonpath-syntax`.
The cleanest way to do this is to extract the logic to a separate
crate, giving rise to `rsonpath-syntax-proptest`.

The serialization format is not stable, as the `Automaton`
is expected to evolve. Thus, serialization includes a version
and deserialization will fail if the version disagrees.

Also added snapshot tests based on `insta` to both the rsonpath-syntax
and rsonpath-lib serialization features.
  • Loading branch information
V0ldek authored Dec 31, 2024
1 parent 1f2ebbe commit 4b81feb
Show file tree
Hide file tree
Showing 43 changed files with 1,925 additions and 561 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

[alias]
rsontest = "hack test -q --feature-powerset --skip default --features arbitrary --ignore-unknown-features"
rsontest = "hack test -q --feature-powerset --skip default -F arbitrary -F serde --ignore-unknown-features"

[env]
RUST_BACKTRACE = "1"
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:
env:
CARGO_TARGET_DIR: target/
- name: Build all feature sets
run: cargo hack build --workspace --feature-powerset --skip default --target ${{ matrix.target_triple }} --features arbitrary --ignore-unknown-features
run: cargo hack build --workspace --feature-powerset --skip default --target ${{ matrix.target_triple }} -F arbitrary -F serde --ignore-unknown-features
env:
RUSTFLAGS: ${{ matrix.rustflags }}
- name: Download rsonpath-test artifact
Expand All @@ -154,7 +154,7 @@ jobs:
name: ${{ needs.test-gen.outputs.artifact-name }}
path: ${{ needs.test-gen.outputs.artifact-path }}
- name: Test all feature sets
run: cargo hack test --workspace --feature-powerset --skip default --target ${{ matrix.target_triple }} --features arbitrary --ignore-unknown-features
run: cargo hack test --workspace --feature-powerset --skip default --target ${{ matrix.target_triple }} -F arbitrary -F serde --ignore-unknown-features
env:
RUSTFLAGS: ${{ matrix.rustflags }}

Expand Down
137 changes: 127 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"crates/rsonpath",
"crates/rsonpath-lib",
"crates/rsonpath-syntax",
"crates/rsonpath-syntax-proptest",
"crates/rsonpath-test",
]

Expand All @@ -24,15 +25,24 @@ edition = "2021"
# Project crates
rsonpath-lib = { version = "0.9.3", path = "./crates/rsonpath-lib", package = "rsonpath-lib", default-features = false }
rsonpath-syntax = { version = "0.3.2", path = "./crates/rsonpath-syntax" }
rsonpath-syntax-proptest = { version = "0.3.2", path = "./crates/rsonpath-syntax-proptest" }
# Main dependencies
arbitrary = { version = "1.4.1" }
cfg-if = "1.0.0"
log = "0.4.22"
thiserror = "2.0.9"
# Dev-dependencies
ciborium = { version = "0.2.2", default-features = false }
insta = { version = "1.41.1" }
itertools = "0.13.0"
pretty_assertions = "1.4.1"
proptest = "1.5.0"
rmp-serde = "1.3.0"
serde = { version = "1.0.217" }
serde_json = { version = "1.0.133", default-features = true, features = [
"std",
"float_roundtrip",
] }
test-case = "3.3.1"

[workspace.lints.rust]
Expand Down
6 changes: 4 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ assert-benchmarks-committed:

# === RELEASE ===

# Execute prerequisits for a release for the given version.
# Execute prerequisites for a release for the given version.
release ver:
cargo update
just release-patch {{ver}}
Expand All @@ -276,7 +276,7 @@ release ver:
cargo build
cargo +nightly fuzz build

# Execute prerequisits for a release of `rsonpath-syntax` for the given version.
# Execute prerequisites for a release of `rsonpath-syntax` for the given version.
release-syntax ver:
#!/usr/bin/env nu
let ver = "{{ver}}";
Expand All @@ -297,10 +297,12 @@ release-readme:
#!/usr/bin/env nu
let rsonpath_deps = (cargo tree --package rsonpath --edges normal --edges build --depth 1 --target=all --all-features);
let rsonpath_lib_deps = (cargo tree --package rsonpath-lib --edges normal --edges build --depth 1 --target=all --all-features);
let rsonpath_syntax_deps = (cargo tree --package rsonpath-syntax --edges normal --edges build --depth 1 --target=all --all-features);
let rsonpath_full_deps = (cargo tree --package rsonpath --edges normal --edges build --target=all --all-features);
let params = [
[$rsonpath_deps, "rsonpath", "./README.md"],
[$rsonpath_lib_deps, "rsonpath-lib", "./README.md"],
[$rsonpath_syntax_deps, "rsonpath-syntax", "./crates/rsonpath-syntax/README.md"],
[$rsonpath_lib_deps, "rsonpath-lib", "./crates/rsonpath-lib/README.md"],
[$rsonpath_full_deps, "rsonpath-full", "./README.md"]
];
Expand Down
1 change: 1 addition & 0 deletions crates/rsonpath-benchmarks/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ where
S: Into<std::borrow::Cow<'static, str>>,
{
use indicatif::{ProgressBar, ProgressStyle};
#[allow(clippy::literal_string_with_formatting_args)]
let style = ProgressStyle::with_template(
"{msg} {spinner} {wide_bar:.green/white} {bytes:>12}/{total_bytes:>12} ({bytes_per_sec:>12}) {eta:>10}",
)
Expand Down
Loading

0 comments on commit 4b81feb

Please sign in to comment.