Skip to content
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
16 changes: 8 additions & 8 deletions unicode/bidi/bidi.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ func (p *Paragraph) prepareInput() (n int, err error) {
return bytecount, nil
}
p.types = append(p.types, cls)
if props.IsOpeningBracket() {

switch {
case !props.IsBracket():
p.pairTypes = append(p.pairTypes, bpNone)
p.pairValues = append(p.pairValues, 0)
case props.IsOpeningBracket():
p.pairTypes = append(p.pairTypes, bpOpen)
p.pairValues = append(p.pairValues, r)
} else if props.IsBracket() {
// this must be a closing bracket,
// since IsOpeningBracket is not true
default:
p.pairTypes = append(p.pairTypes, bpClose)
p.pairValues = append(p.pairValues, r)
} else {
p.pairTypes = append(p.pairTypes, bpNone)
p.pairValues = append(p.pairValues, 0)
p.pairValues = append(p.pairValues, props.reverseBracket(r))
}
}
return bytecount, nil
Expand Down
32 changes: 32 additions & 0 deletions unicode/bidi/bidi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,35 @@ func TestAppendReverse(t *testing.T) {
}

}

func TestBracket(t *testing.T) {
str := `ع a (b)`
p := Paragraph{}
p.SetString(str, DefaultDirection(LeftToRight))
order, err := p.Order()
if err != nil {
log.Fatal(err)
}

expectedRuns := []runInformation{
{"ع ", RightToLeft, 0, 1},
{"a (b)", LeftToRight, 2, 6},
}

if nr, want := order.NumRuns(), len(expectedRuns); nr != want {
t.Errorf("order.NumRuns() = %d; want %d", nr, want)
}

for i, want := range expectedRuns {
r := order.Run(i)
if got := r.String(); got != want.str {
t.Errorf("Run(%d) = %q; want %q", i, got, want.str)
}
if s, e := r.Pos(); s != want.start || e != want.end {
t.Errorf("Run(%d).start = %d, .end = %d; want start = %d, end = %d", i, s, e, want.start, want.end)
}
if d := r.Direction(); d != want.dir {
t.Errorf("Run(%d).Direction = %d; want %d", i, d, want.dir)
}
}
}