use blade_syntax::parse;
use proptest::prelude::*;
const FRAGMENTS: &[&str] = &[
"{{",
"}}",
"{!!",
"!!}",
"{{--",
"--}}",
"@if",
"@endif",
"@foreach",
"@else",
"@verbatim",
"@endverbatim",
"@php",
"@endphp",
"(",
")",
"'",
"\"",
"\\",
"@",
"@@",
"<?php",
"?>",
" ",
"\r\n",
"é",
"👋",
"x",
"@section",
"('a')",
"@show",
"@empty",
"@forelse",
"@endforelse",
"@disk",
"@enddisk",
"@elsedisk",
"\t",
"<",
">",
"</",
"/>",
"<div",
"</div>",
"<script>",
"</script>",
"<!--",
"-->",
"=",
"class=\"",
"@click",
"<x-a",
":b=\"",
];
fn blade_like() -> impl Strategy<Value = String> {
prop::collection::vec(prop::sample::select(FRAGMENTS), 0..40).prop_map(|parts| parts.concat())
}
proptest! {
#![proptest_config(ProptestConfig::with_cases(2000))]
#[test]
fn parse_is_lossless_and_never_panics(s in blade_like()) {
prop_assert_eq!(parse(&s).syntax().to_string(), s);
}
#[test]
fn any_string_round_trips(s in any::<String>()) {
prop_assert_eq!(parse(&s).syntax().to_string(), s);
}
#[test]
fn error_ranges_are_inside_the_input(s in blade_like()) {
let p = parse(&s);
for e in p.errors() {
prop_assert!(usize::from(e.range.end()) <= s.len());
prop_assert!(s.is_char_boundary(usize::from(e.range.start())));
}
}
}