haku: add len and index functions for reading lists

This commit is contained in:
りき萌 2024-10-25 23:21:28 +02:00
parent dd955b0649
commit e2f9538156
3 changed files with 63 additions and 8 deletions

View file

@ -292,3 +292,20 @@ fn with_dotter_identity() {
"#;
assert_eq!(eval(code).unwrap(), Value::Ref(RefId::from_u32(2)))
}
#[test]
fn system_len() {
expect_number("len []", 0.0, 0.0001);
expect_number("len [1, 2]", 2.0, 0.0001);
}
#[test]
fn system_index() {
expect_number("index [1] 0", 1.0, 0.0001);
expect_number("index [1, 2] 0", 1.0, 0.0001);
expect_number("index [1, 2] 1", 2.0, 0.0001);
expect_number("index [1] 0.5", 1.0, 0.0001);
expect_number("index [1, 2] 0.5", 1.0, 0.0001);
assert!(eval("index [1] (-1)").is_err());
assert!(eval("index [1] 1").is_err());
}