Skip to content
Merged
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
70 changes: 70 additions & 0 deletions shaping/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,76 @@ func TestSplitScript(t *testing.T) {
tu.Assert(t, got.Script == run.script)
}
}

// Verifies that Arabic diacritics (which usually have
// script 'Inherited') are correctly clustered with their base Arabic letters,
// rather than being split into a separate shaping run.
for _, test := range []struct {
text []rune
expectedRuns []run
}{
{
// Arabic Letter + Diacritic
// \u0628 => BEH
// \u0650 => KASRA (Diacritic)
[]rune{'\u0628', '\u0650'},
[]run{{0, 2, language.Arabic}},
},
{
// Arabic Word with Multiple Diacritics
[]rune{
'\u0628', // BEH
'\u0650', // KASRA
'\u0633', // SEEN
'\u0652', // SUKUN
'\u0645', // MEEM
'\u0650', // KASRA
},
[]run{{0, 6, language.Arabic}},
},
{
// Mixed Script (CONTROL Case) #1
// Arabic Letter + Latin Letter
// THESE MUST SPLIT TO 2.
[]rune{'\u0628', 'A'},
[]run{
{0, 1, language.Arabic},
{1, 2, language.Latin},
},
},
{
// Mixed Script (CONTROL Case) #2
// Arabic Letter + Diacritic + Diacritic + Latin Letter + Arabic Letter + Diacritic
// THESE MUST SPLIT TO 3.
[]rune{'\u0628', '\u0651', '\u0650', 'A', '\u0628', '\u0650'},
[]run{
{0, 3, language.Arabic},
{3, 4, language.Latin},
{4, 6, language.Arabic},
},
},
{
// Mixed Script (A little 'stress' test)
// Latin 's' + Arabic Kasra + Latin 'r' + Arabic Fatha
// this is technically valid unicode!
// the diacritics should inherit "Latin"
[]rune{'s', '\u0651', '\u0650', 'r', '\u064E'},
[]run{{0, 5, language.Latin}},
},
} {
var seg Segmenter
seg.splitByBidi(Input{Text: test.text, RunEnd: len(test.text), Direction: di.DirectionLTR})
seg.input, seg.output = seg.output, seg.input

seg.splitByScript()
tu.Assert(t, len(seg.output) == len(test.expectedRuns))
for i, run := range test.expectedRuns {
got := seg.output[i]
tu.Assert(t, got.RunStart == run.start)
tu.Assert(t, got.RunEnd == run.end)
tu.Assert(t, got.Script == run.script)
}
}
}

func TestSplitVertOrientation(t *testing.T) {
Expand Down