Support declaring bytearray literals as base16 strings.

This commit is contained in:
KtorZ
2022-12-29 13:08:58 +01:00
parent 6f8d1698fe
commit 3139c85fe8
5 changed files with 94 additions and 2 deletions

View File

@@ -3,7 +3,7 @@ use indoc::indoc;
use pretty_assertions::assert_eq;
use crate::{
ast::{self, DataType, Function, Span, TypeAlias, Use},
ast::{self, Constant, DataType, Function, ModuleConstant, Span, TypeAlias, Use},
expr, parser,
};
@@ -1542,3 +1542,49 @@ fn parse_tuple() {
}),
)
}
#[test]
fn plain_bytearray_literals() {
let code = indoc! {r#"
pub const my_policy_id = #[0, 170, 255]
"#};
assert_definition(
code,
ast::UntypedDefinition::ModuleConstant(ModuleConstant {
doc: None,
location: Span::new((), 0..39),
public: true,
name: "my_policy_id".to_string(),
annotation: None,
value: Box::new(Constant::ByteArray {
location: Span::new((), 25..39),
bytes: vec![0, 170, 255],
}),
tipo: (),
}),
)
}
#[test]
fn base16_bytearray_literals() {
let code = indoc! {r#"
pub const my_policy_id = #"00aaff"
"#};
assert_definition(
code,
ast::UntypedDefinition::ModuleConstant(ModuleConstant {
doc: None,
location: Span::new((), 0..34),
public: true,
name: "my_policy_id".to_string(),
annotation: None,
value: Box::new(Constant::ByteArray {
location: Span::new((), 25..34),
bytes: vec![0, 170, 255],
}),
tipo: (),
}),
)
}