Files
openchamber-android-native/third_party/mygo/internal/text/pretty_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

63 lines
2.3 KiB
Go

package text
import "testing"
// TestPretty gives a paragraph's last line a word from the line before
// rather than one alone, as narrow as that leaves it, keeping the lines
// before as they are; leaves a last line of words, a paragraph whose line
// before has no word to spare, and one MaxLines cuts as they wrap.
func TestPretty(t *testing.T) {
s := breakSystem(0)
s.UsePretty()
p := Params{Text: "aaa bbb ccc ddd eee fff ggg hhh i", Style: Style{Size: 10}, Width: 160}
if l := s.Layout(p); len(l.Lines) != 3 || lineText(l, 2) != "i" {
t.Fatalf("not pretty, %d lines, the last %q", len(l.Lines), lineText(l, len(l.Lines)-1))
}
p.Pretty = true
l := s.Layout(p)
if len(l.Lines) != 3 || lineText(l, 0) != "aaa bbb ccc ddd " || lineText(l, 1) != "eee fff ggg " || lineText(l, 2) != "hhh i" {
t.Fatalf("pretty: %q", texts(l))
}
// Laid out once, and kept.
made := s.LayoutsMade()
if s.Layout(p) != l || s.LayoutsMade() != made {
t.Error("the pretty layout was made again")
}
// Each paragraph on its own, after a newline too.
p.Text = "aaa bbb ccc ddd e\naaa bbb ccc ddd eee ff"
if l := s.Layout(p); len(l.Lines) != 4 || lineText(l, 0) != "aaa bbb ccc " || lineText(l, 1) != "ddd e" || lineText(l, 3) != "eee ff" {
t.Errorf("two paragraphs: %q", texts(l))
}
// A two-line paragraph, the first indented.
p = Params{Text: "aaa bbb ccc ddd e", Style: Style{Size: 10}, Width: 160, Indent: 10, Pretty: true}
if l := s.Layout(p); len(l.Lines) != 2 || lineText(l, 1) != "ddd e" {
t.Errorf("indented: %q", texts(l))
}
for _, tc := range []struct {
name string
p Params
last string
}{
{"a last line of words", Params{Text: "aaa bbb ccc ddd ee ff", Width: 160}, "ee ff"},
{"no word to spare", Params{Text: "aaaaaaaaaaaaaaaa b", Width: 160}, "b"},
{"one line", Params{Text: "aaa b", Width: 160}, "aaa b"},
} {
tc.p.Style, tc.p.Pretty = Style{Size: 10}, true
if l := s.Layout(tc.p); lineText(l, len(l.Lines)-1) != tc.last {
t.Errorf("%s: %q", tc.name, texts(l))
}
}
p = Params{Text: "aaa bbb ccc ddd e", Style: Style{Size: 10}, Width: 160, MaxLines: 1, Pretty: true}
if l := s.Layout(p); len(l.Lines) != 1 || !l.Truncated {
t.Errorf("cut to a line: %q", texts(l))
}
}
func texts(l *Layout) []string {
var out []string
for i := range l.Lines {
out = append(out, lineText(l, i))
}
return out
}