-
Notifications
You must be signed in to change notification settings - Fork 64
Fix sigil formatting bug that produced invalid mixed syntax #371
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
Closed
+197
−3
Closed
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d102ae4
Fix sigil formatting bug that produced invalid mixed syntax
williamthome 77d7f6a
Improve sigil formatting to break containers with multiline sigils
williamthome fe1edd4
Refine sigil formatting to handle triple-quoted sigils properly
williamthome 552a2e9
Add comprehensive tests for triple-quoted sigil behavior
williamthome 08de55a
Remove unreachable fallback clause from sigil handling
williamthome d8cbea4
Improve test string formatting for better readability
williamthome 0899828
Fix triple-quoted sigils to break containers consistently
williamthome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -295,7 +295,171 @@ sigils(Config) when is_list(Config) -> | |
| ), | ||
| ?assertSame("~s\"\"\"\n\\tabc\n\\tdef\n\"\"\"\n"), | ||
| ?assertSame("\"\"\"\nTest\nMultiline\n\"\"\"\n"), | ||
| ?assertSame("~\"\"\"\nTest\nMultiline\n\"\"\"\n"). | ||
| ?assertSame("~\"\"\"\nTest\nMultiline\n\"\"\"\n"), | ||
| %% Test multiline sigils in lists cause list to break | ||
| ?assertFormat( | ||
| "[~\"\n" | ||
| " foo\n" | ||
| " \"].\n", | ||
| "[\n" | ||
| " ~\"\n" | ||
| " foo\n" | ||
| " \"\n" | ||
| "].\n" | ||
| ), | ||
| %% Triple-quoted sigils don't cause container breaks (they handle indentation properly) | ||
| ?assertSame( | ||
| "[~\"\"\"\n" | ||
| " foo\n" | ||
| " bar\n" | ||
| " \"\"\"].\n" | ||
| ), | ||
|
||
| %% Triple-quoted sigils with prefixes also don't break containers | ||
| ?assertSame( | ||
| "[~s\"\"\"\n" | ||
| " content\n" | ||
| " with prefix\n" | ||
| " \"\"\"].\n" | ||
| ), | ||
| %% Triple-quoted sigils in tuples don't break containers | ||
| ?assertSame( | ||
| "{~\"\"\"\n" | ||
| " tuple content\n" | ||
| " \"\"\", other}.\n" | ||
| ), | ||
| %% Triple-quoted sigils in function calls don't break containers | ||
| ?assertSame( | ||
| "process(~\"\"\"\n" | ||
| " function arg\n" | ||
| " \"\"\").\n" | ||
| ), | ||
| %% Edge case: minimal triple-quoted sigil content | ||
| ?assertSame( | ||
| "[~\"\"\"\n" | ||
| "\"\"\"].\n" | ||
| ), | ||
| %% Mixed triple-quoted and regular multiline sigils show different behavior | ||
| ?assertFormat( | ||
| "[~\"\"\"\n" | ||
| " triple quoted\n" | ||
| " \"\"\", ~\"\n" | ||
| " regular multiline\n" | ||
| " \"].\n", | ||
| "[\n" | ||
| " ~\"\"\"\n" | ||
| " triple quoted\n" | ||
| " \"\"\",\n" | ||
| " ~\"\n" | ||
| " regular multiline\n" | ||
| " \"\n" | ||
| "].\n" | ||
| ), | ||
| %% Test sigils with prefixes and modifiers in lists | ||
| ?assertFormat( | ||
| "[~s\"\n" | ||
| " foo\n" | ||
| " \"].\n", | ||
| "[\n" | ||
| " ~s\"\n" | ||
| " foo\n" | ||
| " \"\n" | ||
| "].\n" | ||
| ), | ||
| ?assertFormat( | ||
| "[~b\"\n" | ||
| " foo\n" | ||
| " \"x].\n", | ||
| "[\n" | ||
| " ~b\"\n" | ||
| " foo\n" | ||
| " \"x\n" | ||
| "].\n" | ||
| ), | ||
| %% Test mixed regular and sigil strings in lists | ||
| ?assertFormat( | ||
| "[\"regular\n" | ||
| " multiline\", ~\"sigil\n" | ||
| " multiline\"].\n", | ||
| "[\n" | ||
| " \"regular\\n\"\n" | ||
| " \" multiline\",\n" | ||
| " ~\"sigil\n" | ||
| " multiline\"\n" | ||
| "].\n" | ||
| ), | ||
| %% Test sigils in tuples | ||
| ?assertFormat( | ||
| "{~\"\n" | ||
| " foo\n" | ||
| " \", bar}.\n", | ||
| "{\n" | ||
| " ~\"\n" | ||
| " foo\n" | ||
| " \",\n" | ||
| " bar\n" | ||
| "}.\n" | ||
| ), | ||
| %% Test sigils in function calls | ||
| ?assertFormat( | ||
| "foo(~\"\n" | ||
| " multiline\n" | ||
| " \").\n", | ||
| "foo(\n" | ||
| " ~\"\n" | ||
| " multiline\n" | ||
| " \"\n" | ||
| ").\n" | ||
| ), | ||
| %% Test sigils in function arguments with other expressions | ||
| ?assertFormat( | ||
| "foo(\"regular\n" | ||
| " string\", ~\"sigil\n" | ||
| " string\", atom).\n", | ||
| "foo(\n" | ||
| " \"regular\\n\"\n" | ||
| " \" string\",\n" | ||
| " ~\"sigil\n" | ||
| " string\",\n" | ||
| " atom\n" | ||
| ").\n" | ||
| ), | ||
| %% Test sigils in maps | ||
| ?assertFormat( | ||
| "#{key => ~\"\n" | ||
| " value\n" | ||
| " \"}.\n", | ||
| "#{\n" | ||
| " key =>\n" | ||
| " ~\"\n" | ||
| " value\n" | ||
| " \"\n" | ||
| "}.\n" | ||
| ), | ||
| %% Test sigils in records | ||
| ?assertFormat( | ||
| "#rec{field = ~\"\n" | ||
| " value\n" | ||
| " \"}.\n", | ||
| "#rec{\n" | ||
| " field =\n" | ||
| " ~\"\n" | ||
| " value\n" | ||
| " \"\n" | ||
| "}.\n" | ||
| ), | ||
| %% Test sigils cause containers to break but preserve sigil content | ||
| ?assertFormat( | ||
| "test() ->\n" | ||
| " [~\"\n" | ||
| " \", b, c].\n", | ||
| "test() ->\n" | ||
| " [\n" | ||
| " ~\"\n" | ||
| " \",\n" | ||
| " b,\n" | ||
| " c\n" | ||
| " ].\n" | ||
| ). | ||
|
|
||
| dotted(Config) when is_list(Config) -> | ||
| ?assertSame("<0.1.2>\n"), | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This will not work correctly for multiple nesting levels. We need to do the same logic as is done in normal triple-quoted strings in
string_to_algebra, just add prefix and suffix around it.Furthermore, ideally we'd avoid duplicating this logic and just share the code.
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.
Could you clarify what specific aspect of nesting isn't working correctly and provide a specific example of a case that's currently broken?
I want to make sure I understand the issue properly before implementing a fix.
A concrete failing test case would help me understand the exact issue you're referring to.