Skip to content

Commit 191d5d2

Browse files
authored
Merge pull request #49 from koxudaxi/structural-sites
feat: add structural sites
2 parents 163ffd2 + 6f4416c commit 191d5d2

21 files changed

Lines changed: 669 additions & 101 deletions

File tree

json-tstring/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[project]
22
name = "json-tstring"
3-
version = "0.2.2"
3+
version = "0.3.0"
44
description = "JSON renderer for t-string structured data templates"
55
readme = "README.md"
66
license = { text = "MIT" }
77
authors = [{ name = "Koudai Aono", email = "koxudaxi@gmail.com" }]
88
maintainers = [{ name = "Koudai Aono", email = "koxudaxi@gmail.com" }]
99
requires-python = ">=3.14"
1010
dependencies = [
11-
"tstring-bindings>=0.2.2",
12-
"tstring-core>=0.2.2",
11+
"tstring-bindings>=0.3.0",
12+
"tstring-core>=0.3.0",
1313
]
1414
keywords = ["pep750", "t-strings", "json", "template-strings", "structured-data"]
1515
classifiers = [

pyproject.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[project]
22
name = "tstring-structured-data-workspace"
3-
version = "0.2.2"
3+
version = "0.3.0"
44
description = "Workspace for parser-first JSON, TOML, and YAML PEP 750 t-string backends"
55
readme = "README.md"
66
requires-python = ">=3.14"
77
dependencies = [
8-
"json-tstring>=0.2.2",
9-
"toml-tstring>=0.2.2",
10-
"tstring-core>=0.2.2",
11-
"yaml-tstring>=0.2.2",
8+
"json-tstring>=0.3.0",
9+
"toml-tstring>=0.3.0",
10+
"tstring-core>=0.3.0",
11+
"yaml-tstring>=0.3.0",
1212
]
1313

1414
[build-system]
@@ -18,14 +18,14 @@ build-backend = "uv_build"
1818
[dependency-groups]
1919
dev = [
2020
"inline-snapshot>=0.32.5",
21-
"json-tstring>=0.2.2",
21+
"json-tstring>=0.3.0",
2222
"maturin>=1.8.0",
2323
"pytest>=8.4.0",
2424
"ruff>=0.11.0",
25-
"toml-tstring>=0.2.2",
26-
"tstring-core>=0.2.2",
25+
"toml-tstring>=0.3.0",
26+
"tstring-core>=0.3.0",
2727
"ty>=0.0.23",
28-
"yaml-tstring>=0.2.2",
28+
"yaml-tstring>=0.3.0",
2929
]
3030
docs = [
3131
"zensical>=0.0.15",

rust/Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ homepage = "https://github.com/koxudaxi/tstring-structured-data"
1818
license = "MIT"
1919
repository = "https://github.com/koxudaxi/tstring-structured-data"
2020
rust-version = "1.94.0"
21-
version = "0.2.2"
21+
version = "0.3.0"
2222

2323
[workspace.dependencies]
2424
num-bigint = "0.4.6"

rust/backend-e2e-tests/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ rust-version.workspace = true
1010
publish = false
1111

1212
[dev-dependencies]
13-
tstring-json = { version = "0.2.2", path = "../json-tstring-rs" }
14-
tstring-syntax = { version = "0.2.2", path = "../tstring-core-rs" }
15-
tstring-toml = { version = "0.2.2", path = "../toml-tstring-rs" }
16-
tstring-yaml = { version = "0.2.2", path = "../yaml-tstring-rs" }
13+
tstring-json = { version = "0.3.0", path = "../json-tstring-rs" }
14+
tstring-syntax = { version = "0.3.0", path = "../tstring-core-rs" }
15+
tstring-toml = { version = "0.3.0", path = "../toml-tstring-rs" }
16+
tstring-yaml = { version = "0.3.0", path = "../yaml-tstring-rs" }

rust/backend-e2e-tests/tests/backend_api.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use tstring_json as backend_json;
22
use tstring_syntax::{
3-
InterpolationTypeRequirement, TemplateInput, TemplateInterpolation, TemplateSegment,
3+
DslType, InterpolationTypeRequirement, StructuralRole, StructuralSite, TemplateInput,
4+
TemplateInterpolation, TemplateSegment, TypeRequirement,
45
};
56
use tstring_toml as backend_toml;
67
use tstring_yaml as backend_yaml;
@@ -38,6 +39,39 @@ fn json_backend_public_api_smoke_test() {
3839
);
3940
}
4041

42+
#[test]
43+
fn json_backend_structural_site_public_api_smoke_test() {
44+
let template = TemplateInput::from_segments(vec![
45+
TemplateSegment::StaticText("{\"items\": [{\"id\": ".to_owned()),
46+
interpolation(0, "id", "{id}"),
47+
TemplateSegment::StaticText("}], \"name\": \"Ada\"}".to_owned()),
48+
]);
49+
50+
assert_eq!(
51+
backend_json::interpolation_type_requirements(&template)
52+
.expect("expected json type requirements"),
53+
vec![InterpolationTypeRequirement::with_site(
54+
0,
55+
"str | int | float | bool | None | dict[str, object] | list[object] | tuple[object, ...]",
56+
"json value",
57+
StructuralSite::new("/items/0/id", StructuralRole::Value)
58+
)]
59+
);
60+
assert_eq!(
61+
backend_json::requirement_for(
62+
&DslType::new("integer"),
63+
backend_json::JsonProfile::default()
64+
),
65+
TypeRequirement::new("int", Vec::new())
66+
);
67+
68+
let outline = backend_json::static_structure_outline(&template).expect("expected outline");
69+
assert_eq!(outline.objects[0].pointer.as_deref(), Some(""));
70+
assert_eq!(outline.objects[1].pointer.as_deref(), Some("/items/0"));
71+
assert_eq!(outline.objects[0].static_keys[0].name, "items");
72+
assert_eq!(outline.objects[0].static_keys[1].name, "name");
73+
}
74+
4175
#[test]
4276
fn toml_backend_public_api_smoke_test() {
4377
let template = TemplateInput::from_segments(vec![

rust/json-tstring-rs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test = false
1818

1919
[dependencies]
2020
serde_json = { workspace = true }
21-
tstring-syntax = { version = "0.2.2", path = "../tstring-core-rs" }
21+
tstring-syntax = { version = "0.3.0", path = "../tstring-core-rs" }
2222

2323
[dev-dependencies]
2424
toml = { workspace = true }

0 commit comments

Comments
 (0)