Skip to content

Commit

Permalink
Bug 1824671 - patch 4 - Update Gtest to accept either ICU4C or unicod…
Browse files Browse the repository at this point in the history
…e-bidi handling of the embedding controls (explicitly unspecified by UAX#9). r=platform-i18n-reviewers,dminor

unicode-bidi more closely follows the UAX#9 recommendations for processing embedding controls
if they're not actually removed from the text; but this is not an actual spec requirement,
so either behavior is acceptable.

Differential Revision: https://phabricator.services.mozilla.com/D197891
  • Loading branch information
jfkthame committed Feb 6, 2024
1 parent fafbd7f commit 54fc032
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions intl/components/gtest/TestBidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,24 +184,39 @@ TEST(IntlBidi, RtlOverride)
ASSERT_EQ(bidi.GetParagraphEmbeddingLevel(), 0);
ASSERT_EQ(bidi.GetParagraphDirection(), Bidi::ParagraphDirection::Mixed);

// Note that the Unicode Bidi Algorithm explicitly does NOT require any
// specific placement or levels for the embedding controls (see
// rule https://www.unicode.org/reports/tr9/#X9).
// Further, the implementation notes at
// https://www.unicode.org/reports/tr9/#Retaining_Explicit_Formatting_Characters
// advise to "Resolve any LRE, RLE, LRO, RLO, PDF, or BN to the level of the
// preceding character if there is one...", which means the embedding marks
// here will each become part of the *preceding* run. This is how the Rust
// unicode-bidi implementation behaves.
// However, ICU4C behavior is such that they take on the level of the *next*
// character, and become part of the following run.
// For now, we accept either result here.
{
auto logicalRun = logicalRunIter.Next();
ASSERT_TRUE(logicalRun.isSome());
ASSERT_EQ(logicalRun->string, MakeStringSpan(u"ltr"));
ASSERT_TRUE(logicalRun->string == MakeStringSpan(u"ltr") ||
logicalRun->string == MakeStringSpan(u"ltr\u202b"));
ASSERT_EQ(logicalRun->embeddingLevel, 0);
ASSERT_EQ(logicalRun->embeddingLevel.Direction(), BidiDirection::LTR);
}
{
auto logicalRun = logicalRunIter.Next();
ASSERT_TRUE(logicalRun.isSome());
ASSERT_EQ(logicalRun->string, MakeStringSpan(u"\u202b___رائع___"));
ASSERT_TRUE(logicalRun->string == MakeStringSpan(u"\u202b___رائع___") ||
logicalRun->string == MakeStringSpan(u"___رائع___\u202a"));
ASSERT_EQ(logicalRun->embeddingLevel, 1);
ASSERT_EQ(logicalRun->embeddingLevel.Direction(), BidiDirection::RTL);
}
{
auto logicalRun = logicalRunIter.Next();
ASSERT_TRUE(logicalRun.isSome());
ASSERT_EQ(logicalRun->string, MakeStringSpan(u"\u202a___ltr__"));
ASSERT_TRUE(logicalRun->string == MakeStringSpan(u"\u202a___ltr__") ||
logicalRun->string == MakeStringSpan(u"___ltr__"));
ASSERT_EQ(logicalRun->embeddingLevel, 2);
ASSERT_EQ(logicalRun->embeddingLevel.Direction(), BidiDirection::LTR);
}
Expand Down Expand Up @@ -254,19 +269,22 @@ TEST(IntlBidi, VisualRunsWithEmbeds)
{
Maybe<VisualRun> run = visualRunIter.Next();
ASSERT_TRUE(run.isSome());
ASSERT_EQ(run->string, MakeStringSpan(u"ltr"));
ASSERT_TRUE(run->string == MakeStringSpan(u"ltr") ||
run->string == MakeStringSpan(u"ltr\u202b"));
ASSERT_EQ(run->direction, BidiDirection::LTR);
}
{
Maybe<VisualRun> run = visualRunIter.Next();
ASSERT_TRUE(run.isSome());
ASSERT_EQ(run->string, MakeStringSpan(u"\u202a___ltr___"));
ASSERT_TRUE(run->string == MakeStringSpan(u"\u202a___ltr___") ||
run->string == MakeStringSpan(u"___ltr___"));
ASSERT_EQ(run->direction, BidiDirection::LTR);
}
{
Maybe<VisualRun> run = visualRunIter.Next();
ASSERT_TRUE(run.isSome());
ASSERT_EQ(run->string, MakeStringSpan(u"\u202b___رائع___"));
ASSERT_TRUE(run->string == MakeStringSpan(u"\u202b___رائع___") ||
run->string == MakeStringSpan(u"___رائع___\u202a"));
ASSERT_EQ(run->direction, BidiDirection::RTL);
}
{
Expand Down

0 comments on commit 54fc032

Please sign in to comment.