Let locations be ranges, not just specific indexes.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::syntax::ast::{ConstantType, Expression, Program, Statement, Value};
|
||||
use crate::syntax::ast::{ConstantType, Expression, Name, Program, Statement, Value};
|
||||
use crate::syntax::location::Location;
|
||||
use proptest::sample::select;
|
||||
use proptest::{
|
||||
@@ -10,15 +10,12 @@ use std::collections::HashMap;
|
||||
const VALID_VARIABLE_NAMES: &str = r"[a-z][a-zA-Z0-9_]*";
|
||||
const OPERATORS: &[(&str, usize)] = &[("+", 2), ("-", 1), ("-", 2), ("*", 2), ("/", 2)];
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Name(String);
|
||||
|
||||
impl Arbitrary for Name {
|
||||
type Parameters = ();
|
||||
type Strategy = BoxedStrategy<Self>;
|
||||
|
||||
fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
|
||||
VALID_VARIABLE_NAMES.prop_map(Name).boxed()
|
||||
VALID_VARIABLE_NAMES.prop_map(Name::manufactured).boxed()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,12 +64,12 @@ impl Arbitrary for Program {
|
||||
output_type: Some(psi.binding_type),
|
||||
});
|
||||
|
||||
defined_variables.insert(psi.name.0.clone(), psi.binding_type);
|
||||
defined_variables.insert(psi.name.name.clone(), psi.binding_type);
|
||||
statements.push(
|
||||
expr.prop_map(move |expr| {
|
||||
Statement::Binding(
|
||||
Location::manufactured(),
|
||||
psi.name.0.clone(),
|
||||
psi.name.clone(),
|
||||
expr,
|
||||
)
|
||||
})
|
||||
@@ -81,7 +78,7 @@ impl Arbitrary for Program {
|
||||
} else {
|
||||
let printers = defined_variables
|
||||
.keys()
|
||||
.map(|n| Just(Statement::Print(Location::manufactured(), n.clone())));
|
||||
.map(|n| Just(Statement::Print(Location::manufactured(), Name::manufactured(n))));
|
||||
statements.push(Union::new(printers).boxed());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user