mirror of
https://github.com/lukaszraczylo/filepuff-mcp.git
synced 2026-10-12 04:54:27 +00:00
edit.ValidateLanguage had zero callers (only its own godoc referenced it) — removed. yaml_json.go: contrary to the audit's claim, the file is NOT entirely dead — ParseYAML/ParseJSON are live via the Parse() dispatch (parser.go:198-200) and are kept with their tests. Removed only the genuinely unreachable scaffolding that nothing constructs or calls: the YAMLNode/JSONNode types, WalkYAML, GetYAMLNodeText, GetYAMLNodeLocation, QueryYAML, QueryJSON, ValidateYAML, ValidateJSON, and ToSitterTree, plus their now-orphaned tests. YAML/JSON parsing behavior is unchanged (TestParseYAML/TestParseJSON/TestRegistryParse_YAML_JSON still pass).
203 lines
4.2 KiB
Go
203 lines
4.2 KiB
Go
package parser
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/lukaszraczylo/mcp-filepuff/pkg/protocol"
|
|
)
|
|
|
|
func TestParseYAML(t *testing.T) {
|
|
registry := NewRegistry()
|
|
defer registry.Close()
|
|
|
|
tests := []struct {
|
|
name string
|
|
content string
|
|
shouldError bool
|
|
}{
|
|
{
|
|
name: "valid simple YAML",
|
|
content: `name: test
|
|
version: 1.0.0
|
|
enabled: true`,
|
|
shouldError: false,
|
|
},
|
|
{
|
|
name: "valid nested YAML",
|
|
content: `metadata:
|
|
name: test-app
|
|
namespace: default
|
|
spec:
|
|
replicas: 3
|
|
selector:
|
|
matchLabels:
|
|
app: test`,
|
|
shouldError: false,
|
|
},
|
|
{
|
|
name: "valid list YAML",
|
|
content: `items:
|
|
- name: item1
|
|
value: 100
|
|
- name: item2
|
|
value: 200`,
|
|
shouldError: false,
|
|
},
|
|
{
|
|
name: "invalid YAML - bad syntax",
|
|
content: `name: test\n bad: indent\n wrong: [unclosed`,
|
|
shouldError: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result, err := registry.ParseYAML(context.Background(), "test.yaml", []byte(tt.content))
|
|
|
|
if tt.shouldError {
|
|
if err == nil {
|
|
t.Error("expected error but got none")
|
|
}
|
|
return
|
|
}
|
|
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
return
|
|
}
|
|
|
|
if result == nil {
|
|
t.Error("expected result but got nil")
|
|
return
|
|
}
|
|
|
|
if result.Language != protocol.LangYAML {
|
|
t.Errorf("expected language YAML, got %s", result.Language)
|
|
}
|
|
|
|
if len(result.Errors) > 0 {
|
|
t.Errorf("expected no syntax errors, got %d", len(result.Errors))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseJSON(t *testing.T) {
|
|
registry := NewRegistry()
|
|
defer registry.Close()
|
|
|
|
tests := []struct {
|
|
name string
|
|
content string
|
|
shouldError bool
|
|
}{
|
|
{
|
|
name: "valid simple JSON",
|
|
content: `{"name": "test", "version": "1.0.0", "enabled": true}`,
|
|
shouldError: false,
|
|
},
|
|
{
|
|
name: "valid nested JSON",
|
|
content: `{
|
|
"metadata": {
|
|
"name": "test-app",
|
|
"namespace": "default"
|
|
},
|
|
"spec": {
|
|
"replicas": 3,
|
|
"selector": {
|
|
"matchLabels": {
|
|
"app": "test"
|
|
}
|
|
}
|
|
}
|
|
}`,
|
|
shouldError: false,
|
|
},
|
|
{
|
|
name: "valid array JSON",
|
|
content: `[{"name": "item1", "value": 100}, {"name": "item2", "value": 200}]`,
|
|
shouldError: false,
|
|
},
|
|
{
|
|
name: "invalid JSON - unclosed brace",
|
|
content: `{"name": "test", "value": 100`,
|
|
shouldError: true,
|
|
},
|
|
{
|
|
name: "invalid JSON - trailing comma",
|
|
content: `{"name": "test", "value": 100,}`,
|
|
shouldError: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result, err := registry.ParseJSON(context.Background(), "test.json", []byte(tt.content))
|
|
|
|
if tt.shouldError {
|
|
if err == nil {
|
|
t.Error("expected error but got none")
|
|
}
|
|
return
|
|
}
|
|
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
return
|
|
}
|
|
|
|
if result == nil {
|
|
t.Error("expected result but got nil")
|
|
return
|
|
}
|
|
|
|
if result.Language != protocol.LangJSON {
|
|
t.Errorf("expected language JSON, got %s", result.Language)
|
|
}
|
|
|
|
if len(result.Errors) > 0 {
|
|
t.Errorf("expected no syntax errors, got %d", len(result.Errors))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRegistryParse_YAML_JSON(t *testing.T) {
|
|
registry := NewRegistry()
|
|
defer registry.Close()
|
|
|
|
yamlContent := []byte(`name: test
|
|
version: 1.0.0`)
|
|
|
|
jsonContent := []byte(`{"name": "test", "version": "1.0.0"}`)
|
|
|
|
// Test YAML through main Parse method
|
|
yamlResult, err := registry.Parse(context.Background(), "config.yaml", yamlContent)
|
|
if err != nil {
|
|
t.Errorf("failed to parse YAML: %v", err)
|
|
}
|
|
if yamlResult.Language != protocol.LangYAML {
|
|
t.Errorf("expected YAML language, got %s", yamlResult.Language)
|
|
}
|
|
|
|
// Test JSON through main Parse method
|
|
jsonResult, err := registry.Parse(context.Background(), "config.json", jsonContent)
|
|
if err != nil {
|
|
t.Errorf("failed to parse JSON: %v", err)
|
|
}
|
|
if jsonResult.Language != protocol.LangJSON {
|
|
t.Errorf("expected JSON language, got %s", jsonResult.Language)
|
|
}
|
|
|
|
// Test .yml extension
|
|
ymlResult, err := registry.Parse(context.Background(), "config.yml", yamlContent)
|
|
if err != nil {
|
|
t.Errorf("failed to parse .yml: %v", err)
|
|
}
|
|
if ymlResult.Language != protocol.LangYAML {
|
|
t.Errorf("expected YAML language for .yml extension, got %s", ymlResult.Language)
|
|
}
|
|
}
|