core/app/app_test.go
core/app/app_test.goBrowse 1970 files
571 tokens
2,243 bytes
Token encoding: o200k_base
Snapshot 21a254f
← Back to SKILL.md
1package app2 3import (4 "path/filepath"5 "regexp"6 "testing"7 8 "github.com/stretchr/testify/require"9)10 11// TestPackageJSON represents the package.json structure for testing12type PackageJSON struct {13 Name string `json:"name"`14 Engines struct {15 Node string `json:"node"`16 } `json:"engines"`17 Scripts struct {18 PostStart string19 PreStart string20 Start string21 }22 Dependencies map[string]string `json:"dependencies"`23 DevDependencies map[string]string `json:"devDependencies"`24 25 AllScripts map[string]string `json:"scripts"`26}27 28func TestApp(t *testing.T) {29 app, err := NewApp("../../examples/node-bun")30 require.NoError(t, err)31 32 content, err := app.ReadFile("package.json")33 require.NoError(t, err)34 require.Contains(t, content, "node-bun")35 36 var packageJSON PackageJSON37 err = app.ReadJSON("package.json", &packageJSON)38 require.NoError(t, err)39 require.Equal(t, packageJSON.Name, "node-bun")40 41 files, err := app.FindFiles("*.ts")42 require.NoError(t, err)43 require.Equal(t, len(files), 1)44 require.Equal(t, files[0], "index.ts")45}46 47func TestAppAbsolutePath(t *testing.T) {48 relPath := "../../examples/node-bun"49 absPath, err := filepath.Abs(relPath)50 require.NoError(t, err)51 52 app, err := NewApp(absPath)53 require.NoError(t, err)54 55 require.Equal(t, app.Source, absPath)56}57 58func TestAppReadJsonWithComments(t *testing.T) {59 app, err := NewApp("../../examples/config-file")60 require.NoError(t, err)61 62 var config map[string]any63 err = app.ReadJSON("hello.jsonc", &config)64 require.NoError(t, err)65 require.Equal(t, config["hello"], "world")66}67 68func TestFindFilesWithContent(t *testing.T) {69 app, err := NewApp("../../examples/node-bun")70 require.NoError(t, err)71 72 // Test finding files containing "process.stdout.write"73 regex := regexp.MustCompile(`process\.stdout\.write`)74 matches := app.FindFilesWithContent("*.ts", regex)75 require.Equal(t, len(matches), 1)76 require.Equal(t, matches[0], "index.ts")77 78 // Test finding files with non-existent pattern79 regex = regexp.MustCompile(`nonexistent`)80 matches = app.FindFilesWithContent("*.ts", regex)81 require.Empty(t, matches)82 83 // Test with invalid glob pattern84 regex = regexp.MustCompile(`test`)85 matches = app.FindFilesWithContent("[invalid", regex)86 require.Empty(t, matches)87}88