Merge pull request #353 from aiken-lang/rvcas/assert_expect
Rename assert to expect
This commit is contained in:
commit
37bd22a0d2
|
@ -801,7 +801,7 @@ impl<A, B> Pattern<A, B> {
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
|
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
|
||||||
pub enum AssignmentKind {
|
pub enum AssignmentKind {
|
||||||
Let,
|
Let,
|
||||||
Assert,
|
Expect,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AssignmentKind {
|
impl AssignmentKind {
|
||||||
|
@ -809,8 +809,15 @@ impl AssignmentKind {
|
||||||
matches!(self, AssignmentKind::Let)
|
matches!(self, AssignmentKind::Let)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_assert(&self) -> bool {
|
pub fn is_expect(&self) -> bool {
|
||||||
matches!(self, AssignmentKind::Assert)
|
matches!(self, AssignmentKind::Expect)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn location_offset(&self) -> usize {
|
||||||
|
match self {
|
||||||
|
AssignmentKind::Let => 3,
|
||||||
|
AssignmentKind::Expect => 6,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -606,7 +606,7 @@ impl<'comments> Formatter<'comments> {
|
||||||
|
|
||||||
let keyword = match kind {
|
let keyword = match kind {
|
||||||
Some(AssignmentKind::Let) => "let ",
|
Some(AssignmentKind::Let) => "let ",
|
||||||
Some(AssignmentKind::Assert) => "assert ",
|
Some(AssignmentKind::Expect) => "expect ",
|
||||||
None => "try ",
|
None => "try ",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1028,7 +1028,7 @@ pub fn expr_parser(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let assert_parser = just(Token::Assert)
|
let expect_parser = just(Token::Expect)
|
||||||
.ignore_then(pattern_parser())
|
.ignore_then(pattern_parser())
|
||||||
.then(just(Token::Colon).ignore_then(type_parser()).or_not())
|
.then(just(Token::Colon).ignore_then(type_parser()).or_not())
|
||||||
.then_ignore(just(Token::Equal))
|
.then_ignore(just(Token::Equal))
|
||||||
|
@ -1038,7 +1038,7 @@ pub fn expr_parser(
|
||||||
location: span,
|
location: span,
|
||||||
value: Box::new(value),
|
value: Box::new(value),
|
||||||
pattern,
|
pattern,
|
||||||
kind: ast::AssignmentKind::Assert,
|
kind: ast::AssignmentKind::Expect,
|
||||||
annotation,
|
annotation,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -1093,7 +1093,7 @@ pub fn expr_parser(
|
||||||
block_parser,
|
block_parser,
|
||||||
when_parser,
|
when_parser,
|
||||||
let_parser,
|
let_parser,
|
||||||
assert_parser,
|
expect_parser,
|
||||||
if_parser,
|
if_parser,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,8 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> {
|
||||||
"trace" => Token::Trace,
|
"trace" => Token::Trace,
|
||||||
"error" => Token::ErrorTerm,
|
"error" => Token::ErrorTerm,
|
||||||
"as" => Token::As,
|
"as" => Token::As,
|
||||||
"assert" => Token::Assert,
|
"assert" => Token::Expect,
|
||||||
|
"expect" => Token::Expect,
|
||||||
"const" => Token::Const,
|
"const" => Token::Const,
|
||||||
"fn" => Token::Fn,
|
"fn" => Token::Fn,
|
||||||
"test" => Token::Test,
|
"test" => Token::Test,
|
||||||
|
|
|
@ -60,11 +60,12 @@ pub enum Token {
|
||||||
NewLine,
|
NewLine,
|
||||||
// Keywords (alphabetically):
|
// Keywords (alphabetically):
|
||||||
As,
|
As,
|
||||||
Assert,
|
|
||||||
Const,
|
Const,
|
||||||
Fn,
|
Fn,
|
||||||
If,
|
If,
|
||||||
Else,
|
Else,
|
||||||
|
ErrorTerm,
|
||||||
|
Expect,
|
||||||
Is,
|
Is,
|
||||||
Let,
|
Let,
|
||||||
Opaque,
|
Opaque,
|
||||||
|
@ -75,7 +76,6 @@ pub enum Token {
|
||||||
Type,
|
Type,
|
||||||
When,
|
When,
|
||||||
Trace,
|
Trace,
|
||||||
ErrorTerm,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Token {
|
impl fmt::Display for Token {
|
||||||
|
@ -140,7 +140,7 @@ impl fmt::Display for Token {
|
||||||
Token::EmptyLine => "EMPTYLINE",
|
Token::EmptyLine => "EMPTYLINE",
|
||||||
Token::NewLine => "NEWLINE",
|
Token::NewLine => "NEWLINE",
|
||||||
Token::As => "as",
|
Token::As => "as",
|
||||||
Token::Assert => "assert",
|
Token::Expect => "expect",
|
||||||
Token::When => "when",
|
Token::When => "when",
|
||||||
Token::Is => "is",
|
Token::Is => "is",
|
||||||
Token::Const => "const",
|
Token::Const => "const",
|
||||||
|
|
|
@ -324,6 +324,77 @@ fn empty_function() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn expect() {
|
||||||
|
let code = indoc! {r#"
|
||||||
|
pub fn run() {
|
||||||
|
expect Some(x) = something.field
|
||||||
|
x.other_field
|
||||||
|
}
|
||||||
|
"#};
|
||||||
|
|
||||||
|
assert_definitions(
|
||||||
|
code,
|
||||||
|
vec![ast::UntypedDefinition::Fn(Function {
|
||||||
|
arguments: vec![],
|
||||||
|
body: expr::UntypedExpr::Sequence {
|
||||||
|
location: Span::new((), 19..69),
|
||||||
|
expressions: vec![
|
||||||
|
expr::UntypedExpr::Assignment {
|
||||||
|
location: Span::new((), 19..51),
|
||||||
|
value: expr::UntypedExpr::FieldAccess {
|
||||||
|
location: Span::new((), 36..51),
|
||||||
|
label: "field".to_string(),
|
||||||
|
container: expr::UntypedExpr::Var {
|
||||||
|
location: Span::new((), 36..45),
|
||||||
|
name: "something".to_string(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
pattern: ast::Pattern::Constructor {
|
||||||
|
is_record: false,
|
||||||
|
location: Span::new((), 26..33),
|
||||||
|
name: "Some".to_string(),
|
||||||
|
arguments: vec![ast::CallArg {
|
||||||
|
label: None,
|
||||||
|
location: Span::new((), 31..32),
|
||||||
|
value: ast::Pattern::Var {
|
||||||
|
location: Span::new((), 31..32),
|
||||||
|
name: "x".to_string(),
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
module: None,
|
||||||
|
constructor: (),
|
||||||
|
with_spread: false,
|
||||||
|
tipo: (),
|
||||||
|
},
|
||||||
|
kind: ast::AssignmentKind::Expect,
|
||||||
|
annotation: None,
|
||||||
|
},
|
||||||
|
expr::UntypedExpr::FieldAccess {
|
||||||
|
location: Span::new((), 56..69),
|
||||||
|
label: "other_field".to_string(),
|
||||||
|
container: expr::UntypedExpr::Var {
|
||||||
|
location: Span::new((), 56..57),
|
||||||
|
name: "x".to_string(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
doc: None,
|
||||||
|
|
||||||
|
location: Span::new((), 0..12),
|
||||||
|
name: "run".to_string(),
|
||||||
|
public: true,
|
||||||
|
return_annotation: None,
|
||||||
|
return_type: (),
|
||||||
|
end_position: 70,
|
||||||
|
})],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn plus_binop() {
|
fn plus_binop() {
|
||||||
let code = indoc! {r#"
|
let code = indoc! {r#"
|
||||||
|
|
|
@ -333,7 +333,7 @@ Perhaps, try the following:
|
||||||
#[diagnostic(code("illegal::module_name"))]
|
#[diagnostic(code("illegal::module_name"))]
|
||||||
#[diagnostic(help(r#"You cannot use keywords as part of a module path name. As a quick reminder, here's a list of all the keywords (and thus, of invalid module path names):
|
#[diagnostic(help(r#"You cannot use keywords as part of a module path name. As a quick reminder, here's a list of all the keywords (and thus, of invalid module path names):
|
||||||
|
|
||||||
as, assert, check, const, else, fn, if, is, let, opaque, pub, test, todo, trace, type, use, when"#))]
|
as, expect, check, const, else, fn, if, is, let, opaque, pub, test, todo, trace, type, use, when"#))]
|
||||||
KeywordInModuleName { name: String, keyword: String },
|
KeywordInModuleName { name: String, keyword: String },
|
||||||
|
|
||||||
#[error("I discovered a function which is ending with an assignment.\n")]
|
#[error("I discovered a function which is ending with an assignment.\n")]
|
||||||
|
@ -1076,6 +1076,21 @@ pub enum Warning {
|
||||||
sample: UntypedExpr,
|
sample: UntypedExpr,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
#[error("I found an {} trying to match a type with one constructor", "expect".purple())]
|
||||||
|
#[diagnostic(
|
||||||
|
code("single_constructor_expect"),
|
||||||
|
help("If your type has one constructor, unless you are casting {} {}, you can\nprefer using a {} binding like so...\n\n{}", "FROM".bold(), "Data".purple(), "let".purple(), format_suggestion(sample))
|
||||||
|
)]
|
||||||
|
SingleConstructorExpect {
|
||||||
|
#[label("use let")]
|
||||||
|
location: Span,
|
||||||
|
#[label("only one constructor")]
|
||||||
|
pattern_location: Span,
|
||||||
|
#[label("is not Data")]
|
||||||
|
value_location: Span,
|
||||||
|
sample: UntypedExpr,
|
||||||
|
},
|
||||||
|
|
||||||
#[error("I found a todo left in the code.\n")]
|
#[error("I found a todo left in the code.\n")]
|
||||||
#[diagnostic(help("You probably want to replace that one with real code... eventually."))]
|
#[diagnostic(help("You probably want to replace that one with real code... eventually."))]
|
||||||
#[diagnostic(code("todo"))]
|
#[diagnostic(code("todo"))]
|
||||||
|
|
|
@ -817,15 +817,18 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
|
|
||||||
fn infer_assignment(
|
fn infer_assignment(
|
||||||
&mut self,
|
&mut self,
|
||||||
pattern: UntypedPattern,
|
untyped_pattern: UntypedPattern,
|
||||||
value: UntypedExpr,
|
untyped_value: UntypedExpr,
|
||||||
kind: AssignmentKind,
|
kind: AssignmentKind,
|
||||||
annotation: &Option<Annotation>,
|
annotation: &Option<Annotation>,
|
||||||
location: Span,
|
location: Span,
|
||||||
) -> Result<TypedExpr, Error> {
|
) -> Result<TypedExpr, Error> {
|
||||||
let typed_value = self.in_new_scope(|value_typer| value_typer.infer(value.clone()))?;
|
let typed_value =
|
||||||
|
self.in_new_scope(|value_typer| value_typer.infer(untyped_value.clone()))?;
|
||||||
let mut value_typ = typed_value.tipo();
|
let mut value_typ = typed_value.tipo();
|
||||||
|
|
||||||
|
let value_is_data = value_typ.is_data();
|
||||||
|
|
||||||
// Check that any type annotation is accurate.
|
// Check that any type annotation is accurate.
|
||||||
let pattern = if let Some(ann) = annotation {
|
let pattern = if let Some(ann) = annotation {
|
||||||
let ann_typ = self
|
let ann_typ = self
|
||||||
|
@ -836,25 +839,25 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
ann_typ.clone(),
|
ann_typ.clone(),
|
||||||
value_typ.clone(),
|
value_typ.clone(),
|
||||||
typed_value.type_defining_location(),
|
typed_value.type_defining_location(),
|
||||||
(kind.is_let() && ann_typ.is_data()) || (kind.is_assert() && value_typ.is_data()),
|
(kind.is_let() && ann_typ.is_data()) || (kind.is_expect() && value_is_data),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
value_typ = ann_typ.clone();
|
value_typ = ann_typ.clone();
|
||||||
|
|
||||||
// Ensure the pattern matches the type of the value
|
// Ensure the pattern matches the type of the value
|
||||||
PatternTyper::new(self.environment, &self.hydrator).unify(
|
PatternTyper::new(self.environment, &self.hydrator).unify(
|
||||||
pattern,
|
untyped_pattern.clone(),
|
||||||
value_typ.clone(),
|
value_typ.clone(),
|
||||||
Some(ann_typ),
|
Some(ann_typ),
|
||||||
)?
|
)?
|
||||||
} else {
|
} else {
|
||||||
if value_typ.is_data() && !pattern.is_var() && !pattern.is_discard() {
|
if value_is_data && !untyped_pattern.is_var() && !untyped_pattern.is_discard() {
|
||||||
return Err(Error::CastDataNoAnn {
|
return Err(Error::CastDataNoAnn {
|
||||||
location,
|
location,
|
||||||
value: UntypedExpr::Assignment {
|
value: UntypedExpr::Assignment {
|
||||||
location,
|
location,
|
||||||
value: value.into(),
|
value: untyped_value.into(),
|
||||||
pattern,
|
pattern: untyped_pattern,
|
||||||
kind,
|
kind,
|
||||||
annotation: Some(Annotation::Constructor {
|
annotation: Some(Annotation::Constructor {
|
||||||
location: Span::empty(),
|
location: Span::empty(),
|
||||||
|
@ -868,7 +871,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
|
|
||||||
// Ensure the pattern matches the type of the value
|
// Ensure the pattern matches the type of the value
|
||||||
PatternTyper::new(self.environment, &self.hydrator).unify(
|
PatternTyper::new(self.environment, &self.hydrator).unify(
|
||||||
pattern,
|
untyped_pattern.clone(),
|
||||||
value_typ.clone(),
|
value_typ.clone(),
|
||||||
None,
|
None,
|
||||||
)?
|
)?
|
||||||
|
@ -877,7 +880,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
// We currently only do limited exhaustiveness checking of custom types
|
// We currently only do limited exhaustiveness checking of custom types
|
||||||
// at the top level of patterns.
|
// at the top level of patterns.
|
||||||
// Do not perform exhaustiveness checking if user explicitly used `assert`.
|
// Do not perform exhaustiveness checking if user explicitly used `assert`.
|
||||||
if kind != AssignmentKind::Assert {
|
if kind != AssignmentKind::Expect {
|
||||||
if let Err(unmatched) = self.environment.check_exhaustiveness(
|
if let Err(unmatched) = self.environment.check_exhaustiveness(
|
||||||
vec![pattern.clone()],
|
vec![pattern.clone()],
|
||||||
collapse_links(value_typ.clone()),
|
collapse_links(value_typ.clone()),
|
||||||
|
@ -888,6 +891,33 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
unmatched,
|
unmatched,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} else if !value_is_data
|
||||||
|
&& self
|
||||||
|
.environment
|
||||||
|
.check_exhaustiveness(
|
||||||
|
vec![pattern.clone()],
|
||||||
|
collapse_links(value_typ.clone()),
|
||||||
|
location,
|
||||||
|
)
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
|
self.environment
|
||||||
|
.warnings
|
||||||
|
.push(Warning::SingleConstructorExpect {
|
||||||
|
location: Span {
|
||||||
|
start: location.start,
|
||||||
|
end: kind.location_offset(),
|
||||||
|
},
|
||||||
|
pattern_location: dbg!(untyped_pattern.location()),
|
||||||
|
value_location: dbg!(untyped_value.location()),
|
||||||
|
sample: UntypedExpr::Assignment {
|
||||||
|
location: Span::empty(),
|
||||||
|
value: Box::new(untyped_value),
|
||||||
|
pattern: untyped_pattern,
|
||||||
|
kind: AssignmentKind::Let,
|
||||||
|
annotation: None,
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(TypedExpr::Assignment {
|
Ok(TypedExpr::Assignment {
|
||||||
|
|
|
@ -20,6 +20,8 @@ use super::{
|
||||||
TypeInfo, ValueConstructor, ValueConstructorVariant,
|
TypeInfo, ValueConstructor, ValueConstructorVariant,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const PUB_OFFSET: usize = 3;
|
||||||
|
|
||||||
impl UntypedModule {
|
impl UntypedModule {
|
||||||
pub fn infer(
|
pub fn infer(
|
||||||
mut self,
|
mut self,
|
||||||
|
@ -162,7 +164,7 @@ fn infer_definition(
|
||||||
environment.warnings.push(Warning::PubInValidatorModule {
|
environment.warnings.push(Warning::PubInValidatorModule {
|
||||||
location: Span {
|
location: Span {
|
||||||
start: location.start,
|
start: location.start,
|
||||||
end: location.start + 3,
|
end: location.start + PUB_OFFSET,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -270,7 +272,7 @@ fn infer_definition(
|
||||||
environment.warnings.push(Warning::PubInValidatorModule {
|
environment.warnings.push(Warning::PubInValidatorModule {
|
||||||
location: Span {
|
location: Span {
|
||||||
start: location.start,
|
start: location.start,
|
||||||
end: location.start + 3,
|
end: location.start + PUB_OFFSET,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -306,7 +308,7 @@ fn infer_definition(
|
||||||
environment.warnings.push(Warning::PubInValidatorModule {
|
environment.warnings.push(Warning::PubInValidatorModule {
|
||||||
location: Span {
|
location: Span {
|
||||||
start: location.start,
|
start: location.start,
|
||||||
end: location.start + 3,
|
end: location.start + PUB_OFFSET,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -449,7 +451,7 @@ fn infer_definition(
|
||||||
environment.warnings.push(Warning::PubInValidatorModule {
|
environment.warnings.push(Warning::PubInValidatorModule {
|
||||||
location: Span {
|
location: Span {
|
||||||
start: location.start,
|
start: location.start,
|
||||||
end: location.start + 3,
|
end: location.start + PUB_OFFSET,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -511,8 +513,11 @@ fn validate_module_name(name: &str) -> Result<(), Error> {
|
||||||
fn str_to_keyword(word: &str) -> Option<Token> {
|
fn str_to_keyword(word: &str) -> Option<Token> {
|
||||||
// Alphabetical keywords:
|
// Alphabetical keywords:
|
||||||
match word {
|
match word {
|
||||||
|
"assert" => Some(Token::Expect),
|
||||||
|
"expect" => Some(Token::Expect),
|
||||||
|
"else" => Some(Token::Else),
|
||||||
|
"is" => Some(Token::Is),
|
||||||
"as" => Some(Token::As),
|
"as" => Some(Token::As),
|
||||||
"assert" => Some(Token::Assert),
|
|
||||||
"when" => Some(Token::When),
|
"when" => Some(Token::When),
|
||||||
"const" => Some(Token::Const),
|
"const" => Some(Token::Const),
|
||||||
"fn" => Some(Token::Fn),
|
"fn" => Some(Token::Fn),
|
||||||
|
|
|
@ -1578,7 +1578,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
pattern_vec.append(value_vec);
|
pattern_vec.append(value_vec);
|
||||||
|
|
||||||
if matches!(assignment_properties.kind, AssignmentKind::Assert)
|
if matches!(assignment_properties.kind, AssignmentKind::Expect)
|
||||||
&& assignment_properties.value_type.is_data()
|
&& assignment_properties.value_type.is_data()
|
||||||
&& !tipo.is_data()
|
&& !tipo.is_data()
|
||||||
{
|
{
|
||||||
|
@ -1604,7 +1604,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
pattern_vec.append(value_vec);
|
pattern_vec.append(value_vec);
|
||||||
}
|
}
|
||||||
list @ Pattern::List { .. } => {
|
list @ Pattern::List { .. } => {
|
||||||
if matches!(assignment_properties.kind, AssignmentKind::Assert)
|
if matches!(assignment_properties.kind, AssignmentKind::Expect)
|
||||||
&& assignment_properties.value_type.is_data()
|
&& assignment_properties.value_type.is_data()
|
||||||
&& !tipo.is_data()
|
&& !tipo.is_data()
|
||||||
{
|
{
|
||||||
|
@ -1629,7 +1629,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
// TODO: Check constr for assert on all cases
|
// TODO: Check constr for assert on all cases
|
||||||
constr @ Pattern::Constructor { .. } => {
|
constr @ Pattern::Constructor { .. } => {
|
||||||
if matches!(assignment_properties.kind, AssignmentKind::Assert)
|
if matches!(assignment_properties.kind, AssignmentKind::Expect)
|
||||||
&& assignment_properties.value_type.is_data()
|
&& assignment_properties.value_type.is_data()
|
||||||
&& !tipo.is_data()
|
&& !tipo.is_data()
|
||||||
{
|
{
|
||||||
|
@ -1653,7 +1653,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tuple @ Pattern::Tuple { .. } => {
|
tuple @ Pattern::Tuple { .. } => {
|
||||||
if matches!(assignment_properties.kind, AssignmentKind::Assert)
|
if matches!(assignment_properties.kind, AssignmentKind::Expect)
|
||||||
&& assignment_properties.value_type.is_data()
|
&& assignment_properties.value_type.is_data()
|
||||||
&& !tipo.is_data()
|
&& !tipo.is_data()
|
||||||
{
|
{
|
||||||
|
@ -2503,7 +2503,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let id = self.id_gen.next();
|
let id = self.id_gen.next();
|
||||||
let list_name = format!("__list_{id}");
|
let list_name = format!("__list_{id}");
|
||||||
|
|
||||||
if matches!(assignment_properties.kind, AssignmentKind::Assert)
|
if matches!(assignment_properties.kind, AssignmentKind::Expect)
|
||||||
&& assignment_properties.value_type.is_data()
|
&& assignment_properties.value_type.is_data()
|
||||||
&& !tipo.is_data()
|
&& !tipo.is_data()
|
||||||
{
|
{
|
||||||
|
@ -2556,7 +2556,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let id = self.id_gen.next();
|
let id = self.id_gen.next();
|
||||||
let constr_name = format!("{constr_name}_{id}");
|
let constr_name = format!("{constr_name}_{id}");
|
||||||
|
|
||||||
if matches!(assignment_properties.kind, AssignmentKind::Assert)
|
if matches!(assignment_properties.kind, AssignmentKind::Expect)
|
||||||
&& assignment_properties.value_type.is_data()
|
&& assignment_properties.value_type.is_data()
|
||||||
&& !tipo.is_data()
|
&& !tipo.is_data()
|
||||||
{
|
{
|
||||||
|
@ -2605,7 +2605,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let id = self.id_gen.next();
|
let id = self.id_gen.next();
|
||||||
let tuple_name = format!("__tuple_name_{id}");
|
let tuple_name = format!("__tuple_name_{id}");
|
||||||
|
|
||||||
if matches!(assignment_properties.kind, AssignmentKind::Assert)
|
if matches!(assignment_properties.kind, AssignmentKind::Expect)
|
||||||
&& assignment_properties.value_type.is_data()
|
&& assignment_properties.value_type.is_data()
|
||||||
&& !tipo.is_data()
|
&& !tipo.is_data()
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,17 +5,17 @@ pub fn is_empty(bytes: ByteArray) -> Bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
test is_empty_1() {
|
test is_empty_1() {
|
||||||
is_empty(#[]) == True
|
is_empty(#"") == True
|
||||||
}
|
}
|
||||||
|
|
||||||
test is_empty_1_alt() {
|
test is_empty_1_alt() {
|
||||||
is_empty(#[])
|
is_empty(#"")
|
||||||
}
|
}
|
||||||
|
|
||||||
test is_empty_2() {
|
test is_empty_2() {
|
||||||
is_empty(#[1]) == False
|
is_empty(#"01") == False
|
||||||
}
|
}
|
||||||
|
|
||||||
test is_empty_2_alt() {
|
test is_empty_2_alt() {
|
||||||
!is_empty(#[1])
|
!is_empty(#"01")
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,5 +5,5 @@ pub fn is_empty(bytes: ByteArray) -> Bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
test is_empty_1() {
|
test is_empty_1() {
|
||||||
is_empty(#[]) == True
|
is_empty(#"") == True
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,6 @@ pub fn drop(bytes: ByteArray, n: Int) -> ByteArray {
|
||||||
}
|
}
|
||||||
|
|
||||||
test drop_1() {
|
test drop_1() {
|
||||||
let x = #[1, 2, 3, 4, 5, 6, 7]
|
let x = #"01020304050607"
|
||||||
drop(x, 2) == #[3, 4, 5, 6, 7]
|
drop(x, 2) == #"0304050607"
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,5 +9,5 @@ pub fn take(bytes: ByteArray, n: Int) -> ByteArray {
|
||||||
}
|
}
|
||||||
|
|
||||||
test take_1() {
|
test take_1() {
|
||||||
take(#[1, 2, 3], 2) == #[1, 2]
|
take(#"010203", 2) == #"0102"
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,7 @@ pub fn insert(
|
||||||
AssocList { inner: do_insert(m.inner, k, v) }
|
AssocList { inner: do_insert(m.inner, k, v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_insert(
|
fn do_insert(elems: List<(key, value)>, k: key, v: value) -> List<(key, value)> {
|
||||||
elems: List<(key, value)>,
|
|
||||||
k: key,
|
|
||||||
v: value,
|
|
||||||
) -> List<(key, value)> {
|
|
||||||
when elems is {
|
when elems is {
|
||||||
[] -> [(k, v)]
|
[] -> [(k, v)]
|
||||||
[(k2, v2), ..rest] ->
|
[(k2, v2), ..rest] ->
|
||||||
|
|
|
@ -25,11 +25,7 @@ pub fn insert(
|
||||||
AssocList { inner: do_insert(m.inner, k, v) }
|
AssocList { inner: do_insert(m.inner, k, v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_insert(
|
fn do_insert(elems: List<(key, value)>, k: key, v: value) -> List<(key, value)> {
|
||||||
elems: List<(key, value)>,
|
|
||||||
k: key,
|
|
||||||
v: value,
|
|
||||||
) -> List<(key, value)> {
|
|
||||||
when elems is {
|
when elems is {
|
||||||
[] -> [(k, v)]
|
[] -> [(k, v)]
|
||||||
[(k2, v2), ..rest] ->
|
[(k2, v2), ..rest] ->
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub fn from_asset(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_lovelace(quantity: Int) -> Value {
|
pub fn from_lovelace(quantity: Int) -> Value {
|
||||||
from_asset(#[], #[], quantity)
|
from_asset(#"", #"", quantity)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(left v0: Value, right v1: Value) -> Value {
|
pub fn add(left v0: Value, right v1: Value) -> Value {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use aiken/list
|
||||||
use aiken/transaction.{Output, ScriptContext}
|
use aiken/transaction.{Output, ScriptContext}
|
||||||
use aiken/transaction/value.{PolicyId}
|
use aiken/transaction/value.{PolicyId}
|
||||||
|
|
||||||
const my_policy_id: PolicyId = #[0, 0, 0, 0, 0]
|
const my_policy_id: PolicyId = #"0000000000"
|
||||||
|
|
||||||
pub fn has_policy_id(self: Output, policy_id: PolicyId) -> Bool {
|
pub fn has_policy_id(self: Output, policy_id: PolicyId) -> Bool {
|
||||||
self.value
|
self.value
|
||||||
|
|
|
@ -37,52 +37,52 @@ pub fn update_door_locked_and_wheels(
|
||||||
test update_owner1() {
|
test update_owner1() {
|
||||||
let initial_car =
|
let initial_car =
|
||||||
Car {
|
Car {
|
||||||
owner: #[],
|
owner: #"",
|
||||||
wheels: 4,
|
wheels: 4,
|
||||||
vin: #[1, 1, 1, 1, 1, 1, 1],
|
vin: #"01010101010101",
|
||||||
door: Door { locked: False, hinge_angle: 45 },
|
door: Door { locked: False, hinge_angle: 45 },
|
||||||
}
|
}
|
||||||
let final_car =
|
let final_car =
|
||||||
Car {
|
Car {
|
||||||
owner: #[244, 244, 244, 244],
|
owner: #"f4f4f4f4",
|
||||||
wheels: 4,
|
wheels: 4,
|
||||||
vin: #[1, 1, 1, 1, 1, 1, 1],
|
vin: #"01010101010101",
|
||||||
door: Door { locked: False, hinge_angle: 45 },
|
door: Door { locked: False, hinge_angle: 45 },
|
||||||
}
|
}
|
||||||
update_owner(#[244, 244, 244, 244], initial_car) == final_car
|
update_owner(#"f4f4f4f4", initial_car) == final_car
|
||||||
}
|
}
|
||||||
|
|
||||||
test update_vin1() {
|
test update_vin1() {
|
||||||
let initial_car =
|
let initial_car =
|
||||||
Car {
|
Car {
|
||||||
owner: #[],
|
owner: #"",
|
||||||
wheels: 4,
|
wheels: 4,
|
||||||
vin: #[1, 1, 1, 1, 1, 1, 1],
|
vin: #"01010101010101",
|
||||||
door: Door { locked: False, hinge_angle: 45 },
|
door: Door { locked: False, hinge_angle: 45 },
|
||||||
}
|
}
|
||||||
let final_car =
|
let final_car =
|
||||||
Car {
|
Car {
|
||||||
owner: #[],
|
owner: #"",
|
||||||
wheels: 4,
|
wheels: 4,
|
||||||
vin: #[2, 2, 2, 2, 2, 2, 2, 2, 2],
|
vin: #"020202020202020202",
|
||||||
door: Door { locked: False, hinge_angle: 45 },
|
door: Door { locked: False, hinge_angle: 45 },
|
||||||
}
|
}
|
||||||
update_vin(#[2, 2, 2, 2, 2, 2, 2, 2, 2], initial_car) == final_car
|
update_vin(#"020202020202020202", initial_car) == final_car
|
||||||
}
|
}
|
||||||
|
|
||||||
test update_door_angle1() {
|
test update_door_angle1() {
|
||||||
let initial_car =
|
let initial_car =
|
||||||
Car {
|
Car {
|
||||||
owner: #[],
|
owner: #"",
|
||||||
wheels: 4,
|
wheels: 4,
|
||||||
vin: #[1, 1, 1, 1, 1, 1, 1],
|
vin: #"01010101010101",
|
||||||
door: Door { locked: False, hinge_angle: 45 },
|
door: Door { locked: False, hinge_angle: 45 },
|
||||||
}
|
}
|
||||||
let final_car =
|
let final_car =
|
||||||
Car {
|
Car {
|
||||||
owner: #[],
|
owner: #"",
|
||||||
wheels: 4,
|
wheels: 4,
|
||||||
vin: #[1, 1, 1, 1, 1, 1, 1],
|
vin: #"01010101010101",
|
||||||
door: Door { locked: False, hinge_angle: 90 },
|
door: Door { locked: False, hinge_angle: 90 },
|
||||||
}
|
}
|
||||||
update_door_angle(90, initial_car) == final_car
|
update_door_angle(90, initial_car) == final_car
|
||||||
|
@ -91,16 +91,16 @@ test update_door_angle1() {
|
||||||
test update_door_locked_and_wheels1() {
|
test update_door_locked_and_wheels1() {
|
||||||
let initial_car =
|
let initial_car =
|
||||||
Car {
|
Car {
|
||||||
owner: #[],
|
owner: #"",
|
||||||
wheels: 4,
|
wheels: 4,
|
||||||
vin: #[1, 1, 1, 1, 1, 1, 1],
|
vin: #"01010101010101",
|
||||||
door: Door { locked: False, hinge_angle: 45 },
|
door: Door { locked: False, hinge_angle: 45 },
|
||||||
}
|
}
|
||||||
let final_car =
|
let final_car =
|
||||||
Car {
|
Car {
|
||||||
owner: #[],
|
owner: #"",
|
||||||
wheels: 5,
|
wheels: 5,
|
||||||
vin: #[1, 1, 1, 1, 1, 1, 1],
|
vin: #"01010101010101",
|
||||||
door: Door { locked: True, hinge_angle: 45 },
|
door: Door { locked: True, hinge_angle: 45 },
|
||||||
}
|
}
|
||||||
update_door_locked_and_wheels(True, 5, initial_car) == final_car
|
update_door_locked_and_wheels(True, 5, initial_car) == final_car
|
||||||
|
|
|
@ -28,6 +28,6 @@ test update_owner1() {
|
||||||
builtin.list_data([]),
|
builtin.list_data([]),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
assert Ford { owner, wheels, truck_bed_limit, .. }: Car = initial_car
|
expect Ford { owner, wheels, truck_bed_limit, .. }: Car = initial_car
|
||||||
owner == #"" && wheels == 4 && truck_bed_limit == 10000
|
owner == #"" && wheels == 4 && truck_bed_limit == 10000
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,19 +13,19 @@ test let_1() {
|
||||||
test let_2() {
|
test let_2() {
|
||||||
let x: Data = 1
|
let x: Data = 1
|
||||||
|
|
||||||
assert y: Int = x
|
expect y: Int = x
|
||||||
|
|
||||||
y == 1
|
y == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
test assert_1() {
|
test assert_1() {
|
||||||
assert thing: Thing = builtin.constr_data(0, [builtin.i_data(1)])
|
expect thing: Thing = builtin.constr_data(0, [builtin.i_data(1)])
|
||||||
|
|
||||||
thing.wow == 1
|
thing.wow == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cast_to_thing(x: Data) -> Thing {
|
fn cast_to_thing(x: Data) -> Thing {
|
||||||
assert x: Thing = x
|
expect x: Thing = x
|
||||||
|
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [ -z $1 ]; then
|
||||||
|
echo -e "\033[31mMissing argument: \033[1mACCEPTANCE_TEST\033[0m"
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[1mUsage: \033[0m"
|
||||||
|
echo " run.sh {ACCEPTANCE_TEST}"
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[1mExample: \033[0m"
|
||||||
|
echo " run.sh 034"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
WORKDIR="$(dirname -- "${BASH_SOURCE[0]}")"
|
||||||
|
TARGET="$WORKDIR/$(basename $1)"
|
||||||
|
|
||||||
|
TMP=$(mktemp)
|
||||||
|
RESULT=$(cargo run --quiet -- fmt $TARGET 2>$TMP)
|
||||||
|
|
||||||
|
if [ "$?" -eq "0" ]; then
|
||||||
|
echo "✅ $(basename $TARGET)"
|
||||||
|
else
|
||||||
|
echo "❌ $(basename $TARGET)"
|
||||||
|
cat $TMP
|
||||||
|
exit 1
|
||||||
|
fi
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
find . -regex ".*[0-9]\{3\}" -type d | xargs -P 8 -I {} -- ./fmt {}
|
Loading…
Reference in New Issue