2026-05-30 14:21:43 +08:00
|
|
|
package js
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"apigo.cc/go/jsmod"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestDocGeneration(t *testing.T) {
|
|
|
|
|
jsmod.Register("db", map[string]any{
|
|
|
|
|
"query": func(ctx context.Context, sql string, args []any) ([]map[string]any, error) {
|
|
|
|
|
return nil, nil
|
|
|
|
|
},
|
2026-06-08 20:47:30 +08:00
|
|
|
"version": "1.0.0",
|
2026-06-05 19:05:20 +08:00
|
|
|
"__exportInternal": func() *struct{ Name string } { return nil },
|
2026-05-30 14:21:43 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
doc := Doc()
|
|
|
|
|
fmt.Println(doc)
|
|
|
|
|
|
2026-06-05 19:05:20 +08:00
|
|
|
if !strings.Contains(doc, "interface GoTime") {
|
|
|
|
|
t.Error("doc should contain GoTime interface")
|
2026-05-30 14:21:43 +08:00
|
|
|
}
|
2026-06-05 19:05:20 +08:00
|
|
|
if !strings.Contains(doc, "interface Db_Module") {
|
|
|
|
|
t.Error("doc should contain Db_Module interface")
|
2026-05-30 14:21:43 +08:00
|
|
|
}
|
2026-06-05 19:05:20 +08:00
|
|
|
if !strings.Contains(doc, "declare const go:") {
|
|
|
|
|
t.Error("doc should contain global go declaration")
|
|
|
|
|
}
|
|
|
|
|
if strings.Contains(doc, "__exportInternal") {
|
|
|
|
|
t.Error("doc should NOT contain __exportInternal")
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(doc, "interface Db_") {
|
|
|
|
|
t.Error("doc should contain supporting interface for internal struct")
|
2026-05-30 14:21:43 +08:00
|
|
|
}
|
|
|
|
|
}
|