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

93 lines
3.2 KiB
Go

//go:build windows && (amd64 || arm64)
package text
import (
"strings"
"testing"
)
// Numbers put together are what DirectWrite shapes, in the system's fonts.
func TestDWriteNumbers(t *testing.T) {
numbers := []string{"0", "7", "11", "1,234,567.89", "-42.5%", "+3.14", "$1,000", "1.1.1.1", "$-0.50", "%%", "--", "..", "1+1-1", "00000000000000000000000000000000", "12.345", "98765.4321"}
styles := []Style{{Size: 11}, {Size: 13}, {Size: 13, Weight: 700}, {Size: 14, Italic: true}, {Size: 14, Family: "Consolas"}, {Size: 16, Family: "Arial"}, {Size: 15, Family: "Georgia"}, {Size: 13, Family: "Times New Roman"}, {Size: 13, Lang: "zh-Hans"}, {Size: 13, Lang: "en"}}
s := newSystem()
s.mu.Lock()
defer s.mu.Unlock()
e := s.engine().(*dwrite)
for _, style := range styles {
for _, number := range numbers {
text := []rune(number)
e.resetScratch()
lines := e.shapeNumber(text, style, nil, 0, false)
if lines == nil {
t.Fatalf("%q in %+v was not put together", number, style)
}
if !sameNumber(lines, e.shapeText(text, style, nil, 0, false, false)) {
t.Errorf("%q in %+v put together is not what DirectWrite shapes", number, style)
}
}
}
for _, f := range e.numbers {
if f.disagreed {
t.Error("a font disagreed with DirectWrite")
}
}
}
// What is not a number, wraps, or takes more than its characters' glyphs is
// left to DirectWrite, and a font it disagrees with stays with it.
func TestDWriteNumbersLeftOut(t *testing.T) {
s := newSystem()
s.mu.Lock()
defer s.mu.Unlock()
e := s.engine().(*dwrite)
style := Style{Size: 13}
for _, c := range []struct {
text string
style Style
spans []Span
width float32
rtl bool
}{
{text: "12a", style: style},
{text: "12:30", style: style},
{text: "١٢٣", style: style},
{text: "123", style: style, rtl: true},
{text: "123", style: style, spans: []Span{{End: 1, Weight: 700}}},
{text: "123", style: Style{Size: 13, LetterSpacing: 1}},
{text: "123", style: Style{Size: 13, Features: "tnum"}},
{text: "123", style: Style{Size: 13, Lang: "tr"}},
{text: "123456", style: style, width: 5},
{text: strings.Repeat("1", maxNumber+1), style: style},
} {
e.resetScratch()
if e.shapeNumber([]rune(c.text), c.style, c.spans, c.width, c.rtl) != nil {
t.Errorf("%q in %+v (width %v, RTL %v) was put together", c.text, c.style, c.width, c.rtl)
}
}
text := []rune("42")
e.resetScratch()
want := e.shapeText(text, style, nil, 0, false, false)
wantX := want[0].runs[0].glyphs[1].X
if e.shapeNumber(text, style, nil, 0, false) == nil {
t.Fatal("42 was not put together")
}
family, custom := e.family(style.Family)
f := e.numbers[formatKey{style.Family, family, custom, style.weight(), style.Italic, style.FontSize(), style.Lang}]
f.pairs[numberSlots['4']-1][numberSlots['2']-1].advance += 5
e.resetScratch()
got := e.shapeNumber(text, style, nil, 0, false)
if !f.disagreed {
t.Error("a number wrong by 5 did not count as a disagreement")
}
if x := got[0].runs[0].glyphs[1].X; x != wantX {
t.Errorf("the second digit of a number that disagrees is at %v, DirectWrite puts it at %v", x, wantX)
}
e.resetScratch()
if e.shapeNumber(text, style, nil, 0, false) != nil {
t.Error("a font that disagreed still has numbers put together")
}
}