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

Yaml.Text(...) fumbles without trailing whitespace #886

Closed
dougbu opened this issue Jan 7, 2024 · 1 comment
Closed

Yaml.Text(...) fumbles without trailing whitespace #886

dougbu opened this issue Jan 7, 2024 · 1 comment

Comments

@dougbu
Copy link
Contributor

dougbu commented Jan 7, 2024

Describe the bug

Many editors either automatically remove trailing whitespace or have extensions that do so. Unfortunately, when trailing whitespace is removed from (say) Serialization/SerializationTests.cs, multiple tests fail with e.g.,

[xUnit.net 00:00:03.99]     ExampleFromSpecificationIsHandledCorrectly [FAIL]
  Failed ExampleFromSpecificationIsHandledCorrectly [1 ms]
  Error Message:
   System.ArgumentOutOfRangeException : startIndex cannot be larger than length of string. (Parameter 'startIndex')
  Stack Trace:
     at System.String.Substring(Int32 startIndex, Int32 length)
   at System.String.Substring(Int32 startIndex)
   at YamlDotNet.Test.Yaml.<>c__DisplayClass10_0.<Text>b__2(String l) in C:\dd\dnx\other\YamlDotNet\YamlDotNet.Test\Yaml.cs:line 111
   at System.Linq.Enumerable.SelectListIterator`2.ToList()
   at YamlDotNet.Test.Yaml.Text(String yamlText) in C:\dd\dnx\other\YamlDotNet\YamlDotNet.Test\Yaml.cs:line 110
   at YamlDotNet.Test.Serialization.SerializationTests.ExampleFromSpecificationIsHandledCorrectly() in C:\dd\dnx\other\YamlDotNet\YamlDotNet.Test\Serialization\SerializationTests.cs:line 1230

That particular test fails at the empty line near the top of the yamlText:

                obj:
                  - &CENTER { x: 1, y: 2 }
                  - &LEFT { x: 0, y: 2 }
                  - &BIG { r: 10 }
                  - &SMALL { r: 1 }

                # All the following maps are equal:

Fix is fairly simple. I'll put up a PR in a bit…

To Reproduce

Edit Serialization/SerializationTests.cs and remove all trailing whitespace, at least in the ExampleFromSpecificationIsHandledCorrectly() fact. Then, execute that test.

dougbu added a commit to dougbu/YamlDotNet that referenced this issue Jan 7, 2024
- see aaubry#886
- transform blank lines to `string.Empty`
- remove all trailing whitespace from lines
  - if trailing whitespace is significant in a future test, YAML files can be added
- `throw new ArgumentException(...)` if a line is insufficiently indented
  - should be easier to fix test than with previous `ArgumentOutOfRangeException` for this case
- add tests
dougbu added a commit to dougbu/YamlDotNet that referenced this issue Jan 7, 2024
- see aaubry#886
- transform blank lines to `string.Empty`
- remove all trailing whitespace from lines
  - if trailing whitespace is significant in a future test, YAML files can be added
- `throw new ArgumentException(...)` if a line is insufficiently indented
  - should be easier to fix test than with previous `ArgumentOutOfRangeException` for this case
- add tests
@dougbu
Copy link
Contributor Author

dougbu commented Jan 23, 2024

fixed in #887 and merged (thanks @aaubry❕) today

@dougbu dougbu closed this as completed Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant