Merge pull request #1176 from MrAliSalehi/master

improving `reply_keyboard_markup`
This commit is contained in:
Lewis Pearson 2024-10-05 22:20:29 +00:00 committed by GitHub
commit 985a820e7b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 2 deletions

View file

@ -65,11 +65,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Wrap `Public` variant of `ChatKind` in `Box` - Wrap `Public` variant of `ChatKind` in `Box`
- Replaced `user_ids` with `users` in `UsersShared` struct - Replaced `user_ids` with `users` in `UsersShared` struct
- Remove a useless generic type in the `KeyboardMarkup::selective` function ([#1176][pr1176])
[pr1131]: https://github.com/teloxide/teloxide/pull/1131 [pr1131]: https://github.com/teloxide/teloxide/pull/1131
[pr1134]: https://github.com/teloxide/teloxide/pull/1134 [pr1134]: https://github.com/teloxide/teloxide/pull/1134
[pr1146]: https://github.com/teloxide/teloxide/pull/1146 [pr1146]: https://github.com/teloxide/teloxide/pull/1146
[pr1147]: https://github.com/teloxide/teloxide/pull/1147 [pr1147]: https://github.com/teloxide/teloxide/pull/1147
[pr1151]: https://github.com/teloxide/teloxide/pull/1151 [pr1151]: https://github.com/teloxide/teloxide/pull/1151
[pr1176]: https://github.com/teloxide/teloxide/pull/1176
### Removed ### Removed

View file

@ -125,7 +125,7 @@ impl KeyboardMarkup {
/// Sets [`selective`] to `true`. /// Sets [`selective`] to `true`.
/// ///
/// [`selective`]: KeyboardMarkup::selective /// [`selective`]: KeyboardMarkup::selective
pub fn selective<T>(self) -> Self { pub fn selective(self) -> Self {
Self { selective: true, ..self } Self { selective: true, ..self }
} }
} }
@ -146,6 +146,23 @@ mod tests {
"selective": false "selective": false
} }
"#; "#;
serde_json::from_str::<KeyboardMarkup>(data).unwrap(); assert!(serde_json::from_str::<KeyboardMarkup>(data).is_ok())
}
#[test]
fn serialize() {
let keyboard = vec![vec![
KeyboardButton::new("a"),
KeyboardButton::new("b"),
KeyboardButton::new("c"),
KeyboardButton::new("d"),
]];
let keyboard_markup = KeyboardMarkup::new(keyboard)
.persistent()
.resize_keyboard()
.selective()
.one_time_keyboard();
let expected = r#"{"keyboard":[[{"text":"a"},{"text":"b"},{"text":"c"},{"text":"d"}]],"is_persistent":true,"resize_keyboard":true,"one_time_keyboard":true,"selective":true}"#;
assert!(serde_json::ser::to_string(&keyboard_markup).is_ok_and(|s| s.eq(expected)));
} }
} }