Skip to content

refactor rfc9535, moved one test to todo since it caused the panic (a… #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 66 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
d170340
refactor rfc9535, moved one test to todo since it caused the panic (a…
besok Jan 22, 2025
6d631d7
add the suite
besok Jan 23, 2025
6cbbcbb
add readme to rfc
besok Jan 23, 2025
dc9645e
fix some parts in parser for slices
besok Jan 26, 2025
cdbfb9a
add test-suite
besok Jan 26, 2025
f974973
remove ( ) for filter
besok Jan 26, 2025
ef9dfb8
fix ()
besok Jan 27, 2025
c8a1d50
fix some tests
besok Jan 27, 2025
4a1e211
add slices
besok Jan 28, 2025
410f32f
fix some tests
besok Jan 29, 2025
b08e887
obj in filter
besok Jan 31, 2025
7cc5886
add slice restr
besok Feb 1, 2025
e010846
fix slice
besok Feb 1, 2025
b058993
add q heck
besok Feb 1, 2025
3085d43
add neg for idx
besok Feb 2, 2025
9e48aa4
add fix for some detail
besok Feb 4, 2025
3a53d11
add parser
besok Feb 4, 2025
c2e9950
add parser
besok Feb 7, 2025
b4fe98c
add 9535 grammar pest file
besok Feb 8, 2025
8d4ed42
add grammar
besok Feb 8, 2025
c88463e
add model
besok Feb 8, 2025
c418285
add literal
besok Feb 9, 2025
fb99476
add test mod
besok Feb 9, 2025
7259ac6
add sing query
besok Feb 9, 2025
0eaa748
add slice
besok Feb 9, 2025
6432936
add part grammar
besok Feb 10, 2025
5da3a60
add part to parse
besok Feb 11, 2025
01e1153
add tests
besok Feb 12, 2025
ecce655
add tests
besok Feb 12, 2025
a9b721a
add + 1
besok Feb 15, 2025
5937d3a
add selectors
besok Feb 15, 2025
15f9eca
add fns
besok Feb 16, 2025
4ea5ba0
change sign
besok Feb 17, 2025
4b79c88
add eq
besok Feb 18, 2025
0e1386a
add eq neq
besok Feb 18, 2025
a1cd911
add test fn
besok Feb 19, 2025
5f04a9c
add processing
besok Feb 20, 2025
f5483a6
add
besok Feb 21, 2025
9d7d313
fix some tests
besok Feb 22, 2025
907defe
add fix
besok Feb 22, 2025
d5e85a5
add tests
besok Feb 23, 2025
da21670
add fix
besok Feb 24, 2025
fe5fd40
fix some tests
besok Mar 1, 2025
eb742b3
fix some tests
besok Mar 2, 2025
f5d5562
tests
besok Mar 3, 2025
2c7fdc2
fix tests
besok Mar 5, 2025
ce4cc90
add changes
besok Mar 8, 2025
671d4ff
add tests
besok Mar 9, 2025
891507e
add des
besok Mar 10, 2025
0c13086
add changes
besok Mar 11, 2025
01569a8
add custom extentions
besok Mar 11, 2025
3570b5a
rem prev mods
besok Mar 12, 2025
989904b
add docs
besok Mar 13, 2025
858f521
fix mut
besok Mar 13, 2025
a0981d7
fix some tests
besok Mar 13, 2025
cec3f64
fix some tests
besok Mar 15, 2025
1a104f8
change rem opt
besok Mar 15, 2025
eb6c1cd
upd doc test
besok Mar 15, 2025
9ed123b
rem cow
besok Mar 15, 2025
4608c36
add privacy for pointer
besok Mar 15, 2025
b1e7b2f
add changes
besok Mar 16, 2025
92c61b0
fix one test
besok Mar 16, 2025
7aacb8c
add tests
besok Mar 17, 2025
13fd060
add upd for tests
besok Mar 17, 2025
88959ae
add 2 tests to filter
besok Mar 17, 2025
c96c924
add changes for tests and reformat
besok Mar 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/target
**/target
.idea
Cargo.lock
.DS_Store
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "rfc9535/test_suite/jsonpath-compliance-test-suite"]
path = rfc9535/test_suite/jsonpath-compliance-test-suite
url = https://github.com/jsonpath-standard/jsonpath-compliance-test-suite.git
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@
- **`0.7.3`**
- make some methods public
- **`0.7.5`**
- add reference and reference_mut methods
- add reference and reference_mut methods
- **`1.0.1`**
- introduced breaking changes to the API to make it compliant with the RFC9535

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "jsonpath-rust"
description = "The library provides the basic functionality to find the set of the data according to the filtering query."
version = "0.7.5"
version = "1.0.0"
authors = ["BorisZhguchev <[email protected]>"]
edition = "2021"
license = "MIT"
Expand All @@ -14,14 +14,14 @@ categories = ["development-tools", "parsing", "text-processing"]
[dependencies]
serde_json = "1.0"
regex = "1"
pest = "2.0"
pest_derive = "2.0"
pest = "2.7.15"
pest_derive = "2.7.15"
thiserror = "2.0.9"

[dev-dependencies]
serde = { version = "1.0", features = ["derive"] }
criterion = "0.5.1"
colored = "2"


[[bench]]
name = "regex"
Expand Down
367 changes: 137 additions & 230 deletions README.md

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions benches/equal.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
use criterion::{criterion_group, criterion_main, Criterion};
use jsonpath_rust::{JsonPath, JsonPathQuery};
use serde_json::json;
use std::str::FromStr;

use jsonpath_rust::parser::model::JpQuery;
use jsonpath_rust::parser::parse_json_path;
use jsonpath_rust::query::state::State;
use jsonpath_rust::query::Query;
use jsonpath_rust::JsonPath;
use serde_json::{json, Value};

struct SearchData {
json: serde_json::Value,
path: JsonPath,
json: Value,
path: JpQuery,
}

const PATH: &str = "$.[?(@.author == 'abcd(Rees)')]";
const PATH: &str = "$[?@.author == 'abcd(Rees)']";

fn equal_perf_test_with_reuse(cfg: &SearchData) {
let _v = cfg.path.find(&cfg.json);
let _v = cfg.path.process(State::root(&cfg.json)).data;
}

fn equal_perf_test_without_reuse() {
let json = Box::new(json!({
"author":"abcd(Rees)",
}));

let _v = json.path(PATH).expect("the path is correct");
let _v = json.query(PATH).expect("the path is correct");
}

pub fn criterion_benchmark(c: &mut Criterion) {
let data = SearchData {
json: json!({
"author":"abcd(Rees)",
}),
path: JsonPath::from_str(PATH).unwrap(),
path: parse_json_path(PATH).unwrap(),
};
c.bench_function("equal bench with reuse", |b| {
b.iter(|| equal_perf_test_with_reuse(&data))
Expand Down
21 changes: 12 additions & 9 deletions benches/regex.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
use criterion::{criterion_group, criterion_main, Criterion};
use jsonpath_rust::{JsonPath, JsonPathQuery};
use jsonpath_rust::parser::model::JpQuery;
use jsonpath_rust::parser::parse_json_path;
use jsonpath_rust::query::state::State;
use jsonpath_rust::query::Query;
use jsonpath_rust::JsonPath;
use serde_json::{json, Value};
use std::str::FromStr;

struct SearchData {
json: serde_json::Value,
path: JsonPath,
json: Value,
path: JpQuery,
}

const PATH: &str = "$.[?(@.author ~= '.*(?i)d\\(Rees\\)')]";
const PATH: &str = "$[?search(@.author,'.*(?i)d\\\\(Rees\\\\)')]";

fn regex_perf_test_with_reuse(cfg: &SearchData) {
let _v = cfg.path.find(&cfg.json);
let _v = cfg.path.process(State::root(&cfg.json)).data;
}

fn regex_perf_test_without_reuse() {
let json = Box::new(json!({
"author":"abcd(Rees)",
}));

let _v = json.path(PATH).expect("the path is correct");
let _v = json.query(PATH).expect("the path is correct");
}

fn json_path_compiling() {
let _v = JsonPath::<Value>::from_str(PATH).unwrap();
let _v = parse_json_path(PATH).unwrap();
}

pub fn criterion_benchmark(c: &mut Criterion) {
let data = SearchData {
json: json!({
"author":"abcd(Rees)",
}),
path: JsonPath::from_str(PATH).unwrap(),
path: parse_json_path(PATH).unwrap(),
};
c.bench_function("regex bench with reuse", |b| {
b.iter(|| regex_perf_test_with_reuse(&data))
Expand Down
12 changes: 0 additions & 12 deletions examples/hello-world.rs

This file was deleted.

15 changes: 15 additions & 0 deletions rfc9535/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "jsonpath-rust-rfc9535"
description = "The tests to check the compliance with RFC 9535"
version = "0.0.1"
edition = "2021"
license = "MIT"
readme = "README.md"


[dependencies]
jsonpath-rust = { path = "../" }
serde_json = "1.0"
serde = { version = "1.0.217", features = ["derive"] }
colored = "2.0"
chrono = "0.4.39"
31 changes: 31 additions & 0 deletions rfc9535/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Tests for RFC9535

This directory contains tests for the [RFC9535](https://www.rfc-editor.org/info/rfc9535) implementation.
The tests can be downloaded using `prepare.sh` script.

## Usage
Run the main.rs.
It will print the test results in the console with the following format:
```
...
Skipping test case: `<name>` because of reason: `reason`
...
Failed tests:

------- <name> -------
<reason>

...

RFC9535 Compliance tests:
Total: 671
Passed: 209
Failed: 462
Skipped: 25 where 18 to fix in 5 issues

```

The results will be saved in the `results.csv` file.

The cases can be filtered using `filtered_cases.json` file.
The file should contain json array with the test case names that should be filtered out and the reason.
79 changes: 79 additions & 0 deletions rfc9535/src/console.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use crate::suite::TestFailure;
use chrono::Local;
use colored::Colorize;
use std::fs::{File, OpenOptions};
use std::io::Write;
use std::io::{BufRead, BufReader, Error};
pub fn process_results(
results: Vec<TestResult>,
skipped_cases: usize,
skipped_to_fix: usize,
issues: usize,
) -> Result<(), Error> {
let (passed, failed): (Vec<_>, Vec<_>) = results.into_iter().partition(TestResult::is_ok);
let total = passed.len() + failed.len() + skipped_cases;
let passed_count = passed.len();
let failed_count = failed.len();
let date = Local::now().format("%Y-%m-%d %H:%M:%S").to_string();

if failed_count > 0 {
println!("\n{}:", "Failed tests".bold());
println!("\n");
}
for failure in failed.iter() {
if let Err(TestFailure(case, reason)) = failure {
println!(" ------- {} -------", case.name.bold());
println!("{}", reason.bold().red());
}
}

let mut file = OpenOptions::new()
.create(true)
.append(true)
.open("test_suite/results.csv")?;
writeln!(
file,
"{}; {}; {}; {}",
total, passed_count, failed_count, date
)?;

clean_file(10)?;

println!(
"\n{}:\n{}\n{}\n{}\n{}",
format!("RFC9535 Compliance tests").underline().bold(),
format!("Total: {}", total).bold(),
format!("Passed: {}", passed_count).green().bold(),
format!("Failed: {}", failed_count).red().bold(),
format!(
"Skipped: {} where {} to fix in {} issues",
skipped_cases, skipped_to_fix, issues
)
.bold()
);
Ok(())
}

fn clean_file(limit: usize) -> Result<(), Error> {
let file_path = "test_suite/results.csv";
let file = File::open(file_path)?;
let reader = BufReader::new(file);
let lines: Vec<String> = reader.lines().collect::<Result<_, _>>()?;

if lines.len() > limit {
let header = &lines[0];
let trimmed_lines = [&[header.clone()], &lines[lines.len() - limit..]].concat();

let mut file = OpenOptions::new()
.write(true)
.truncate(true)
.open(file_path)?;
for line in trimmed_lines {
writeln!(file, "{}", line)?;
}
}

Ok(())
}

pub type TestResult<'a> = Result<(), TestFailure<'a>>;
23 changes: 23 additions & 0 deletions rfc9535/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

mod console;
mod suite;
use crate::suite::get_suite;
use colored::Colorize;
use console::TestResult;
use std::io::Error;
use std::io::Write;
use std::str::FromStr;

fn main() -> Result<(), Error> {
let (cases, skipped, skipped_to_fix, issues) = get_suite()?;
console::process_results(
cases
.iter()
.map(suite::handle_test_case)
.collect::<Vec<TestResult>>(),
skipped,
skipped_to_fix,
issues,
)
}

Loading
Loading