use super::*;
#[test]
fn test20086_results_are_shown_where_they_are() {
use sha2::{Digest, Sha256};
let dir = tempfile::tempdir().expect("a directory");
let text = "from util import helper\nhelper(1)\n";
std::fs::write(dir.path().join("app.py"), text).expect("a file");
let hash = format!("sha256:{:x}", Sha256::digest(text.as_bytes()));
let span = |start: usize| serde_json::json!({ "path": "app.py", "content_hash": hash, "range_utf8": [start, start + 6] });
let reference = serde_json::json!({ "item": "reference", "span": span(24), "role": "reference" });
assert_eq!(line(dir.path(), "wsb", &reference), "wsb/app.py:2:1 reference");
let symbol = serde_json::json!({
"item": "symbol", "kind": "function", "path": "util.helper", "signature": "def helper(x)", "location": span(17)
});
assert_eq!(line(dir.path(), ".", &symbol), "app.py:1:18 function util.helper def helper(x)");
let node = serde_json::json!({ "item": "node", "symbol": symbol, "depth": 2, "category": "possible" });
assert_eq!(line(dir.path(), ".", &node), "app.py:1:18 function util.helper def helper(x) (depth 2, possible)");
let diagnostic = serde_json::json!({
"primary": span(0), "severity": "error", "code": "missing_token", "message": "missing `)`", "source": "omni-python"
});
assert_eq!(line(dir.path(), ".", &diagnostic), "app.py:1:1 error missing_token: missing `)` [omni-python]");
std::fs::write(dir.path().join("app.py"), format!("# an edit above\n{text}")).expect("a change");
assert_eq!(line(dir.path(), ".", &reference), "app.py@24 (changed since it was analyzed) reference");
let unknown = serde_json::json!({ "item": "bridge", "x": 1 });
let shown = line(dir.path(), "wsb", &unknown);
assert!(shown.contains("does not know how to show") && shown.contains("\"bridge\""), "{shown}");
}