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.
71 lines
2.0 KiB
Go
71 lines
2.0 KiB
Go
package markdown
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
)
|
|
|
|
func TestViewCodeLink(t *testing.T) {
|
|
files := map[string]string{"src/app.go:12": "file:src/app.go#L12"}
|
|
var opened []string
|
|
o := &Options{
|
|
CodeLink: func(code string) (string, bool) { d, ok := files[code]; return d, ok },
|
|
OnLink: func(url string) { opened = append(opened, url) },
|
|
}
|
|
src := "See `src/app.go:12` and `go test`, and @octocat."
|
|
tt := ui.NewTester(func(c *ui.Context) { View(c, src, o) }, 600, 400)
|
|
if err := tt.Click("src/app.go:12"); err != nil {
|
|
t.Fatalf("%v in %q", err, tt.Texts())
|
|
}
|
|
if !slices.Equal(opened, []string{"file:src/app.go#L12"}) {
|
|
t.Errorf("opened %q", opened)
|
|
}
|
|
// Code it doesn't know, and mentions without Resolve, stay text.
|
|
for _, s := range []string{"go test", "@octocat"} {
|
|
if err := tt.Click(s); err == nil {
|
|
t.Errorf("%s is a link", s)
|
|
}
|
|
}
|
|
// It's asked again as the view builds: code it learns of links.
|
|
files["go test"] = "cmd:go-test"
|
|
tt.Frame()
|
|
if err := tt.Click("go test"); err != nil || opened[len(opened)-1] != "cmd:go-test" {
|
|
t.Errorf("go test once known: %v, opened %q", err, opened)
|
|
}
|
|
// Cleared, it's all text again, as one run.
|
|
o.CodeLink = nil
|
|
tt.Frame()
|
|
if err := tt.Click("src/app.go:12"); err == nil {
|
|
t.Error("still a link once CodeLink is cleared")
|
|
}
|
|
if !tt.HasText("See src/app.go:12 and go test, and @octocat.") {
|
|
t.Errorf("text %q", tt.Texts())
|
|
}
|
|
}
|
|
|
|
func TestViewCodeLinkStreaming(t *testing.T) {
|
|
asked := 0
|
|
o := &Options{Reveal: &Reveal{Unit: AtOnce, Fade: -1}, CodeLink: func(code string) (string, bool) {
|
|
asked++
|
|
return "file:" + code, strings.Contains(code, "/")
|
|
}}
|
|
var src string
|
|
tt := ui.NewTester(func(c *ui.Context) { Stream(c, src, o) }, 600, 400)
|
|
for _, part := range []string{"Open `a/b", ".go` now", " and `c/d.go`."} {
|
|
src += part
|
|
tt.Frame()
|
|
}
|
|
if err := tt.Click("c/d.go"); err != nil {
|
|
t.Fatalf("%v in %q", err, tt.Texts())
|
|
}
|
|
if err := tt.Click("a/b.go"); err != nil {
|
|
t.Fatalf("%v in %q", err, tt.Texts())
|
|
}
|
|
if asked == 0 {
|
|
t.Error("never asked")
|
|
}
|
|
}
|