Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fmt
  • Loading branch information
ascjones committed Aug 19, 2020
commit e55248a8f014f522be5a5ed7b3dc17e02b615e6a
51 changes: 37 additions & 14 deletions metadata/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl ContractBuilder {
/// Set the contract name (required)
pub fn name<S>(&mut self, name: S) -> &mut Self
where
S: AsRef<str>
S: AsRef<str>,
{
self.name = Some(name.as_ref().to_string());
self
Expand All @@ -276,14 +276,19 @@ impl ContractBuilder {
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
self.authors = Some(authors.into_iter().map(|s| s.as_ref().to_string()).collect());
self.authors = Some(
authors
.into_iter()
.map(|s| s.as_ref().to_string())
.collect(),
);
self
}

/// Set the contract description (optional)
pub fn description<S>(&mut self, description: Option<S>) -> &mut Self
where
S: AsRef<str>
S: AsRef<str>,
{
self.description = description.map(|s| s.as_ref().to_string());
self
Expand All @@ -302,16 +307,15 @@ impl ContractBuilder {
}

/// Set the contract homepage url (optional)
pub fn homepage(&mut self, homepage: Option<Url>) -> &mut Self
{
pub fn homepage(&mut self, homepage: Option<Url>) -> &mut Self {
self.homepage = homepage;
self
}

/// Set the contract license (optional)
pub fn license<S>(&mut self, license: Option<S>) -> &mut Self
where
S: AsRef<str>
where
S: AsRef<str>,
{
self.license = license.map(|s| s.as_ref().to_string());
self
Expand All @@ -323,7 +327,9 @@ impl ContractBuilder {
pub fn build(&self) -> Result<Contract, String> {
let mut required = Vec::new();

if let (Some(name), Some(version), Some(authors)) = (&self.name, &self.version, &self.authors) {
if let (Some(name), Some(version), Some(authors)) =
(&self.name, &self.version, &self.authors)
{
Ok(Contract {
name: name.to_string(),
version: version.clone(),
Expand All @@ -344,7 +350,10 @@ impl ContractBuilder {
if self.authors.is_none() {
required.push("authors")
}
Err(format!("Missing required non-default fields: {}", required.join(", ")))
Err(format!(
"Missing required non-default fields: {}",
required.join(", ")
))
}
}
}
Expand Down Expand Up @@ -380,31 +389,43 @@ mod tests {
.authors(vec!["Parity Technologies <admin@parity.io>".to_string()])
.build();

assert_eq!(missing_name.unwrap_err(), "Missing required non-default fields: name");
assert_eq!(
missing_name.unwrap_err(),
"Missing required non-default fields: name"
);

let missing_version = Contract::builder()
.name("incrementer".to_string())
// .version(Version::new(2, 1, 0))
.authors(vec!["Parity Technologies <admin@parity.io>".to_string()])
.build();

assert_eq!(missing_version.unwrap_err(), "Missing required non-default fields: version");
assert_eq!(
missing_version.unwrap_err(),
"Missing required non-default fields: version"
);

let missing_authors = Contract::builder()
.name("incrementer".to_string())
.version(Version::new(2, 1, 0))
// .authors(vec!["Parity Technologies <admin@parity.io>".to_string()])
.build();

assert_eq!(missing_authors.unwrap_err(), "Missing required non-default fields: authors");
assert_eq!(
missing_authors.unwrap_err(),
"Missing required non-default fields: authors"
);

let missing_all = Contract::builder()
// .name("incrementer".to_string())
// .version(Version::new(2, 1, 0))
// .authors(vec!["Parity Technologies <admin@parity.io>".to_string()])
.build();

assert_eq!(missing_all.unwrap_err(), "Missing required non-default fields: name, version, authors");
assert_eq!(
missing_all.unwrap_err(),
"Missing required non-default fields: name, version, authors"
);
}

#[test]
Expand All @@ -419,7 +440,9 @@ mod tests {
.authors(vec!["Parity Technologies <admin@parity.io>".to_string()])
.description(Some("increment a value".to_string()))
.documentation(Some(Url::parse("http://docs.rs/").unwrap()))
.repository(Some(Url::parse("http://github.com/paritytech/ink/").unwrap()))
.repository(Some(
Url::parse("http://github.com/paritytech/ink/").unwrap(),
))
.homepage(Some(Url::parse("http://example.com/").unwrap()))
.license(Some("Apache-2.0".to_string()))
.build()
Expand Down