Translate asset and material parity tests
Some checks failed
Rust API gates / api-gates (push) Has been cancelled
Some checks failed
Rust API gates / api-gates (push) Has been cancelled
This commit is contained in:
@@ -171,6 +171,10 @@ MEMBER_RETURN_OVERRIDES = {
|
||||
"M:LibreMetaverse.Caps.Capabilities": "Vec<String>",
|
||||
}
|
||||
MEMBER_SIGNATURE_OVERRIDES = {
|
||||
"M:LibreMetaverse.AssetManager.#ctor(LibreMetaverse.GridClient)": (
|
||||
"pub fn new(client: Option<libremetaverse::GridClient>) -> Result<Self, crate::Error>",
|
||||
"optional_owned",
|
||||
),
|
||||
"M:LibreMetaverse.Helpers.ZeroDecode(System.Byte[],System.Int32,System.Byte[])": (
|
||||
"pub fn zero_decode(src: Option<&[u8]>, srclen: i32, dest: Option<&mut [u8]>) "
|
||||
"-> Result<i32, crate::Error>",
|
||||
@@ -187,6 +191,18 @@ MEMBER_SIGNATURE_OVERRIDES = {
|
||||
"-> Result<(), crate::Error>",
|
||||
"mutable_self,owned,mutable_borrow,mutable_borrow,optional_mutable_borrow",
|
||||
),
|
||||
"M:LibreMetaverse.TerrainManager.GetTerrainMaterialOverridesAsync(System.Threading.CancellationToken)": (
|
||||
"pub async fn get_terrain_material_overrides(&self, cancellation_token: "
|
||||
"Option<libremetaverse_types::compat::CancellationToken>) "
|
||||
"-> Result<Option<Vec<Option<libremetaverse::assets::AssetMaterial>>>, crate::Error>",
|
||||
"shared_self,optional_owned",
|
||||
),
|
||||
"M:LibreMetaverse.TerrainManager.SetTerrainMaterialOverridesAsync(LibreMetaverse.Assets.AssetMaterial[],System.Threading.CancellationToken)": (
|
||||
"pub async fn set_terrain_material_overrides(&self, overrides: "
|
||||
"Vec<Option<libremetaverse::assets::AssetMaterial>>, cancellation_token: "
|
||||
"Option<libremetaverse_types::compat::CancellationToken>) -> Result<bool, crate::Error>",
|
||||
"shared_self,owned,optional_owned",
|
||||
),
|
||||
}
|
||||
TYPE_USAGE_OVERRIDES = {
|
||||
"LibreMetaverse.DictionaryChangeCallback": (
|
||||
@@ -580,6 +596,10 @@ def method_receiver(owner: dict, item: dict) -> tuple[str, str]:
|
||||
return "", "none"
|
||||
if item["name"] == "Deserialize":
|
||||
return "&mut self", "mutable_self"
|
||||
if owner["doc_id"] == "T:LibreMetaverse.Assets.AssetMaterial" and item["name"].startswith(
|
||||
("Apply", "Decode", "Encode", "Set")
|
||||
):
|
||||
return "&mut self", "mutable_self"
|
||||
if owner["doc_id"] == "T:LibreMetaverse.BitPack" and item["name"].startswith(("Pack", "Unpack")):
|
||||
return "&mut self", "mutable_self"
|
||||
if (
|
||||
|
||||
@@ -388,10 +388,14 @@ def extract_tests(upstream: Path) -> list[dict[str, object]]:
|
||||
return tests
|
||||
|
||||
|
||||
def review_paths(root: Path) -> list[Path]:
|
||||
review_roots = (root / "tests" / "compat" / "tests", root / "crates")
|
||||
return sorted(path for review_root in review_roots for path in review_root.rglob("*.rs"))
|
||||
|
||||
|
||||
def reviewed_tests(root: Path) -> dict[str, dict[str, object]]:
|
||||
reviews: dict[str, dict[str, object]] = {}
|
||||
tests_root = root / "tests" / "compat" / "tests"
|
||||
for path in sorted(tests_root.rglob("*.rs")):
|
||||
for path in review_paths(root):
|
||||
if path.name == "generated_parity.rs":
|
||||
continue
|
||||
text = path.read_text()
|
||||
@@ -532,7 +536,7 @@ def generate_tests(upstream: Path, output: Path, review_root: Path | None = None
|
||||
|
||||
def scan_parity_markers(root: Path) -> dict[str, list[dict[str, object]]]:
|
||||
markers: defaultdict[str, list[dict[str, object]]] = defaultdict(list)
|
||||
for path in sorted((root / "tests" / "compat" / "tests").rglob("*.rs")):
|
||||
for path in review_paths(root):
|
||||
text = path.read_text()
|
||||
for marker in PARITY_MARKER_RE.finditer(text):
|
||||
next_marker = PARITY_MARKER_RE.search(text, marker.end())
|
||||
|
||||
@@ -4,10 +4,33 @@ import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from generate_surface import check_test_parity, extract_tests, generate_tests, mask_csharp_comments
|
||||
from generate_surface import (
|
||||
check_test_parity,
|
||||
extract_tests,
|
||||
generate_tests,
|
||||
mask_csharp_comments,
|
||||
reviewed_tests,
|
||||
scan_parity_markers,
|
||||
)
|
||||
|
||||
|
||||
class ParityGenerationTests(unittest.TestCase):
|
||||
def test_reviewed_tests_include_owning_crate_unit_tests(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
root = Path(temporary)
|
||||
rust_file = root / "crates" / "example" / "src" / "internal_semantics.rs"
|
||||
rust_file.parent.mkdir(parents=True)
|
||||
case_id = "Example.Tests.cs::ExampleTests.InternalMember::test"
|
||||
rust_file.write_text(
|
||||
f"// parity-case: {case_id} {'a' * 64} translated\n"
|
||||
"#[test]\nfn internal_member() {}\n"
|
||||
)
|
||||
|
||||
review = reviewed_tests(root)[case_id]
|
||||
self.assertEqual(review["rust_file"], "crates/example/src/internal_semantics.rs")
|
||||
self.assertEqual(review["rust_test"], "internal_member")
|
||||
self.assertEqual(scan_parity_markers(root)[case_id][0], review)
|
||||
|
||||
def test_comment_masking_preserves_offsets_and_ignores_fake_tests(self) -> None:
|
||||
source = '''var url = "https://example.com/[Test]"; // [Test]\n/* [TestCase(1)] */\n[Test]\n'''
|
||||
masked = mask_csharp_comments(source)
|
||||
|
||||
Reference in New Issue
Block a user