clone

a personal forge on plain git: static pages, stacked-diff reviews, signed local ci, repo sites and releases

main
forge / test / scenarios / code-search-index.sh
code-search-index.sh 2.8K
1# A build writes the default branch's code index, search.json points at it,2# and a query finds the file and line of every line with all its words (or3# its quoted phrase), ignoring case.4. "$(dirname "$0")/../lib.sh"5user dami6repo dami/greet "say hello"7clone dami dami/greet "$T/w/dami"8mkdir -p "$T/w/dami/src"9printf 'one\ntwo\n' >"$T/w/dami/notes.txt"10i=111while [ $i -le 20 ]; do printf 'line %s\n' "$i"; i=$((i + 1)); done >"$T/w/dami/src/main.go"12printf 'func Greet(name string) string {\n\treturn "Hello, " + name\n}\n' >>"$T/w/dami/src/main.go"13printf '# Notes\n\nSee greetHelper here.\n' >"$T/w/dami/README.md"14at "$T/w/dami" commit "first"15push_as dami "$T/w/dami" origin main16build17db=$FORGE_WWW/dami/greet/code.db18exists "$db"19has "$FORGE_WWW/dami/greet/search.json" '"code":"/dami/greet/code.db"'20# The rest of the index is unchanged.21has "$FORGE_WWW/dami/greet/search.json" '"files":"/dami/greet/files/main.txt"'22bench() { node "$T_HOME/test/code-search-bench.ts" "$@"; }23ok bench sql "$db" 'return "hello, "'24eq "$(output)" 'src/main.go:22: return "Hello, " + name'25# Line 22 is in the third chunk of eight lines; markdown links to its source page.26ok bench sql "$db" 'GREETHELPER'27eq "$(output)" 'README.md:3: See greetHelper here.'28ok bench sql "$db" 'nothing like this'29eq "$(output)" ''30# Several words: every one on the same line, in any order, ignoring case.31# Words under 3 characters only filter; a quoted phrase is one literal string.32ok bench sql "$db" 'name GREET'33eq "$(output)" 'src/main.go:21: func Greet(name string) string {'34ok bench sql "$db" 'string func'35eq "$(output)" 'src/main.go:21: func Greet(name string) string {'36ok bench sql "$db" 'func hello'37eq "$(output)" ''38ok bench sql "$db" 'name {'39eq "$(output)" 'src/main.go:21: func Greet(name string) string {'40ok bench sql "$db" '"greet name"'41eq "$(output)" ''42ok bench sql "$db" '"Greet(name" string'43eq "$(output)" 'src/main.go:21: func Greet(name string) string {'44ok bench sql "$db" '"return "hello'45eq "$(output)" 'src/main.go:22: return "Hello, " + name'46ok bench sql "$db" 'go {'47eq "$(output)" ''48# Pages name the worker and sqlite-wasm, and the assets exist.49has "$FORGE_WWW/dami/greet/index.html" 'data-code="/assets/codesearch\.[^"]+\.js" data-sqlite="/assets/sqlite3\.[^"]+\.js" data-wasm="/assets/sqlite3\.[^"]+\.wasm"'50lacks "$FORGE_WWW/index.html" 'data-code='51ls "$FORGE_WWW/assets" >"$T/assets"52has "$T/assets" '^sqlite3\.[0-9A-Za-z_-]{10}\.wasm$'53has "$FORGE_WWW/assets/versions.json" 'sqlite3\.[0-9A-Za-z_-]{10}\.wasm'54# The worker imports the query parser (query.ts) by its shipped, hashed name.55w=$(ls "$FORGE_WWW"/assets/codesearch.*.js)56has "$w" "^import \{ [a-z, ]+ \} from '\./query\.[0-9A-Za-z_-]{10}\.js';$"57exists "$FORGE_WWW/assets/$(sed -n "s|^import .* from '\./\(query\.[^']*\)';\$|\1|p" "$w")"