Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in as-max-len? #300

Closed
obycode opened this issue Jan 24, 2024 · 3 comments
Closed

Error in as-max-len? #300

obycode opened this issue Jan 24, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@obycode
Copy link
Collaborator

obycode commented Jan 24, 2024

(as-max-len? "" u0)

This is returning none but it should return (some ""). This seems to be a generic issue with as-max-len?.

@obycode obycode added the bug Something isn't working label Jan 24, 2024
@obycode
Copy link
Collaborator Author

obycode commented Jan 24, 2024

Experimenting with this a bit more, it seems to be an off by one error. If the length passed to as-max-len? is equal to the length of the value, it should return some value, but it is returning none. If it is length + 1, then it seems fine. It looks like my tests didn't cover that case.

@obycode
Copy link
Collaborator Author

obycode commented Jan 24, 2024

    #[test]
    fn as_max_len_string_utf8() {
        crosscheck(
            r#"(as-max-len? u"hello" u16)"#,
            Ok(Some(
                Value::some(
                    Value::string_utf8_from_string_utf8_literal("hello".to_owned()).unwrap(),
                )
                .unwrap(),
            )),
        );
    }

    #[test]
    fn as_max_len_list() {
        crosscheck(
            r#"(as-max-len? (list 42 21) u2)"#,
            Ok(Some(
                Value::some(
                    Value::cons_list_unsanitized(vec![Value::Int(42), Value::Int(21)]).unwrap(),
                )
                .unwrap(),
            )),
        );
    }

    #[test]
    fn as_max_len_string_0() {
        crosscheck(
            r#"(as-max-len? "" u0)"#,
            Ok(Some(
                Value::some(Value::string_ascii_from_bytes(vec![]).unwrap()).unwrap(),
            )),
        );
    }

    #[test]
    fn as_max_len_list_0() {
        crosscheck(
            r#"(as-max-len? (list) u0)"#,
            Ok(Some(
                Value::some(Value::cons_list_unsanitized(vec![]).unwrap()).unwrap(),
            )),
        );
    }

@obycode obycode self-assigned this Jan 24, 2024
@obycode
Copy link
Collaborator Author

obycode commented Jan 25, 2024

Fixed in #306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

1 participant