-
Notifications
You must be signed in to change notification settings - Fork 3
fix(parser): comment before next binding bleeds into previous content_position #143
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -947,4 +947,48 @@ _: opcode-1(0xabcd 456); | |
| assert_eq!(inner.hash, inner_hash_hex); | ||
| assert_eq!(inner.unwrap_constant_binding(), "0x1111"); | ||
| } | ||
|
|
||
| // Mutation-validated: revert the process_binding fix (restore content_text path) and | ||
| // this test fails because b1's content_position extends through the comment. | ||
| #[test] | ||
| fn test_comment_before_binding_excluded_from_previous_content_position() { | ||
| let store = Store::new(); | ||
| let meta_store = Arc::new(RwLock::new(store)); | ||
|
|
||
| // Comment before #b2 must not appear in b1's content or content_position. | ||
| let text = "---\n#b1\n! elided\n\n/* comment for b2 */\n#b2\n! elided2\n"; | ||
| let rain_document = | ||
| RainDocument::create(text.to_owned(), Some(meta_store.clone()), None, None); | ||
|
|
||
| let b1 = rain_document | ||
| .bindings() | ||
| .iter() | ||
| .find(|b| b.name == "b1") | ||
| .expect("binding b1 not found"); | ||
|
|
||
| // b1 content must be the elision text only, not including the comment. | ||
| assert_eq!(b1.content, "! elided"); | ||
|
|
||
| // b1 content_position must end at the last char of "! elided", not at the comment. | ||
| let content_end = b1.content_position[1]; | ||
| let text_at_end = text.get(b1.content_position[0]..content_end).unwrap(); | ||
| assert_eq!(text_at_end, "! elided"); | ||
|
|
||
| // The comment text must not appear anywhere inside b1's content_position range. | ||
| let b1_content_range = text | ||
| .get(b1.content_position[0]..b1.content_position[1]) | ||
| .unwrap(); | ||
| assert!( | ||
| !b1_content_range.contains("/*"), | ||
| "comment leaked into b1 content_position: {b1_content_range:?}" | ||
| ); | ||
|
|
||
| // b2 must also parse correctly. | ||
| let b2 = rain_document | ||
| .bindings() | ||
| .iter() | ||
| .find(|b| b.name == "b2") | ||
| .expect("binding b2 not found"); | ||
| assert_eq!(b2.content, "! elided2"); | ||
| } | ||
|
Comment on lines
+953
to
+993
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win Solid regression test for the exclusion path; consider covering the complementary cases. This validates that a trailing comment before 🤖 Prompt for AI Agents |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: rainlanguage/dotrain
Length of output: 403
🏁 Script executed:
Repository: rainlanguage/dotrain
Length of output: 24199
🏁 Script executed:
Repository: rainlanguage/dotrain
Length of output: 8244
🏁 Script executed:
Repository: rainlanguage/dotrain
Length of output: 19722
🏁 Script executed:
Repository: rainlanguage/dotrain
Length of output: 11446
Clamp
content_positionbefore storing itBindings whose content is only comments after leading whitespace can still end up with
start > end:trimmed_origpreserves the comment text, whileraw_trimmed.2trims the comment-replaced slice back to the start of the content. The local.get(...).unwrap_or("")hides it here, butcontent_positionis still stored as a malformed range.🤖 Prompt for AI Agents