Skip to content

Commit 7e3cd08

Browse files
committed
temporary solution for the broken concat
1 parent 918a061 commit 7e3cd08

6 files changed

Lines changed: 156 additions & 21 deletions

File tree

Cargo.lock

Lines changed: 120 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ env_logger = "0.11.8"
2525

2626
syn = "2.0.103"
2727
quote = "1.0"
28-
candid_parser = "0.1.4"
28+
candid_parser = "0.2.1"
2929
#ic-cdk-bindgen = { path = "../cdk-rs/src/ic-cdk-bindgen" }
3030
#wf-cdk-bindgen = { path = "../wf-cdk-bindgen" }
31-
wf-cdk-bindgen = "0.1.6"
31+
wf-cdk-bindgen = "0.1.7"
3232

3333
prettyplease = "0.2.34"
3434
serde_json = { version = "1.0", features = ["preserve_order"] }
@@ -54,7 +54,7 @@ dialoguer = { version = "0.11.0", features = ["fuzzy-select"] }
5454
alloy = { version = "1.0.23", features = ["full"], optional = true }
5555
alloy-node-bindings = { version = "1.0.23", optional = true }
5656

57-
candid = "0.10"
57+
candid = "0.10.16"
5858
pocket-ic = "9.0.2"
5959
ic-agent = "0.40.0"
6060

src/generator/candid_to_rust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn generate_bindings(setup: &mut IcpTestSetup) -> Result<(), Error> {
7979

8080
config.set_canister_wasm_path(wasm_path.to_string_lossy().to_string());
8181

82-
let (env, actor) =
82+
let (env, actor, _) =
8383
candid_parser::typing::pretty_check_file(&expand_path(Path::new(&candid_path)))
8484
.unwrap();
8585

src/generator/candid_value_to_rust.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ static KEYWORDS: [&str; 51] = [
2525
"override", "priv", "typeof", "unsized", "virtual", "yield", "try",
2626
];
2727

28+
/// temporary replacement for the older function contact, that is now broken
29+
pub fn concat<'a, D>(docs: D, sep: &'a str) -> RcDoc<'a>
30+
where
31+
D: Iterator<Item = RcDoc<'a>> + Clone,
32+
{
33+
RcDoc::intersperse(docs.clone().map(|d| d.append(sep)), RcDoc::line()).flat_alt(
34+
RcDoc::intersperse(docs, RcDoc::text(sep).append(RcDoc::line())),
35+
)
36+
}
37+
2838
fn ident_<'a>(id: &'a str, case: Option<Case<'a>>) -> (RcDoc<'a>, bool) {
2939
if id.is_empty()
3040
|| id.starts_with(|c: char| !c.is_ascii_alphabetic() && c != '_')
@@ -718,7 +728,7 @@ mod tests {
718728
let type_path = Path::new(type_path);
719729
let value_path = Path::new(value_path);
720730

721-
let (env, actor) = candid_parser::typing::pretty_check_file(type_path).unwrap();
731+
let (env, actor, _) = candid_parser::typing::pretty_check_file(type_path).unwrap();
722732

723733
let candid_value = std::fs::read_to_string(value_path).unwrap();
724734

@@ -730,7 +740,7 @@ mod tests {
730740
fn get_generated(type_path: &str, candid_value: &str) -> String {
731741
let type_path = Path::new(type_path);
732742

733-
let (env, actor) = candid_parser::typing::pretty_check_file(type_path).unwrap();
743+
let (env, actor, _) = candid_parser::typing::pretty_check_file(type_path).unwrap();
734744

735745
if !candid_value.is_empty() {
736746
let arg_value = candid_parser::parse_idl_args(candid_value).unwrap();
@@ -743,7 +753,7 @@ mod tests {
743753

744754
fn rust_check(rust: &str) {
745755
// patterns that we do not like:
746-
let bad_patterns = [r"\w+todo!", r"::::", r",\s*,", r"::\s*\{"];
756+
let bad_patterns = [r"\w+todo!", r"::::", r"^\s*,", r"::\s*\{"];
747757

748758
for pattern in bad_patterns {
749759
let re = Regex::new(pattern).unwrap();
@@ -794,10 +804,14 @@ mod tests {
794804
}
795805

796806
#[test]
797-
fn test_no_args_types() {
807+
fn test_no_args() {
798808
let rust = get_generated("tests/no_args.did", "");
799809

800810
rust_check(&rust);
811+
812+
let rust = get_generated("tests/no_args2.did", "");
813+
814+
rust_check(&rust);
801815
}
802816

803817
#[test]

tests/no_args.did

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
service : () -> {
1+
service : ( ) -> {
22
basic_fs_test : () -> ();
33
compute_file_hash : (text) -> (text);
44
do_fs_test : () -> (text);

tests/no_args2.did

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
service : {
2+
basic_fs_test : () -> ();
3+
compute_file_hash : (text) -> (text);
4+
do_fs_test : () -> (text);
5+
generate_random_fs : (nat64, nat64, nat64) -> (nat64);
6+
get_log : () -> (text) query;
7+
greet : (text) -> (text) query;
8+
read_file : (text) -> (text);
9+
scan_directory : (text) -> (text);
10+
test_create_dir_all : (text) -> ();
11+
test_read_dir : (text) -> (vec text);
12+
write_file : (text, text) -> ();
13+
}

0 commit comments

Comments
 (0)