#![allow(missing_docs)]
use std::fs;
use std::path::PathBuf;
#[test]
fn test_parser_084_while_loop_with_hashmap_insert() {
let code = r#"use std::collections::HashMap;
fun parse_args(args: Vec<String>) -> HashMap<String, String> {
let mut parsed = HashMap::new();
let mut i = 0;
while i < args.len() {
let arg = &args[i];
if arg.starts_with("--") {
let key_part = &arg[2..];
parsed.insert(key_part.to_string(), String::from("value"));
}
i += 1;
}
parsed
}
fun main() {
let test = vec![String::from("--test")];
let result = parse_args(test);
println("Done");
}
"#;
let temp_file = PathBuf::from("/tmp/test_parser_084_while_hashmap.ruchy");
fs::write(&temp_file, code).unwrap();
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("check")
.arg(&temp_file)
.assert()
.success();
let _ = fs::remove_file(&temp_file);
}
#[test]
fn test_parser_084_simplified_while_hashmap_insert() {
let code = r#"use std::collections::HashMap;
fun test_insert() -> HashMap<String, String> {
let mut map = HashMap::new();
let mut i = 0;
while i < 3 {
map.insert(String::from("key"), String::from("value"));
i += 1;
}
map
}
fun main() {
let result = test_insert();
println("Done");
}
"#;
let temp_file = PathBuf::from("/tmp/test_parser_084_simplified.ruchy");
fs::write(&temp_file, code).unwrap();
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("check")
.arg(&temp_file)
.assert()
.success();
let _ = fs::remove_file(&temp_file);
}
#[test]
fn test_parser_084_while_with_method_call() {
let code = r#"fun test_method_call() {
let mut i = 0;
let mut s = String::from("test");
while i < 3 {
s.push_str("!");
i += 1;
}
}
fun main() {
test_method_call();
println("Done");
}
"#;
let temp_file = PathBuf::from("/tmp/test_parser_084_method_call.ruchy");
fs::write(&temp_file, code).unwrap();
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("check")
.arg(&temp_file)
.assert()
.success();
let _ = fs::remove_file(&temp_file);
}
#[test]
fn test_parser_084_for_loop_with_hashmap_insert() {
let code = r#"use std::collections::HashMap;
fun test_for_insert() -> HashMap<i32, String> {
let mut map = HashMap::new();
for i in 0..3 {
map.insert(i, String::from("value"));
}
map
}
fun main() {
let result = test_for_insert();
println("Done");
}
"#;
let temp_file = PathBuf::from("/tmp/test_parser_084_for_loop.ruchy");
fs::write(&temp_file, code).unwrap();
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("check")
.arg(&temp_file)
.assert()
.success();
let _ = fs::remove_file(&temp_file);
}