Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Jun 20, 2024
1 parent a21d9b9 commit 088a17c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rust/candid_parser/src/bindings/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ impl<'a> State<'a> {
.pretty(80)
.to_string();
let match_path = self.state.config_source.get("use_type").unwrap().join(".");
let test_name = use_type.replace(|c: char| !c.is_ascii_alphanumeric(), "_");
let body = format!(
r##"#[test]
fn test_{use_type}() {{
// Generated from path {match_path}.use_type = "{use_type}"
fn test_{test_name}() {{
// Generated from {match_path}.use_type = "{use_type}"
let candid_src = r#"{src}"#;
candid_parser::utils::check_rust_type::<{use_type}>(candid_src).unwrap();
}}
"##
}}"##
);
self.tests.insert(use_type.to_string(), body);
}
Expand Down
2 changes: 2 additions & 0 deletions rust/candid_parser/src/bindings/rust_agent.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ impl<'a> {{PascalCase service_name}}<'a> {
pub const CANISTER_ID : Principal = Principal::from_slice(&[{{principal_slice canister_id}}]); // {{canister_id}}
{{/if}}
{{/if}}
{{#if tests}}
{{tests}}
{{/if}}
2 changes: 2 additions & 0 deletions rust/candid_parser/src/bindings/rust_call.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ pub const CANISTER_ID : Principal = Principal::from_slice(&[{{principal_slice ca
pub const {{snake_case service_name}} : {{PascalCase service_name}} = {{PascalCase service_name}}(CANISTER_ID);
{{/if}}
{{/if}}
{{#if tests}}
{{tests}}
{{/if}}
2 changes: 2 additions & 0 deletions rust/candid_parser/src/bindings/rust_stub.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ fn {{this.name}}({{#each this.args}}{{#if (not @first)}}, {{/if}}{{this.0}}: {{t
unimplemented!()
}
{{/each}}
{{#if tests}}
{{tests}}
{{/if}}
20 changes: 20 additions & 0 deletions rust/candid_parser/tests/assets/ok/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,24 @@ impl Service {
}
pub const CANISTER_ID : Principal = Principal::from_slice(&[]); // aaaaa-aa
pub const service : Service = Service(CANISTER_ID);
#[test]
fn test_Arc_MyList_() {
// Generated from ListInner.record.tail.use_type = "Arc<MyList>"
let candid_src = r#"type List = opt ListInner;
type ListInner = record { head : int; tail : List };
(List)"#;
candid_parser::utils::check_rust_type::<Arc<MyList>>(candid_src).unwrap();
}
#[test]
fn test_i128() {
// Generated from g1.ret0.use_type = "i128"
let candid_src = r#"(int)"#;
candid_parser::utils::check_rust_type::<i128>(candid_src).unwrap();
}
#[test]
fn test_u128() {
// Generated from nat.use_type = "u128"
let candid_src = r#"(nat)"#;
candid_parser::utils::check_rust_type::<u128>(candid_src).unwrap();
}

0 comments on commit 088a17c

Please sign in to comment.