mirror of
https://github.com/lukaszraczylo/filepuff-mcp.git
synced 2026-10-12 04:54:27 +00:00
skeletonPythonNode took lines[0] of a decorated_definition, which is the first @decorator line, dropping the def/class signature entirely. Now emit the decorator line(s) then recurse into the wrapped definition so its signature is preserved. Adds skeleton_test.go (decorated + plain function).
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package parser
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A decorated Python function must keep BOTH its decorator(s) and its def
|
|
// signature in the skeleton — previously only the first decorator survived and
|
|
// the signature was dropped.
|
|
func TestSkeletonPythonDecoratedFunction(t *testing.T) {
|
|
r := NewRegistry()
|
|
defer r.Close()
|
|
|
|
src := "@app.route(\"/\")\n" +
|
|
"def home():\n" +
|
|
" return \"hi\"\n"
|
|
|
|
out, _, err := SkeletonFile(context.Background(), r, "app.py", []byte(src))
|
|
if err != nil {
|
|
t.Fatalf("SkeletonFile error: %v", err)
|
|
}
|
|
if !strings.Contains(out, "@app.route(\"/\")") {
|
|
t.Errorf("skeleton lost decorator, got:\n%s", out)
|
|
}
|
|
if !strings.Contains(out, "def home():") {
|
|
t.Errorf("skeleton lost def signature, got:\n%s", out)
|
|
}
|
|
if strings.Contains(out, "return \"hi\"") {
|
|
t.Errorf("skeleton should elide the body, got:\n%s", out)
|
|
}
|
|
}
|
|
|
|
// A plain (undecorated) Python function still renders its signature + body stub.
|
|
func TestSkeletonPythonPlainFunction(t *testing.T) {
|
|
r := NewRegistry()
|
|
defer r.Close()
|
|
|
|
src := "def add(a, b):\n return a + b\n"
|
|
out, _, err := SkeletonFile(context.Background(), r, "m.py", []byte(src))
|
|
if err != nil {
|
|
t.Fatalf("SkeletonFile error: %v", err)
|
|
}
|
|
if !strings.Contains(out, "def add(a, b):") {
|
|
t.Errorf("skeleton lost signature, got:\n%s", out)
|
|
}
|
|
}
|