Files
openchamber-android-native/third_party/mygo/ui/richtext/quotebar_test.go
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
2026-11-18 13:22:59 +08:00

69 lines
2.0 KiB
Go

package richtext
import (
"testing"
"github.com/egoist/mygo/ui"
)
// The bars of a quotation's paragraphs join as one: rounded at the
// quotation's ends only, so that no notch shows where two paragraphs
// meet, even at the bar's outer edges.
func TestQuoteBarsJoin(t *testing.T) {
doc := NewDocument(TextOf(
para("Before"),
Paragraph{Style: ParagraphStyle{Quote: true}, Runs: []Run{{Text: "One"}}},
Paragraph{Style: ParagraphStyle{Quote: true}, Runs: []Run{{Text: "Two"}}},
para("After"),
))
red := ui.RGB(255, 0, 0)
boxes := new([]ParagraphBox)
tt := openTester(t, func(c *ui.Context) {
*boxes = doc.VisibleParagraphs()
EditorBase(c, doc, EditorOptions{Font: ui.Font{Size: 10},
Theme: &Theme{QuoteBar: red, QuoteBarWidth: 6, ParagraphSpacing: 0.8}}).Fill()
}, 300, 200)
tt.Frame()
if len(*boxes) != 4 {
t.Fatalf("%d paragraphs in view, want 4", len(*boxes))
}
one, two := (*boxes)[1], (*boxes)[2]
img := tt.Image()
s := float32(img.Bounds().Dx()) / 300
isRed := func(x, y int) bool {
c := img.RGBAAt(x, y)
return c.R > 200 && c.G < 60 && c.B < 60
}
row := int((one.Top + one.Height/2) * s)
first, last := -1, -1
for x := 0; x < img.Bounds().Dx()/2; x++ {
if isRed(x, row) {
if first < 0 {
first = x
}
last = x
}
}
if first < 0 {
t.Fatal("no bar beside the first quoted line")
}
// The bar's outermost columns, where rounded ends would leave a notch,
// are red all the way from the middle of one line to the next.
for _, x := range []int{first, last} {
for y := row; y < int((two.Top+two.Height/2)*s); y++ {
if !isRed(x, y) {
t.Fatalf("the bar has a notch at x %d, y %d (DIP %v), between the paragraphs at %v and %v", x, y, float32(y)/s, one.Top, two.Top)
}
}
}
// Its ends stay round: the corner pixel at the top of the quotation is
// not filled.
top := row
for top > 0 && isRed((first+last)/2, top-1) {
top--
}
if isRed(first, top) {
t.Error("the quotation's first bar is square at its top end")
}
}