-
-
Notifications
You must be signed in to change notification settings - Fork 504
Recognize supplementary characters #913
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
Merged
+2,324
−26
Merged
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
f43d988
Recognize supplementary characters
tats-u 2a851a2
Internatize Rune
tats-u de5d3fe
Fix failing tests
tats-u 095f0ed
Fix extra comment error
tats-u 948bf66
Remove extra local variable c
tats-u e968e52
Reorganize classes around Rune
tats-u bbffa33
Prepare both Rune and char variants / make Rune variant public for .NET
tats-u 3a65e4b
Make APIs in StringSlice.cs public only in modern .NET
tats-u 0f928a2
Throw exception if cannot obtain first Rune
tats-u a4c9146
Add comments
tats-u 9839b99
Add comment on PeekRuneExtra
tats-u 3ba8a3c
Use `Rune.TryCreate`
tats-u 8ab6542
Remove backtrack
tats-u f6d6916
Fix parameter name in XML comment
tats-u 03822ac
Don't throw when error in `Rune.DecodeFromUtf16`
tats-u b9d9e09
Fix RuneAt
tats-u 476fb63
Add tests of Rune-related methods of `StringSlice`
tats-u 4cb6895
Make comment more tolerant of changes
tats-u e1e58cb
Tweak comment
tats-u b302cbc
Fix comment
tats-u a0d08bf
Add `readonly`
tats-u 31f48ac
Move namespace of polyfilled Rune out of System.Text
tats-u dbcbcf9
Apply suggestions from code review
tats-u 7d4a678
Fix regression by review suggestion
tats-u b23a002
Merge remote-tracking branch 'origin/master' into rune
tats-u c048018
Prepare constant for .NET Standard test
tats-u 15baf1e
Don't call `IsPunctuationException` if unnecessary
tats-u 3272f9a
PR feedback
MihaZupan 0675757
Merge pull request #1 from MihaZupan/rune-feedback
tats-u 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
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 |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // Copyright (c) Alexandre Mutel. All rights reserved. | ||
| // This file is licensed under the BSD-Clause 2 license. | ||
| // See the license.txt file in the project root for more information. | ||
|
|
||
| using Markdig.Helpers; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Drawing; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Markdig.Tests; | ||
|
|
||
| [TestFixture] | ||
| internal class TestStringSlice | ||
| { | ||
| // TODO: Add more tests for StringSlice | ||
|
|
||
| // Old versions of modern .NET (that meets NETCOREAPP but not the following #if) try to load the polyfilled Rune in .NET Standard 2.x build of Markdig while they have built-in Rune too | ||
| // Adjust this condition to match the minimal modern (not .NET Standard or Framework) .NET target framework of Markdig (not Markdig.Tests) | ||
| #if NET8_0_OR_GREATER | ||
|
|
||
| [Test] | ||
| public void TestRuneBmp() | ||
| { | ||
| var slice = new StringSlice("01234"); | ||
|
|
||
| Assert.AreEqual((Rune)'0', slice.CurrentRune); | ||
| Assert.AreEqual((Rune)'1', slice.NextRune()); | ||
| Assert.AreEqual((Rune)'2', slice.NextRune()); | ||
| Assert.AreEqual((Rune)'2', slice.CurrentRune); | ||
| Assert.AreEqual("234", slice.ToString()); | ||
| Assert.AreEqual((Rune)'3', slice.PeekRuneExtra(1)); | ||
| Assert.AreEqual((Rune)'4', slice.PeekRuneExtra(2)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(3)); | ||
| Assert.AreEqual((Rune)'1', slice.PeekRuneExtra(-1)); | ||
| Assert.AreEqual((Rune)'0', slice.PeekRuneExtra(-2)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(-3)); | ||
| Assert.AreEqual((Rune)'0', slice.RuneAt(0)); | ||
| Assert.AreEqual((Rune)'1', slice.RuneAt(1)); | ||
| Assert.AreEqual((Rune)'2', slice.RuneAt(2)); | ||
| Assert.AreEqual((Rune)'3', slice.RuneAt(3)); | ||
| Assert.AreEqual((Rune)'4', slice.RuneAt(4)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TestRuneSupplementaryOnly() | ||
| { | ||
| var slice = new StringSlice("𝟎𝟏𝟐𝟑𝟒"); | ||
|
|
||
| // 𝟎 = U+1D7CE, 𝟐 = U+1D7D0 | ||
| Assert.AreEqual((Rune)0x1D7CE, slice.CurrentRune); // 𝟎 | ||
| Assert.AreEqual((Rune)0x1D7CF, slice.NextRune()); // 𝟏 | ||
| Assert.AreEqual((Rune)0x1D7D0, slice.NextRune()); // 𝟐 | ||
| Assert.AreEqual((Rune)0x1D7D0, slice.CurrentRune); // 𝟐 | ||
| Assert.AreEqual("𝟐𝟑𝟒", slice.ToString()); | ||
| // CurrentRune occupies 2 `char`s, so next Rune starts at index 2 | ||
| Assert.AreEqual((Rune)0x1D7D1, slice.PeekRuneExtra(2)); // 𝟑 | ||
| Assert.AreEqual((Rune)0x1D7D2, slice.PeekRuneExtra(4)); // 𝟒 | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(6)); | ||
| Assert.AreEqual((Rune)0x1D7CF, slice.PeekRuneExtra(-1)); // 𝟏 | ||
| Assert.AreEqual((Rune)0x1D7CE, slice.PeekRuneExtra(-3)); // 𝟎 | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(-5)); | ||
| Assert.AreEqual((Rune)0x1D7CE, slice.RuneAt(0)); // 𝟎 | ||
| Assert.AreEqual((Rune)0x1D7CF, slice.RuneAt(2)); // 𝟏 | ||
| Assert.AreEqual((Rune)0x1D7D0, slice.RuneAt(4)); // 𝟐 | ||
| Assert.AreEqual((Rune)0x1D7D1, slice.RuneAt(6)); // 𝟑 | ||
| Assert.AreEqual((Rune)0x1D7D2, slice.RuneAt(8)); // 𝟒 | ||
| // The following usages are not expected. You should take into consideration the `char`s that the Rune you just acquired occupies. | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(-4)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(-2)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(1)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(3)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(5)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(1)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(3)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(5)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(7)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(9)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TestRuneIsolatedHighSurrogate() | ||
| { | ||
| var slice = new StringSlice("\ud800\ud801\ud802\ud803\ud804"); | ||
| Assert.AreEqual((Rune)'\0', slice.CurrentRune); | ||
| Assert.AreEqual((Rune)'\0', slice.NextRune()); | ||
| Assert.AreEqual('\ud801', slice.CurrentChar); | ||
| Assert.AreEqual((Rune)'\0', slice.NextRune()); | ||
| Assert.AreEqual('\ud802', slice.CurrentChar); | ||
| Assert.AreEqual((Rune)'\0', slice.CurrentRune); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(-3)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(-2)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(-1)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(1)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(2)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(3)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(0)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(1)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(2)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(3)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(4)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TestRuneIsolatedLowSurrogate() | ||
| { | ||
| var slice = new StringSlice("\udc00\udc01\udc02\udc03\udc04"); | ||
| Assert.AreEqual((Rune)'\0', slice.CurrentRune); | ||
| Assert.AreEqual((Rune)'\0', slice.NextRune()); | ||
| Assert.AreEqual('\udc01', slice.CurrentChar); | ||
| Assert.AreEqual((Rune)'\0', slice.NextRune()); | ||
| Assert.AreEqual('\udc02', slice.CurrentChar); | ||
| Assert.AreEqual((Rune)'\0', slice.CurrentRune); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(-3)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(-2)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(-1)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(1)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(2)); | ||
| Assert.AreEqual((Rune)'\0', slice.PeekRuneExtra(3)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(0)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(1)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(2)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(3)); | ||
| Assert.AreEqual((Rune)'\0', slice.RuneAt(4)); | ||
| } | ||
| #endif | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.