mirror of
https://github.com/JuliusBrussee/caveman.git
synced 2026-09-14 18:02:35 +08:00
82864c8f4c
Single-commit port of the Caveman 2 tree onto the original repo history (candidate caveman-2@88878a4 applied over main@3098342). No unrelated-history merge; original history untouched. Preserved v1 surfaces: - skills/caveman/SKILL.md byte-for-byte, plus plugin mirror and caveman.skill zip - legacy CI (Node 18/20/22 installer + Python 3.11 suites) alongside engine-ci - cli/install.js compatibility shim forwarding to bin/install.js - .codex/config.toml ships both hooks and codex_hooks for older Codex (#617) - README Trendshift + Skills.sh badges and local star-history asset - v1.10.0-pinned curl installs; benchmarks/tmp-starcharts ignore rules Fixed for public same-repo release: - SECURITY.md vulnerability reporting points at this repository - release-binaries.yml publishes to this repo via job-scoped GITHUB_TOKEN (cross-repo PAT removed); binary-release environment still gates signing - packages/cli/PUBLISHING.md rewritten for packages/ layout and same-repo flow - profile-contract and provider-catalog lanes skip lane-scope gates on initial import so the launch PR can gate on their real validation steps - ANNOUNCEMENT.md network claim corrected: compression is local; requests still go to the provider you configured Caveman 2 stays opt-in: bin-v1.0.0 binaries and @caveman-ai/cli publish separately after this lands and soaks. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BLvb5QniwYjmcawyssQNw9
38 lines
2.3 KiB
Go
38 lines
2.3 KiB
Go
package engine_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/JuliusBrussee/caveman/engine"
|
|
)
|
|
|
|
func TestDetect(t *testing.T) {
|
|
e := engine.New(nil, nil)
|
|
cases := []struct {
|
|
name string
|
|
in string
|
|
want string
|
|
}{
|
|
{"json object", `{"a":1,"b":[1,2,3]}`, engine.TypeJSON},
|
|
{"json array", `[1,2,3,4]`, engine.TypeJSON},
|
|
{"diff", "diff --git a/a.go b/a.go\n--- a/a.go\n+++ b/a.go\n@@ -1,5 +1,5 @@\n context\n-old\n+new\n context\n", engine.TypeDiff},
|
|
{"go code", "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"hi\")\n}\n", engine.TypeCode},
|
|
{"python code", "import os\n\ndef run(x):\n return x + 1\n\nclass A:\n def m(self):\n return 2\n", engine.TypeCode},
|
|
{"log", "2026-01-01T00:00:00Z [INFO] start\n[INFO] step\n[WARN] slow\n[ERROR] boom\n[INFO] end\n", engine.TypeLog},
|
|
{"search results", "src/a.go:10:match\nsrc/b.go:11:match\nsrc/c.go:12:match\nsrc/d.go:13:match\nsrc/e.go:14:match\nsrc/f.go:15:match\n", engine.TypeSearchResult},
|
|
{"csv table", "name,region,revenue,status\nalpha,eu,120,ok\nbravo,us,140,ok\ncharlie,apac,90,ok\ndelta,eu,180,ok\necho,us,160,ok\nfoxtrot,apac,110,ok\ngolf,eu,200,ok\nhotel,us,170,ok\nindia,apac,130,ok\n", engine.TypeTabular},
|
|
{"markdown table", "| name | region | revenue |\n| --- | --- | ---: |\n| alpha | eu | 120 |\n| bravo | us | 140 |\n| charlie | apac | 90 |\n| delta | eu | 180 |\n| echo | us | 160 |\n| foxtrot | apac | 110 |\n", engine.TypeTabular},
|
|
{"yaml config", "service:\n name: api\n port: 8080\n database:\n host: db.internal\n port: 5432\n pool: 20\n cache:\n host: cache.internal\n ttl: 300\n limits:\n requests: 1000\n burst: 50\n telemetry:\n enabled: true\n endpoint: http://otel.internal\n", engine.TypeConfig},
|
|
{"toml config", "[service]\nname = \"api\"\nport = 8080\n[database]\nhost = \"db.internal\"\nport = 5432\npool = 20\n[cache]\nhost = \"cache.internal\"\nttl = 300\n[limits]\nrequests = 1000\nburst = 50\n[telemetry]\nenabled = true\nendpoint = \"http://otel.internal\"\n", engine.TypeConfig},
|
|
{"prose", "The quick brown fox jumps over the lazy dog. Nothing structured here at all.", engine.TypeText},
|
|
{"empty", "", engine.TypeText},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
if got := e.Detect([]byte(c.in)); got != c.want {
|
|
t.Errorf("Detect(%q) = %q, want %q", c.name, got, c.want)
|
|
}
|
|
})
|
|
}
|
|
}
|