Skip to content

Commit

Permalink
chore: add formatting settings and re-formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Oct 4, 2023
1 parent 57a495f commit 0d87a8d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 56 deletions.
10 changes: 2 additions & 8 deletions examples/logo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ use tileline::{tile, Config, Element, ElementLink, Rgb};
struct Value(Rgb, Rgb);

impl Value {
fn new(
background: &str,
border: &str,
) -> std::result::Result<Self, Box<dyn std::error::Error>> {
Ok(Self(
Rgb::from_hex_str(background)?,
Rgb::from_hex_str(border)?,
))
fn new(background: &str, border: &str) -> std::result::Result<Self, Box<dyn std::error::Error>> {
Ok(Self(Rgb::from_hex_str(background)?, Rgb::from_hex_str(border)?))
}
}

Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
max_width = 120
8 changes: 3 additions & 5 deletions src/pieces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ where
W: Write,
{
let mut svg = Writer::new(output);
svg.write_event(Event::Decl(BytesDecl::new(
"1.0",
Some("UTF-8"),
Some("no"),
svg.write_event(Event::Decl(BytesDecl::new("1.0", Some("UTF-8"), Some("no"))))?;
svg.write_event(Event::DocType(BytesText::from_escaped(
r#"svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd""#,
)))?;
svg.write_event(Event::DocType(BytesText::from_escaped(r#"svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd""#)))?;

svg.create_element("svg")
.with_attributes(vec![
Expand Down
23 changes: 4 additions & 19 deletions src/year.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ impl<E: Element> Week<E> {
fn new(date: NaiveDate, year: i32, data_source: Rc<dyn DateDataSource<E>>) -> Self {
let weekday = if date.iso_week().year() != year {
let rem = 7 - date.weekday().number_from_sunday();
date.checked_add_days(chrono::Days::new(rem as u64))
.unwrap()
date.checked_add_days(chrono::Days::new(rem as u64)).unwrap()
} else {
date.checked_add_days(chrono::Days::new(7)).unwrap()
};
Expand All @@ -71,9 +70,7 @@ impl<E: Element> Iterator for Week<E> {
Some(WrapperElement::None)
} else {
let ds = self.data_source.clone();
self.date
.next()
.map(|d| WrapperElement::Real(ds.get_element(d)))
self.date.next().map(|d| WrapperElement::Real(ds.get_element(d)))
}
}
}
Expand Down Expand Up @@ -159,14 +156,7 @@ impl Metadata<std::vec::IntoIter<YearInfo>, YearInfo> for YearMetadata {
}

fn top(&self) -> Option<std::vec::IntoIter<YearInfo>> {
Some(
vec![
YearInfo::new("S", 3),
YearInfo::new("T", 3),
YearInfo::new("S", 1),
]
.into_iter(),
)
Some(vec![YearInfo::new("S", 3), YearInfo::new("T", 3), YearInfo::new("S", 1)].into_iter())
}

fn right(&self) -> Option<std::vec::IntoIter<YearInfo>> {
Expand All @@ -191,11 +181,6 @@ where
{
config.set_mode(Mode::ColumnRow);
let metadata = YearMetadata {};
metadata_tile(
config,
metadata,
Year::new(year, Rc::new(data_source)),
output,
)?;
metadata_tile(config, metadata, Year::new(year, Rc::new(data_source)), output)?;
Ok(())
}
29 changes: 5 additions & 24 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ fn test_simple() {
let config = Config::new().build();
let mut out = Vec::new();
tile(config.clone(), val.clone().into_iter(), &mut out).unwrap();
assert_eq!(
out,
std::fs::read("./fixtures/simple.svg").unwrap().to_vec()
);
assert_eq!(out, std::fs::read("./fixtures/simple.svg").unwrap().to_vec());
}

#[test]
Expand All @@ -132,12 +129,7 @@ fn test_simple_column_row() {
let config = Config::new().mode(Mode::ColumnRow).build();
let mut out = Vec::new();
tile(config.clone(), val.clone().into_iter(), &mut out).unwrap();
assert_eq!(
out,
std::fs::read("./fixtures/simple_column_row.svg")
.unwrap()
.to_vec()
);
assert_eq!(out, std::fs::read("./fixtures/simple_column_row.svg").unwrap().to_vec());
}

#[test]
Expand All @@ -154,12 +146,7 @@ fn test_metadata() {
let config = Config::new().build();
let mut out = Vec::new();
metadata_tile(config, Meta::default(), val.into_iter(), &mut out).unwrap();
assert_eq!(
out,
std::fs::read("./fixtures/simple_metadata.svg")
.unwrap()
.to_vec()
);
assert_eq!(out, std::fs::read("./fixtures/simple_metadata.svg").unwrap().to_vec());
}

#[test]
Expand All @@ -181,10 +168,7 @@ fn test_year_line() {
}

fn get_link(&self) -> Option<Box<dyn ElementLink>> {
Some(Box::new(ElementLinkImpl(
format!("{}", self.date),
"bbb".to_owned(),
)))
Some(Box::new(ElementLinkImpl(format!("{}", self.date), "bbb".to_owned())))
}
}
impl tileline::DateDataSource<DateElement> for YearDatasource {
Expand All @@ -206,8 +190,5 @@ fn test_year_line() {
let config = Config::new().build();
let mut out = Vec::new();
tileline::year_line(2023, YearDatasource {}, &mut out, config).unwrap();
assert_eq!(
out,
std::fs::read("./fixtures/year_line.svg").unwrap().to_vec()
);
assert_eq!(out, std::fs::read("./fixtures/year_line.svg").unwrap().to_vec());
}

0 comments on commit 0d87a8d

Please sign in to comment.