Files
radicle-git/git-ref-format/t/src/properties/pattern.rs
T
Fintan Halpenny db7f2d40e3 git-ref-format: fix to deserialization
When deserializing through `serde_json::from_value` the following
error would occur:

  panicked at 'called Result::unwrap() on an Err value: Error("invalid
  type: string "master", expected a borrowed string", line: 0, column:
  0)'

To fix this it is necessary for the Deserialize implementations to
deserialize into an owned String and convert from there.

While attempting to test this the `Qualified` and `Namespaced`
implementations were not able to be used:

  error: implementation of `serde::de::Deserialize` is not general enough
  --> git-ref-format/t/src/properties/name.rs:86:9
   |
86 |         roundtrip::json_value(qualified);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `serde::de::Deserialize` is not general enough
   |
   = note: `Qualified<'_>` must implement `serde::de::Deserialize<'0>`, for any lifetime `'0`...
   = note: ...but `Qualified<'_>` actually implements
   `serde::de::Deserialize<'1>`, for some specific lifetime `'1`

The Deserialize for both of those types now return owned data by
returning a 'static lifetime instead.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-12-08 15:20:11 +00:00

61 lines
1.6 KiB
Rust

// Copyright © 2022 The Radicle Link Contributors
// SPDX-License-Identifier: GPL-3.0-or-later
use std::convert::TryFrom;
use git_ref_format::{refspec, Error};
use proptest::prelude::*;
use test_helpers::roundtrip;
use crate::gen;
proptest! {
#[test]
fn valid(input in gen::with_glob()) {
assert_eq!(input.as_str(), refspec::PatternStr::try_from_str(&input).unwrap().as_str())
}
#[test]
fn refname_is_pattern(input in gen::valid()) {
assert_eq!(input.as_str(), refspec::PatternStr::try_from_str(&input).unwrap().as_str())
}
#[test]
fn no_more_than_one_star(input in gen::multi_glob()) {
assert_matches!(refspec::PatternString::try_from(input), Err(Error::Pattern))
}
#[test]
fn invalid_refname_is_invalid_pattern(input in gen::invalid()) {
assert_matches!(refspec::PatternString::try_from(input), Err(_))
}
#[test]
fn roundtrip_components(input in gen::with_glob()) {
assert_eq!(
input.as_str(),
refspec::PatternStr::try_from_str(&input)
.unwrap()
.components()
.collect::<Result<refspec::PatternString, _>>()
.unwrap()
.as_str()
)
}
#[test]
fn json(input in gen::with_glob()) {
roundtrip::json(refspec::PatternString::try_from(input).unwrap())
}
#[test]
fn json_value(input in gen::with_glob()) {
roundtrip::json_value(refspec::PatternString::try_from(input).unwrap())
}
#[test]
fn cbor(input in gen::with_glob()) {
roundtrip::cbor(refspec::PatternString::try_from(input).unwrap())
}
}