✨ feat(mq-lang): add base64url/base64urld builtins and tests#1297
✨ feat(mq-lang): add base64url/base64urld builtins and tests#1297
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds URL-safe base64 encoding and decoding functions (base64url and base64urld) to the mq language, addressing issues #1294 and #1295. The implementation follows the same pattern as the existing standard base64 functions (base64 and base64d), using the BASE64_URL_SAFE_NO_PAD encoder from the base64 crate instead of BASE64_STANDARD.
Changes:
- Add
BASE64URLandBASE64URLDbuiltin function implementations with support for String and Markdown types - Register hash constants, dispatch table entries, and function documentation for both new functions
- Add test cases for encoding, decoding, and error handling with invalid types
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/mq-lang/src/eval/builtin.rs | Adds BASE64URL and BASE64URLD builtin definitions, helper functions, hash constants, dispatch entries, and documentation |
| crates/mq-lang/src/eval.rs | Adds test cases for base64url encode/decode and error handling |
| #[case::base64url_encode( | ||
| vec![RuntimeValue::String("hello".into())], | ||
| vec![ | ||
| ast_call("base64url", smallvec![ | ||
| ]) | ||
| ], | ||
| Ok(vec![RuntimeValue::String("aGVsbG8".into())]) | ||
| )] | ||
| #[case::base64url_decode( | ||
| vec![RuntimeValue::String("aGVsbG8".into())], | ||
| vec![ | ||
| ast_call("base64urld", smallvec![ | ||
| ]) | ||
| ], | ||
| Ok(vec![RuntimeValue::String("hello".into())]) | ||
| )] | ||
| #[case::base64url(vec![RuntimeValue::Number(1.into())], | ||
| vec![ | ||
| ast_call("base64url", smallvec![ | ||
| ]) | ||
| ], | ||
| Err(InnerError::Runtime(RuntimeError::InvalidTypes{token: Token { range: Range::default(), kind: TokenKind::Eof, module_id: 1.into()}, | ||
| name: "base64url".to_string(), | ||
| args: vec![1.to_string().into()]})))] | ||
| #[case::base64urld(vec![RuntimeValue::Number(1.into())], | ||
| vec![ | ||
| ast_call("base64urld", smallvec![ | ||
| ]) | ||
| ], | ||
| Err(InnerError::Runtime(RuntimeError::InvalidTypes{token: Token { range: Range::default(), kind: TokenKind::Eof, module_id: 1.into()}, | ||
| name: "base64urld".to_string(), | ||
| args: vec![1.to_string().into()]})))] |
There was a problem hiding this comment.
The test coverage for base64url and base64urld is incomplete. The existing base64 and base64d tests include cases for Markdown nodes (see lines 2766-2770 and 2785-2790), but the new base64url and base64urld tests only cover String and Number types. To maintain consistency and ensure complete test coverage, add test cases for base64url and base64urld with Markdown nodes as input.
Closes #1294
Closes #1295