mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-22 22:44:47 +03:00
add tests
This commit is contained in:
parent
dda608f484
commit
3b3d4b4c26
@ -441,6 +441,9 @@ impl ParserContext<'_> {
|
||||
|
||||
// Parses an external function call `credits.aleo/transfer()` or locator `token.aleo/accounts`.
|
||||
fn parse_external_resource(&mut self, expr: Expression, network_span: Span) -> Result<Expression> {
|
||||
// Parse `/`.
|
||||
self.expect(&Token::Div)?;
|
||||
|
||||
// Parse name.
|
||||
let name = self.expect_identifier()?;
|
||||
|
||||
@ -504,8 +507,27 @@ impl ParserContext<'_> {
|
||||
} else if self.eat(&Token::Leo) {
|
||||
return Err(ParserError::only_aleo_external_calls(expr.span()).into());
|
||||
} else if self.eat(&Token::Aleo) {
|
||||
expr = self.parse_external_resource(expr, self.prev_token.span)?;
|
||||
if self.token.token == Token::Div {
|
||||
expr = self.parse_external_resource(expr, self.prev_token.span)?;
|
||||
} else {
|
||||
// Parse as address literal, e.g. `let next: address = hello.aleo;`.
|
||||
if !matches!(expr, Expression::Identifier(_)) {
|
||||
self.emit_err(ParserError::unexpected(expr.to_string(), "an identifier", expr.span()))
|
||||
}
|
||||
|
||||
expr = Expression::Literal(Literal::Address(format!("{}.aleo", expr.to_string()), expr.span(), self.node_builder.next_id()))
|
||||
}
|
||||
} else {
|
||||
// Parse instances of `self.address`.
|
||||
if let Expression::Identifier(id) = expr {
|
||||
if id.name == sym::SelfLower && self.token.token == Token::Address {
|
||||
let span = self.expect(&Token::Address)?;
|
||||
// Convert `self.address` to the current program name.
|
||||
// Note that the unwrap is safe as in order to get to this stage of parsing a program name must have already been parsed.
|
||||
return Ok(Expression::Literal(Literal::Address(format!("{}.aleo", self.program_name.unwrap()), expr.span() + span, self.node_builder.next_id())));
|
||||
}
|
||||
}
|
||||
|
||||
// Parse identifier name.
|
||||
let name = self.expect_identifier()?;
|
||||
|
||||
|
18
tests/expectations/compiler/address/special_address.out
Normal file
18
tests/expectations/compiler/address/special_address.out
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- - compile:
|
||||
- initial_symbol_table: f159adcd5ea24c580a6b8535b217667a40173809e5802a0b03db3dc5b9bec9aa
|
||||
type_checked_symbol_table: 9fd0ee7288d5151305f4cd3820594bd9db7accb589bc936e186709af1df6de21
|
||||
unrolled_symbol_table: 9fd0ee7288d5151305f4cd3820594bd9db7accb589bc936e186709af1df6de21
|
||||
initial_ast: 21db64864f84959ad71dace62a2487285c3b6bb74818536b83a54b63a2bd8d82
|
||||
unrolled_ast: 21db64864f84959ad71dace62a2487285c3b6bb74818536b83a54b63a2bd8d82
|
||||
ssa_ast: d4e2a516deaa30f8663bb3cd1501c52e3cc781b330dbb149ee3bad0692a8cb59
|
||||
flattened_ast: 175fbd23f91421e3d47440c8a7e00fb9e3a2bef1147e061cd8a3f2bd0c978098
|
||||
destructured_ast: a23caa23b3ac10d6c2a1b119af502a9ec4380cf521eb65da2c9e2a5f19d44172
|
||||
inlined_ast: a23caa23b3ac10d6c2a1b119af502a9ec4380cf521eb65da2c9e2a5f19d44172
|
||||
dce_ast: a23caa23b3ac10d6c2a1b119af502a9ec4380cf521eb65da2c9e2a5f19d44172
|
||||
bytecode: d9e6c28f9e5527abe9cdb07b9d35375901446415f5d645b0363597200ee45be7
|
||||
errors: ""
|
||||
warnings: ""
|
110
tests/expectations/parser/program/address_literal.out
Normal file
110
tests/expectations/parser/program/address_literal.out
Normal file
@ -0,0 +1,110 @@
|
||||
---
|
||||
namespace: Parse
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- imports: {}
|
||||
stubs: {}
|
||||
program_scopes:
|
||||
test:
|
||||
program_id: "{\"name\":\"test\",\"network\":\"\\\"{\\\\\\\"id\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"name\\\\\\\":\\\\\\\"aleo\\\\\\\",\\\\\\\"span\\\\\\\":\\\\\\\"{\\\\\\\\\\\\\\\"lo\\\\\\\\\\\\\\\":0,\\\\\\\\\\\\\\\"hi\\\\\\\\\\\\\\\":0}\\\\\\\"}\\\"\"}"
|
||||
consts: []
|
||||
structs: []
|
||||
mappings:
|
||||
- - Yo
|
||||
- identifier: "{\"id\":\"2\",\"name\":\"Yo\",\"span\":\"{\\\"lo\\\":34,\\\"hi\\\":36}\"}"
|
||||
key_type: Address
|
||||
value_type:
|
||||
Integer: U32
|
||||
span:
|
||||
lo: 26
|
||||
hi: 53
|
||||
id: 3
|
||||
functions:
|
||||
- - main
|
||||
- annotations: []
|
||||
variant: Transition
|
||||
identifier: "{\"id\":\"4\",\"name\":\"main\",\"span\":\"{\\\"lo\\\":70,\\\"hi\\\":74}\"}"
|
||||
input:
|
||||
- Internal:
|
||||
identifier: "{\"id\":\"5\",\"name\":\"a\",\"span\":\"{\\\"lo\\\":75,\\\"hi\\\":76}\"}"
|
||||
mode: None
|
||||
type_: Address
|
||||
span:
|
||||
lo: 75
|
||||
hi: 76
|
||||
id: 6
|
||||
output: []
|
||||
output_type: Unit
|
||||
block:
|
||||
statements:
|
||||
- Assert:
|
||||
variant:
|
||||
AssertEq:
|
||||
- Identifier: "{\"id\":\"7\",\"name\":\"a\",\"span\":\"{\\\"lo\\\":107,\\\"hi\\\":108}\"}"
|
||||
- Access:
|
||||
Member:
|
||||
inner:
|
||||
Identifier: "{\"id\":\"8\",\"name\":\"self\",\"span\":\"{\\\"lo\\\":110,\\\"hi\\\":114}\"}"
|
||||
name: "{\"id\":\"9\",\"name\":\"caller\",\"span\":\"{\\\"lo\\\":115,\\\"hi\\\":121}\"}"
|
||||
span:
|
||||
lo: 110
|
||||
hi: 121
|
||||
id: 10
|
||||
span:
|
||||
lo: 97
|
||||
hi: 106
|
||||
id: 11
|
||||
- Assert:
|
||||
variant:
|
||||
AssertEq:
|
||||
- Identifier: "{\"id\":\"12\",\"name\":\"a\",\"span\":\"{\\\"lo\\\":142,\\\"hi\\\":143}\"}"
|
||||
- Literal:
|
||||
Address:
|
||||
- test.aleo
|
||||
- span:
|
||||
lo: 145
|
||||
hi: 157
|
||||
- 14
|
||||
span:
|
||||
lo: 132
|
||||
hi: 141
|
||||
id: 15
|
||||
- Assert:
|
||||
variant:
|
||||
AssertEq:
|
||||
- Identifier: "{\"id\":\"16\",\"name\":\"a\",\"span\":\"{\\\"lo\\\":178,\\\"hi\\\":179}\"}"
|
||||
- Literal:
|
||||
Address:
|
||||
- hello
|
||||
- span:
|
||||
lo: 181
|
||||
hi: 186
|
||||
- 18
|
||||
span:
|
||||
lo: 168
|
||||
hi: 177
|
||||
id: 19
|
||||
- Return:
|
||||
expression:
|
||||
Literal:
|
||||
Address:
|
||||
- foo
|
||||
- span:
|
||||
lo: 209
|
||||
hi: 212
|
||||
- 21
|
||||
span:
|
||||
lo: 202
|
||||
hi: 218
|
||||
id: 22
|
||||
span:
|
||||
lo: 87
|
||||
hi: 224
|
||||
id: 23
|
||||
span:
|
||||
lo: 59
|
||||
hi: 224
|
||||
id: 24
|
||||
span:
|
||||
lo: 2
|
||||
hi: 226
|
110
tests/expectations/parser/program/special_address.out
Normal file
110
tests/expectations/parser/program/special_address.out
Normal file
@ -0,0 +1,110 @@
|
||||
---
|
||||
namespace: Parse
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- imports: {}
|
||||
stubs: {}
|
||||
program_scopes:
|
||||
test:
|
||||
program_id: "{\"name\":\"test\",\"network\":\"\\\"{\\\\\\\"id\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"name\\\\\\\":\\\\\\\"aleo\\\\\\\",\\\\\\\"span\\\\\\\":\\\\\\\"{\\\\\\\\\\\\\\\"lo\\\\\\\\\\\\\\\":0,\\\\\\\\\\\\\\\"hi\\\\\\\\\\\\\\\":0}\\\\\\\"}\\\"\"}"
|
||||
consts: []
|
||||
structs: []
|
||||
mappings:
|
||||
- - Yo
|
||||
- identifier: "{\"id\":\"2\",\"name\":\"Yo\",\"span\":\"{\\\"lo\\\":34,\\\"hi\\\":36}\"}"
|
||||
key_type: Address
|
||||
value_type:
|
||||
Integer: U32
|
||||
span:
|
||||
lo: 26
|
||||
hi: 53
|
||||
id: 3
|
||||
functions:
|
||||
- - main
|
||||
- annotations: []
|
||||
variant: Transition
|
||||
identifier: "{\"id\":\"4\",\"name\":\"main\",\"span\":\"{\\\"lo\\\":70,\\\"hi\\\":74}\"}"
|
||||
input:
|
||||
- Internal:
|
||||
identifier: "{\"id\":\"5\",\"name\":\"a\",\"span\":\"{\\\"lo\\\":75,\\\"hi\\\":76}\"}"
|
||||
mode: None
|
||||
type_: Address
|
||||
span:
|
||||
lo: 75
|
||||
hi: 76
|
||||
id: 6
|
||||
output: []
|
||||
output_type: Unit
|
||||
block:
|
||||
statements:
|
||||
- Assert:
|
||||
variant:
|
||||
AssertEq:
|
||||
- Identifier: "{\"id\":\"7\",\"name\":\"a\",\"span\":\"{\\\"lo\\\":107,\\\"hi\\\":108}\"}"
|
||||
- Access:
|
||||
Member:
|
||||
inner:
|
||||
Identifier: "{\"id\":\"8\",\"name\":\"self\",\"span\":\"{\\\"lo\\\":110,\\\"hi\\\":114}\"}"
|
||||
name: "{\"id\":\"9\",\"name\":\"caller\",\"span\":\"{\\\"lo\\\":115,\\\"hi\\\":121}\"}"
|
||||
span:
|
||||
lo: 110
|
||||
hi: 121
|
||||
id: 10
|
||||
span:
|
||||
lo: 97
|
||||
hi: 106
|
||||
id: 11
|
||||
- Assert:
|
||||
variant:
|
||||
AssertEq:
|
||||
- Identifier: "{\"id\":\"12\",\"name\":\"a\",\"span\":\"{\\\"lo\\\":142,\\\"hi\\\":143}\"}"
|
||||
- Literal:
|
||||
Address:
|
||||
- test.aleo
|
||||
- span:
|
||||
lo: 145
|
||||
hi: 157
|
||||
- 14
|
||||
span:
|
||||
lo: 132
|
||||
hi: 141
|
||||
id: 15
|
||||
- Assert:
|
||||
variant:
|
||||
AssertEq:
|
||||
- Identifier: "{\"id\":\"16\",\"name\":\"a\",\"span\":\"{\\\"lo\\\":178,\\\"hi\\\":179}\"}"
|
||||
- Literal:
|
||||
Address:
|
||||
- hello
|
||||
- span:
|
||||
lo: 181
|
||||
hi: 186
|
||||
- 18
|
||||
span:
|
||||
lo: 168
|
||||
hi: 177
|
||||
id: 19
|
||||
- Return:
|
||||
expression:
|
||||
Literal:
|
||||
Address:
|
||||
- foo
|
||||
- span:
|
||||
lo: 209
|
||||
hi: 212
|
||||
- 21
|
||||
span:
|
||||
lo: 202
|
||||
hi: 218
|
||||
id: 22
|
||||
span:
|
||||
lo: 87
|
||||
hi: 224
|
||||
id: 23
|
||||
span:
|
||||
lo: 59
|
||||
hi: 224
|
||||
id: 24
|
||||
span:
|
||||
lo: 2
|
||||
hi: 226
|
15
tests/tests/compiler/address/special_address.leo
Normal file
15
tests/tests/compiler/address/special_address.leo
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
*/
|
||||
|
||||
program test.aleo {
|
||||
mapping Yo: address => u32;
|
||||
|
||||
transition main(a: address) -> address {
|
||||
assert_eq(a, self.caller);
|
||||
assert_eq(a, self.address);
|
||||
assert_eq(a, hello.aleo);
|
||||
return foo.aleo;
|
||||
}
|
||||
}
|
@ -4,3 +4,9 @@ expectation: Pass
|
||||
*/
|
||||
|
||||
aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8s7pyjh9
|
||||
|
||||
hello.aleo
|
||||
|
||||
fooooo.aleo
|
||||
|
||||
bar.aleo
|
15
tests/tests/parser/program/special_address.leo
Normal file
15
tests/tests/parser/program/special_address.leo
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
namespace: Parse
|
||||
expectation: Pass
|
||||
*/
|
||||
|
||||
program test.aleo {
|
||||
mapping Yo: address => u32;
|
||||
|
||||
transition main(a: address) {
|
||||
assert_eq(a, self.caller);
|
||||
assert_eq(a, self.address);
|
||||
assert_eq(a, hello.aleo);
|
||||
return foo.aleo;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user