Skip to content

Commit

Permalink
feat: include # prefix of index path
Browse files Browse the repository at this point in the history
  • Loading branch information
SARDONYX-sard committed Dec 15, 2024
1 parent e4f5648 commit aecefda
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
17 changes: 7 additions & 10 deletions core/nemesis_xml/src/helpers/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde_hkx::xml::de::parser::{delimited_with_multispace0, tag::attr_string};
use std::str::FromStr;
use winnow::{
ascii::digit1,
combinator::{alt, delimited, preceded, seq},
combinator::{alt, delimited, seq},
error::{
ContextError, StrContext,
StrContextValue::{self},
Expand Down Expand Up @@ -162,13 +162,10 @@ fn index_name_attr<'a>(input: &mut &'a str) -> PResult<PointerType<'a>> {
/// # Errors
/// If parsing failed.
pub fn index_name<'a>(input: &mut &'a str) -> PResult<PointerType<'a>> {
preceded(
"#",
alt((
digit1.map(PointerType::Index),
take_until(0.., '\"').map(PointerType::Var),
)),
)
alt((
("#", digit1).take().map(PointerType::Index),
take_until(0.., '\"').map(PointerType::Var),
))
.parse_next(input)
}

Expand All @@ -180,10 +177,10 @@ mod tests {
fn test_index() {
assert_eq!(
index_name_attr.parse("\"#0002\""),
Ok(PointerType::Index("0002"))
Ok(PointerType::Index("#0002"))
);
assert_eq!(
index_name_attr.parse("\"#$id$2\""),
index_name_attr.parse("\"$id$2\""),
Ok(PointerType::Var("$id$2"))
);
}
Expand Down
13 changes: 6 additions & 7 deletions core/nemesis_xml/src/patch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,8 @@ impl<'de> PatchDeserializer<'de> {

#[cfg(test)]
mod tests {
use simd_json::json_typed;

use super::*;
use simd_json::json_typed;

#[test]
fn replace_field() {
Expand All @@ -566,7 +565,7 @@ mod tests {
actual,
vec![JsonPatch {
op: Op::Replace,
path: vec!["0010", "hkbProjectData", "stringData"]
path: vec!["#0010", "hkbProjectData", "stringData"]
.into_iter()
.map(|s| s.into())
.collect(),
Expand Down Expand Up @@ -607,7 +606,7 @@ mod tests {
op: Op::Add,
// path: https://crates.io/crates/jsonpath-rust
path: vec![
"0009",
"#0009",
"hkbProjectStringData",
"characterFilenames",
"[1:7]"
Expand Down Expand Up @@ -664,7 +663,7 @@ mod tests {
vec![JsonPatch {
op: Op::Remove,
path: vec![
"0009",
"#0009",
"hkbProjectStringData",
"characterFilenames",
"[5:7]"
Expand Down Expand Up @@ -701,7 +700,7 @@ mod tests {
op: Op::Replace,
// path: https://crates.io/crates/jsonpath-rust
path: [
"0008",
"#0008",
"hkRootLevelContainer",
"namedVariants",
"[0]",
Expand All @@ -717,7 +716,7 @@ mod tests {
}

#[cfg_attr(feature = "tracing", quick_tracing::init)]
#[ignore = "dummy"]
#[ignore = "because we need external test files"]
#[test]
fn parse() {
use std::fs::read_to_string;
Expand Down

0 comments on commit aecefda

Please sign in to comment.