#+test package main import "core:strings" import "core:sync" import "core:testing" import "treesitter" // The treesitter parser store is normally initialized by main() via // treesitter.init_persistent(); the test runner never calls main. init_once // ensures it happens exactly once no matter which test thread arrives first, // and preloads the builtin parsers on that single thread — after which the // concurrent tests only *read* the cache (the unlocked writes in ensure_parser // are what corrupt it, not reads). @(private = "file") init_once: sync.Once setup_treesitter :: proc() { sync.once_do(&init_once, proc() { treesitter.init_persistent() treesitter.ensure_parser("html") treesitter.ensure_parser("css") }) } // The builtin parsers are cached and shared per-language, and tree-sitter // parsers are not reentrant — concurrent parser_parse_string corrupts their // internal subtree pool. The multi-threaded test runner would otherwise race, // so serialize parser use behind this mutex. (Production renders on a single // thread, so it needs no such lock.) @(private = "file") parse_mu: sync.Mutex ts_minify_html :: proc(s: string) -> string { sync.mutex_lock(&parse_mu) defer sync.mutex_unlock(&parse_mu) return minify_html(s) } ts_minify_css :: proc(s: string) -> string { sync.mutex_lock(&parse_mu) defer sync.mutex_unlock(&parse_mu) return minify_css(s) } // --- minify_html: inline
hi