|
| 1 | +// RUN: %target-run-simple-swift %t |
| 2 | +// REQUIRES: executable_test |
| 3 | + |
| 4 | +import StdlibUnittest |
| 5 | + |
| 6 | +var UnicodeScalarPropertiesTests = TestSuite("UnicodeScalarPropertiesTests") |
| 7 | + |
| 8 | +func us(_ scalar: Unicode.Scalar) -> Unicode.Scalar { return scalar } |
| 9 | + |
| 10 | +UnicodeScalarPropertiesTests.test("lowercased") { |
| 11 | + expectEqual("2", us("2").lowercased()) |
| 12 | + expectEqual("i", us("I").lowercased()) |
| 13 | + expectEqual("i\u{0307}", us("\u{0130}").lowercased()) |
| 14 | + // There are currently no lowercase mappings that produce multiple graphemes. |
| 15 | +} |
| 16 | + |
| 17 | +UnicodeScalarPropertiesTests.test("uppercased") { |
| 18 | + expectEqual("2", us("2").uppercased()) |
| 19 | + expectEqual("I", us("i").uppercased()) |
| 20 | + expectEqual("\u{02BC}N", us("\u{0149}").uppercased()) // multiple scalars |
| 21 | + expectEqual("SS", us("ß").uppercased()) // multiple graphemes |
| 22 | + expectEqual("FFL", us("\u{FB04}").uppercased()) // multiple graphemes |
| 23 | +} |
| 24 | + |
| 25 | +UnicodeScalarPropertiesTests.test("titlecased") { |
| 26 | + expectEqual("2", us("2").titlecased()) |
| 27 | + expectEqual("I", us("i").titlecased()) |
| 28 | + expectEqual("\u{02BC}N", us("\u{0149}").titlecased()) // multiple scalars |
| 29 | + expectEqual("Ff", us("\u{FB00}").titlecased()) // multiple graphemes |
| 30 | + expectEqual("Ffl", us("\u{FB04}").titlecased()) // multiple graphemes |
| 31 | +} |
| 32 | + |
| 33 | +UnicodeScalarPropertiesTests.test("properties.name") { |
| 34 | + // A scalar with no assigned name returns nil. |
| 35 | + expectNil(us("\u{0000}").properties.name) |
| 36 | + |
| 37 | + // Try some results that should fit in small strings. |
| 38 | + expectEqual("CARE OF", us("\u{2105}").properties.name) |
| 39 | + expectEqual("ACCOUNT OF", us("\u{2100}").properties.name) |
| 40 | + |
| 41 | + // Try some results that need heap-allocated strings. |
| 42 | + expectEqual("LATIN SMALL LETTER A", us("\u{0061}").properties.name) |
| 43 | + expectEqual( |
| 44 | + "COMBINING LEFTWARDS HARPOON WITH BARB DOWNWARDS", |
| 45 | + us("\u{20ED}").properties.name) |
| 46 | + expectEqual( |
| 47 | + "PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRAKCET", // [sic] |
| 48 | + us("\u{FE18}").properties.name) |
| 49 | + |
| 50 | + // Try some boundary cases around the length limit of a SmallUTF8String. |
| 51 | + expectEqual("COMBINING HORN", us("\u{031B}").properties.name) // 14 |
| 52 | + expectEqual("COMBINING TILDE", us("\u{0303}").properties.name) // 15 |
| 53 | + expectEqual("COMBINING MACRON", us("\u{0304}").properties.name) // 16 |
| 54 | +} |
| 55 | + |
| 56 | +UnicodeScalarPropertiesTests.test("properties.nameAlias") { |
| 57 | + // A scalar with no assigned alias returns nil. |
| 58 | + expectNil(us("\u{0000}").properties.nameAlias) |
| 59 | + expectNil(us("\u{0040}").properties.nameAlias) |
| 60 | + |
| 61 | + // Try some aliases of varying lengths, getting some small and large string |
| 62 | + // coverage. |
| 63 | + expectEqual("LAO LETTER RO", us("\u{0EA3}").properties.nameAlias) |
| 64 | + expectEqual("MICR DASH SYMBOL", us("\u{2449}").properties.nameAlias) |
| 65 | + expectEqual( |
| 66 | + "PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRACKET", |
| 67 | + us("\u{FE18}").properties.nameAlias) |
| 68 | +} |
| 69 | + |
| 70 | +UnicodeScalarPropertiesTests.test("properties.age") { |
| 71 | + func expectAgeEqual( |
| 72 | + _ expected: (Int, Int), |
| 73 | + _ scalar: Unicode.Scalar, |
| 74 | + _ message: String = "", |
| 75 | + file: String = #file, |
| 76 | + line: UInt = #line |
| 77 | + ) { |
| 78 | + expectNotNil(scalar.properties.age, message, file: file, line: line) |
| 79 | + expectEqual( |
| 80 | + expected, scalar.properties.age!, message, file: file, line: line) |
| 81 | + } |
| 82 | + |
| 83 | + expectNil(us("\u{0378}").properties.age) |
| 84 | + expectAgeEqual((1, 1), "\u{0040}") |
| 85 | + expectAgeEqual((3, 0), "\u{3500}") |
| 86 | + expectAgeEqual((3, 2), "\u{FE00}") |
| 87 | + expectAgeEqual((6, 1), "\u{11180}") |
| 88 | +} |
| 89 | + |
| 90 | +runAllTests() |
0 commit comments