Add iterator support for strings.

This commit is contained in:
Stephen Chung
2020-06-16 09:34:30 +08:00
parent 4603f8026f
commit ff37e02443
5 changed files with 57 additions and 14 deletions

View File

@@ -30,6 +30,26 @@ fn test_for_array() -> Result<(), Box<EvalAltResult>> {
Ok(())
}
#[test]
fn test_for_string() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
let script = r#"
let s = "hello";
let sum = 0;
for ch in s {
sum += ch.to_int();
}
sum
"#;
assert_eq!(engine.eval::<INT>(script)?, 532);
Ok(())
}
#[cfg(not(feature = "no_object"))]
#[cfg(not(feature = "no_index"))]
#[test]