use pkl_parser::parse;
use regex::Regex;
use select::{document::Document, predicate::Name};
#[test]
pub fn lang_ref_code() {
let resp =
reqwest::blocking::get("https://pkl-lang.org/main/current/language-reference/index.html")
.unwrap();
assert!(resp.status().is_success());
let re = Regex::new(r"\(\d\)").unwrap();
let code_parts = Document::from_read(resp)
.unwrap()
.find(Name("code"))
.filter(|n| {
n.attr("class")
.map(|x| !x.contains("expression") && x.contains("language-pkl"))
.unwrap_or(false)
})
.map(|x| re.replace_all(&x.text(), "").to_string())
.collect::<Vec<_>>();
assert!(!code_parts.is_empty());
let code = code_parts.join("\n");
let parsed = parse(&code);
assert!(parsed.is_ok());
}