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

add missing unicode categories in python library #3872

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion src/fable-library-py/fable_library/char.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,19 @@ class UnicodeCategory(IntEnum):
"Sk": UnicodeCategory.ModifierSymbol,
"Mn": UnicodeCategory.NonSpacingMark,
"Lo": UnicodeCategory.OtherLetter,
"No": UnicodeCategory.OtherLetter,
"No": UnicodeCategory.OtherNumber,
"Lt": UnicodeCategory.TitlecaseLetter,
"Cn": UnicodeCategory.OtherNotAssigned,
"Co": UnicodeCategory.PrivateUse,
"Cs": UnicodeCategory.Surrogate,
"Zp": UnicodeCategory.ParagraphSeparator,
"Lm": UnicodeCategory.ModifierLetter,
"Mc": UnicodeCategory.SpacingCombiningMark,
"Me": UnicodeCategory.EnclosingMark,
"Pe": UnicodeCategory.ClosePunctuation,
"Pf": UnicodeCategory.FinalQuotePunctuation,
"Ps": UnicodeCategory.OpenPunctuation,
"So": UnicodeCategory.OtherSymbol,
}


Expand Down
51 changes: 51 additions & 0 deletions tests/Python/TestString.fs
Original file line number Diff line number Diff line change
Expand Up @@ -959,3 +959,54 @@ let ``test calling ToString(CultureInfo.InvariantCulture) works`` () =
(1).ToString(CultureInfo.InvariantCulture) |> equal "1"
(7923209L).ToString(CultureInfo.InvariantCulture) |> equal "7923209"
(7923209UL).ToString(CultureInfo.InvariantCulture) |> equal "7923209"


#if FABLE_COMPILER
open Fable.Core

[<Import("category", "unicodedata")>]
let unicodeCategory: char -> string = nativeOnly

[<Fact>]
let ``test unicode categories`` () =
let chars = [
"\x00", "Cc"
" ", "Zs"
"!", "Po"
"$", "Sc"
"(", "Ps"
")", "Pe"
"+", "Sm"
"-", "Pd"
"0", "Nd"
"A", "Lu"
"^", "Sk"
"_", "Pc"
"a", "Ll"
"¦", "So"
"ª", "Lo"
"«", "Pi"
"\xad", "Cf"
"²", "No"
"»", "Pf"
"Dž", "Lt"
"ʰ", "Lm"
"", "Mn"
"\u0378", "Cn"
"\u0488", "Me"
"\u0903", "Mc"
"\u16ee", "Nl"
"\u2028", "Zl"
"\u2029", "Zp"
//TODO: this fails with error EXCEPTION: Unable to translate Unicode character \\uD800 at index 116 to specified code page.
//"\ud800" , "Cs"
"\ue000", "Co"
]
for (s, cat) in chars do
s
|> String.iter (fun c ->
// this ensures that the character is from the expected category
cat |> equal (unicodeCategory c)
Char.IsLetterOrDigit c |> ignore
)
#endif
Loading