Skip to content
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

More tests for backslash behaviour #438

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/test_cases/expected_kdl/esc_multiple_newlines.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node "12"
1 change: 1 addition & 0 deletions tests/test_cases/expected_kdl/escline_alone.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions tests/test_cases/expected_kdl/escline_end_of_node.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a
b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node "a\\ b\na\\b"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node "\"\"\""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node " a"
4 changes: 4 additions & 0 deletions tests/test_cases/input/esc_multiple_newlines.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node "1\


2"
1 change: 1 addition & 0 deletions tests/test_cases/input/escline_alone.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm confused: is this actually allowed? I think it should be (just allow all whitespace to be escaped even if it's meaning less) but right now I'm not sure what the spec actually says right now

3 changes: 3 additions & 0 deletions tests/test_cases/input/escline_end_of_node.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a \

b
1 change: 1 addition & 0 deletions tests/test_cases/input/escline_node.kdl
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node1
\
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the filename I figured this test was missing something...

Copy link
Member

@bgotink bgotink Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is allowed per spec, but I'm surprised by that.

line-space doesn't contain escline, only node-space has escline
All whitespace between nodes is line-space, so on first sight this test would be invalid, but…
base-node starts with slashdash? type? node-space* string which means this is valid

node1
\
node2

but this isn't

(lorem)node1
\
(lorem)node2

I personally always read the start of base-node as slashdash? (type node-space*)? string, as I interpreted the node-space to be meant as space between the type and name. Apparently that's also how I implemented this, as my parser fails this test atm.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...I noticed this recently in kdl-rs too and it made me wonder whether escline should be part of line-space.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what in the spec allows this, btw?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see:

(type) \
node

is allowed and (type) is optional, therefore

\
node

is allowed.

Quite separately,

/- \
(type)node

and even

/-
\
(type)node

are allowed because /- can always be followed by node-space, even when not in a node.

IMHO, this is too confusing and escline belongs in line-space.

node2
4 changes: 4 additions & 0 deletions tests/test_cases/input/multiline_string_double_backslash.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node """
a\\ b
a\\\ b
"""
3 changes: 3 additions & 0 deletions tests/test_cases/input/multiline_string_escape_delimiter.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node """
\"""
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node """
a
\
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node """
a
\
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node """
\s escaped prefix
literal prefix
"""
Loading