Skip to content
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
15 changes: 0 additions & 15 deletions Lib/test/test_unicodedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ def test_no_names_in_pua(self):
char = chr(i)
self.assertRaises(ValueError, self.db.name, char)

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: KeyError not raised by lookup
def test_lookup_nonexistant(self):
# just make sure that lookup can fail
for nonexistent in [
Expand Down Expand Up @@ -360,7 +359,6 @@ def test_bidirectional_unassigned(self):
self.assertEqual(self.db.bidirectional('\U0001FFFE'), '' if self.old else 'BN')
self.assertEqual(self.db.bidirectional('\U00010D01'), '' if self.old else 'AL')

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: '<compat> 03A3 != ''
def test_decomposition(self):
self.assertEqual(self.db.decomposition('\uFFFE'),'')
self.assertEqual(self.db.decomposition('\u00bc'), '<fraction> 0031 2044 0034')
Expand Down Expand Up @@ -700,7 +698,6 @@ def test_east_asian_width(self):
# New in 17.0.0
self.assertEqual(eaw('\U00016FF2'), 'N' if self.old else 'W')

@unittest.skip("TODO: RUSTPYTHON; AssertionError: 'N' != 'W' (passed on latest, fails on 3.2)")
def test_east_asian_width_unassigned(self):
eaw = self.db.east_asian_width
# unassigned
Expand Down Expand Up @@ -1102,18 +1099,6 @@ def test_block_invalid_input(self):
self.assertRaises(TypeError, self.db.block, '')
self.assertRaises(TypeError, self.db.block, 'xx')

@unittest.expectedFailure # TODO: RUSTPYTHON; + N
def test_east_asian_width_9_0_changes(self):
return super().test_east_asian_width_9_0_changes()

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 'D4CC 11B6' != '1111 1171 11B6'
def test_decomposition(self):
return super().test_decomposition()

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: KeyError not raised by lookup
def test_lookup_nonexistant(self):
return super().test_lookup_nonexistant()

@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module 'unicodedata' has no attribute 'digit'
def test_function_checksum(self):
return super().test_function_checksum()
Expand Down
30 changes: 0 additions & 30 deletions crates/unicode/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,36 +371,6 @@ fn generate_decomp(decomp_lines: Vec<(u32, String)>) {
&mut values,
);
write_slice_unordered(&mut writer, "DECOMP_RANGE", "u32", &mut decomp_ranges);

// Normalization corrections is super small - only a handful chars at the time of writing.
let reader = UnicodeLineReader::from_file_name("NormalizationCorrections.txt", true);
let mut values = Vec::new();
for line in reader {
let field = line.field(
NonZeroUsize::new(1).unwrap(),
Some(&format!(
"field 2 missing from NormalizationCorrections: {}",
line.line
)),
);
let original = u32::from_str_radix(field.trim(), 16).unwrap_or_else(|e| {
panic!("field 2 of decomp corrections should be a char in hex: {field} {e}")
});
let version = line.field(
NonZeroUsize::new(3).unwrap(),
Some(&format!(
"field 4 of decomp corrections should be a UCD version: {}",
line.line
)),
);

// `version` = when the char was updated. Therefore, we use the incorrect chars past
// 3.2.0 but skip the chars fixed in 3.2.0 because they'll already be right.
if version != "3.2.0" {
values.push((line.start, original))
}
}
write_slice_pairs(&mut writer, "DECOMP_UPDATES", "(u32, u32)", &mut values);
}

fn generate_algo_names(names: Vec<(u32, Box<str>)>) {
Expand Down
55 changes: 26 additions & 29 deletions crates/unicode/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,16 @@ impl Ucd {
#[must_use]
pub fn lookup(self, search_name: &str) -> Option<LookupResult> {
if let Some(ch) = unicode_names2::character(search_name)
.filter(|&ch| {
character_name(ch).is_some_and(|name| name.eq_ignore_ascii_case(search_name))
})
.or_else(|| AlgorithmicName::check_name(search_name))
{
if self.modern {
return Some(LookupResult::Character(ch));
}
cold_path();

if !self.membership(ch) {
return None;
}

// 3.2.0 doesn't have aliases but unicode_names2 supports aliases so reject them.
if lookup_alias(search_name).is_some() {
return None;
Expand Down Expand Up @@ -381,19 +380,12 @@ impl Ucd {
pub fn east_asian_width(&self, c: CodePoint) -> &'static str {
c.to_char()
.and_then(|c| {
if self.modern {
if self.modern || GeneralCategory::for_char(c) == GeneralCategory::Unassigned {
Some(EastAsianWidth::for_char(c))
} else {
cold_path();
// CPython overrides characters in the PUA for 3.2.0.
// Basic Multilingual Plane:
// https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane
// https://en.wikipedia.org/wiki/Private_Use_Areas
// https://www.unicode.org/reports/tr11/tr11-10.html
// https://www.unicode.org/reports/tr11/
//
// Currently, this implementation is incomplete because I can't figure
// out what CPython is doing.
// CPython keeps modern width defaults for still-unassigned characters.
// Assigned characters use their 3.2 width, or Neutral if new since 3.2.
lookup_table(EAST_ASIAN_WIDTH, c)
}
})
Expand Down Expand Up @@ -445,21 +437,26 @@ impl Ucd {
return String::new();
};

// Decomposition is remarkable stable according to the normalization file,
// so the updates slice is very small - only about four char pairs. Linearly searching
// it is very fast. The file lists the original, incorrect decomp and the fixed char.
// For 3.2.0, we use the original decomp for compatibility while ignoring the update.
//
// Finally, we don't have to do anything for the latest UCD as it's already updated.
if self.modern
&& let Some((_, original)) = DECOMP_UPDATES
.iter()
.find(|&&(codep, _original)| codep == ch as u32)
{
format!("{original:04X}")
} else if let Ok(i) =
DECOMP_COMPAT.binary_search_by_key(&(ch as u32), |&(codep, _, _)| codep)
{
if !self.membership(ch) {
return String::new();
}

// CPython exposes the full Hangul L/V/T decomposition, not ICU's
// non-recursive LV/T decomposition.
let code = ch as u32;
if (0xAC00..0xD7A4).contains(&code) {
let index = code - 0xAC00;
let leading = 0x1100 + index / (21 * 28);
let vowel = 0x1161 + (index % (21 * 28)) / 28;
let trailing = index % 28;
return if trailing == 0 {
format!("{leading:04X} {vowel:04X}")
} else {
format!("{leading:04X} {vowel:04X} {:04X}", 0x11A7 + trailing)
};
}

if let Ok(i) = DECOMP_COMPAT.binary_search_by_key(&(ch as u32), |&(codep, _, _)| codep) {
// Compatibility decomposition
// `icu4x` doesn't expose a non-recursive, compatibility decomposer so we
// have to do it manually for now.
Expand Down
Loading