Names: a pattern copy's piece names match as the original's do (#6270)

* Test: a pattern copy's piece names match as the original's do

A copy's faces carry the instance after the name, after any piece qualifier
(`top#[left,slot:a]@F9.1`). A stored piece name of a copy whose bounding faces have changed since
finds no face of the copy at all (None at the first assertion), where the original's identical
name matches by its stem. On a real part: the joint ends on a patterned copy fall back to their
picks after a size change, the original's resolve by name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PsiqyXWBFGTCX9J51bhysc

* Names: a pattern copy's piece names match as the original's do

Problem: a pattern's copy names its faces after the original's with the instance appended
after any piece qualifier (`top#[left,slot:a]@F9.1`). The piece parser expects a qualified name
to end with its qualifier, so a copy's name was its own stem: when the faces around a piece
changed, a stored name of a copy matched no face of the copy at all, where the original's
identical name still matched by its stem. Joint ends on a patterned part fell back to their picks
after a size change and flipped to the other end of their holes.

Solution: `history_names::matches` takes the pattern instances off the end of both names first
and compares the rest as before, within the same copy only (equal instances; an original's name
never matches a copy's face, nor one copy's another's).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PsiqyXWBFGTCX9J51bhysc

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NOWN-DEVandClaude Opus 5.5 authored and GitHub committed 2026-10-25 01:55:47 +00:00
1 parent f54ad0f12f
commit e260437846
2 files changed
+47

No files matched your search

+21
View File
@@ -428,6 +428,12 @@ pub(crate) fn matches(names: &Names, index: usize, name: &str) -> Option<Match>
if info.is_some_and(|i| i.aliases.iter().any(|a| a == name)) {
return Some(Match::Alias);
}
// A pattern copy's faces carry their instance after the name (`…@F9.1`, after any
// qualifier): the names compare as the original's do, within the same copy only.
let ((name, at), (current, here)) = (instance_suffix(name), instance_suffix(current));
if at != here {
return None;
}
// The named face (or piece) was split further: this is one of its pieces.
if descends(current, name) {
return Some(Match::Piece);
@@ -443,6 +449,21 @@ pub(crate) fn matches(names: &Names, index: usize, name: &str) -> Option<Match>
(crate::naming::strip_piece(current) == root).then_some(Match::Stem)
}
/// A name and the pattern instances after it (`F3:top#[F4:side]@F9.1` is `F3:top#[F4:side]` and
/// `@F9.1`; a copy of a copy carries one instance after another).
fn instance_suffix(n: &str) -> (&str, &str) {
let mut core = n;
while let Some(at) = core.rfind('@') {
let instance = core.get(at + 1..).and_then(|t| t.strip_prefix('F')).and_then(|t| t.split_once('.'));
let digits = |t: &str| !t.is_empty() && t.bytes().all(|b| b.is_ascii_digit());
if !instance.is_some_and(|(feature, k)| digits(feature) && digits(k)) {
break;
}
core = core.get(..at).unwrap_or_default();
}
(core, n.get(core.len()..).unwrap_or_default())
}
#[cfg(test)]
#[path = "history_names_tests.rs"]
mod tests;
+26
View File
@@ -44,6 +44,32 @@ fn pieces_are_told_apart_by_the_faces_only_they_touch() {
assert_eq!(matches(&names, 2, "top"), None);
}
/// A pattern's copy names its faces after the original's with the instance after them
/// (`…@F9.1`, after any qualifier): a stored piece name of a copy finds its piece as the
/// original's does, in that copy only.
#[test]
fn a_pattern_copys_piece_names_match_as_the_originals_do() {
let faces = named(&["top#[left,slot:a]@F9.1", "top#[right,slot:b]@F9.1", "front@F9.1", "top#[left,slot:a]@F9.2", "top#[left,slot:a]"]);
let names = qualify(faces, &[]);
// The faces around the piece have changed since the name was stored (other slot walls).
let stored = "top#[left,slot:c]@F9.1";
assert_eq!(matches(&names, 0, stored), Some(Match::Stem));
assert_eq!(matches(&names, 1, stored), Some(Match::Stem));
assert_eq!(matches(&names, 2, stored), None);
assert_eq!(matches(&names, 3, stored), None, "another copy");
assert_eq!(matches(&names, 4, stored), None, "the original");
assert_eq!(matches(&names, 0, "top@F9.1"), Some(Match::Piece), "a piece of the copy's face");
assert_eq!(matches(&names, 0, "top#[left,slot:a]@F9.1"), Some(Match::Exact));
// Copies of copies carry one instance after another.
let names = qualify(named(&["top#[left]@F9.1@F12.2", "top#[left]@F9.1@F12.1"]), &[]);
assert_eq!(matches(&names, 0, "top#[slot:c]@F9.1@F12.2"), Some(Match::Stem));
assert_eq!(matches(&names, 1, "top#[slot:c]@F9.1@F12.2"), None);
// Hostile suffixes never panic.
for n in ["@", "@F", "@F.", "@F1.", "a@F1.1@", "a#[b]@F1.1]", "@F1.1"] {
let _ = matches(&names, 0, n);
}
}
#[test]
fn pieces_nothing_tells_apart_are_numbered_and_unverified() {
let faces = named(&["top", "top", "ring"]);