Skip to content

Commit b58b0b1

Browse files
authored
Code coverage on models (#4)
* increase code coverage * fix workflow missing fmt
1 parent e67f96a commit b58b0b1

File tree

4 files changed

+106
-2
lines changed

4 files changed

+106
-2
lines changed

.github/workflows/validation.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
options: --security-opt seccomp=unconfined
1515
steps:
1616
- uses: actions/checkout@v4
17+
- name: Setup tools
18+
run: rustup component add rustfmt
1719
- name: Cargo check
1820
timeout-minutes: 2
1921
run: cargo check --locked

scraper/src/df/models.rs

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Ord for DevilFruit {
5151

5252
impl PartialOrd for DevilFruit {
5353
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
54-
self.df_url.partial_cmp(&other.df_url)
54+
Some(self.cmp(other))
5555
}
5656
}
5757

@@ -86,3 +86,75 @@ impl UrlTyped for Character {
8686
format!("/wiki/Character:{}", self.id)
8787
}
8888
}
89+
90+
#[cfg(test)]
91+
mod tests {
92+
use crate::{
93+
df::{
94+
models::DfTypeInfo,
95+
types::{DfSubType, DfType},
96+
},
97+
types::UrlTyped,
98+
};
99+
100+
use super::{Character, DevilFruit};
101+
102+
#[test]
103+
fn df_has_valid_traits() {
104+
let dftype = DfTypeInfo {
105+
df_type: DfType::Logia,
106+
cannon_count: 10,
107+
non_cannon_count: 1,
108+
description: "logia".to_string(),
109+
};
110+
assert_eq!(
111+
format!("{}", dftype),
112+
"(df_type: Logia, cannon: 10, non-cannon: 1, description: logia)"
113+
);
114+
let df1 = DevilFruit {
115+
df_type: DfType::Zoan,
116+
df_sub_type: Some(DfSubType::MythicalZoan),
117+
name: "Nika".to_string(),
118+
en_name: "Nika".to_string(),
119+
description: "Used to Gomu".to_string(),
120+
pic_url: "pic".to_string(),
121+
df_url: "nika".to_string(),
122+
};
123+
let df2 = DevilFruit {
124+
df_type: DfType::Zoan,
125+
df_sub_type: Some(DfSubType::MythicalZoan),
126+
name: "Zeus".to_string(),
127+
en_name: "Zeus".to_string(),
128+
description: "Greek".to_string(),
129+
pic_url: "pic".to_string(),
130+
df_url: "zeus".to_string(),
131+
};
132+
let df3 = DevilFruit {
133+
df_type: DfType::Zoan,
134+
df_sub_type: Some(DfSubType::MythicalZoan),
135+
name: "Nika".to_string(),
136+
en_name: "Nika".to_string(),
137+
description: "Used to Gomu".to_string(),
138+
pic_url: "pic".to_string(),
139+
df_url: "nika".to_string(),
140+
};
141+
assert_ne!(df1, df2);
142+
assert_eq!(df1, df3);
143+
assert!(df1 < df2);
144+
assert_eq!(
145+
format!("{}", df1),
146+
format!("(df_type: {}, df_sub_type: {:?}, name: {}, english name: {}, pic: {}, url: {}, description: {})",
147+
df1.df_type, df1.df_sub_type, df1.name, df1.en_name, df1.pic_url, df1.df_url, df1.description
148+
));
149+
}
150+
151+
#[test]
152+
fn char_has_valid_traits() {
153+
let character = Character {
154+
id: "1234".to_string(),
155+
name: "Foo".to_string(),
156+
pic_url: "pic".to_string(),
157+
};
158+
assert_eq!(character.get_path(), "/wiki/Character:1234");
159+
}
160+
}

scraper/src/df/types.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,33 @@ impl DfSubType {
7070
}
7171
}
7272
}
73+
74+
#[cfg(test)]
75+
mod tests {
76+
use crate::{df::types::DfSubType, types::UrlTyped};
77+
78+
use super::DfType;
79+
80+
#[test]
81+
fn dftype_has_valid_impl() {
82+
let dft = DfType::Zoan;
83+
assert_eq!(dft.get_path(), "/wiki/Zoan");
84+
assert_eq!(dft.id_for_fruit_list(), "#List_of_Zoan-Type_Fruits");
85+
let dft = DfType::Logia;
86+
assert_eq!(dft.get_path(), "/wiki/Logia");
87+
assert_eq!(dft.id_for_fruit_list(), "#Logia-Types");
88+
let dft = DfType::Paramecia;
89+
assert_eq!(dft.get_path(), "/wiki/Paramecia");
90+
assert_eq!(dft.id_for_fruit_list(), "#Paramecia-Type_Fruits");
91+
let dft = DfType::Undetermined;
92+
assert_eq!(dft.get_path(), "");
93+
assert_eq!(dft.id_for_fruit_list(), "");
94+
95+
let dfsub = DfSubType::AncientZoan;
96+
assert_eq!(dfsub.get_path(), "/wiki/Zoan");
97+
assert_eq!(dfsub.id_for_fruit_list(), "#Ancient_Zoan");
98+
let dfsub = DfSubType::MythicalZoan;
99+
assert_eq!(dfsub.get_path(), "/wiki/Zoan");
100+
assert_eq!(dfsub.id_for_fruit_list(), "#Mythical_Zoan");
101+
}
102+
}

tarpaulin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ name = "complete code coverage"
33
manifest-path = "./Cargo.toml"
44
output-dir = "./coverage"
55
out = ["Html", "Xml"]
6-
exclude-files = []
6+
exclude-files = ["scraper/src/main.rs"]

0 commit comments

Comments
 (0)