Skip to content

Commit 9fe6196

Browse files
committed
Improve code coverage
1 parent 557308b commit 9fe6196

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl QueryString {
8989
/// ```
9090
#[allow(clippy::new_ret_no_self)]
9191
pub fn simple() -> QueryStringSimple {
92-
QueryStringSimple::new()
92+
QueryStringSimple::default()
9393
}
9494

9595
/// Creates a new, empty query string builder.
@@ -284,7 +284,7 @@ mod tests {
284284

285285
#[test]
286286
fn test_empty() {
287-
let qs = QueryString::dynamic();
287+
let qs = QueryStringSimple::default();
288288
assert_eq!(qs.to_string(), "");
289289
assert_eq!(qs.len(), 0);
290290
assert!(qs.is_empty());

src/slim.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22
use std::fmt::{Debug, Display, Formatter, Write};
33

4-
use crate::{QueryString, QUERY};
4+
use crate::QUERY;
55
use percent_encoding::utf8_percent_encode;
66

77
/// A type alias for the [`WrappedQueryString`] root.
@@ -30,7 +30,7 @@ pub type QueryStringSimple = WrappedQueryString<RootMarker, EmptyValue>;
3030
/// ```
3131
pub struct WrappedQueryString<B, T>
3232
where
33-
B: ConditionalDisplay + Identifyable,
33+
B: ConditionalDisplay + Identifiable,
3434
T: Display,
3535
{
3636
base: BaseOption<B>,
@@ -39,7 +39,7 @@ where
3939

4040
impl Default for QueryStringSimple {
4141
fn default() -> Self {
42-
QueryString::simple()
42+
QueryStringSimple::new()
4343
}
4444
}
4545

@@ -73,7 +73,7 @@ pub struct EmptyValue(());
7373

7474
impl<B, T> WrappedQueryString<B, T>
7575
where
76-
B: ConditionalDisplay + Identifyable,
76+
B: ConditionalDisplay + Identifiable,
7777
T: Display,
7878
{
7979
/// Creates a new, empty query string builder.
@@ -173,36 +173,42 @@ where
173173
}
174174
}
175175

176-
pub trait Identifyable {
176+
pub trait Identifiable {
177177
fn is_root(&self) -> bool;
178178
fn is_empty(&self) -> bool;
179179
fn len(&self) -> usize;
180180
}
181181

182-
impl Identifyable for RootMarker {
182+
pub trait ConditionalDisplay {
183+
fn cond_fmt(&self, should_display: bool, f: &mut Formatter<'_>) -> Result<usize, fmt::Error>;
184+
}
185+
186+
impl Identifiable for RootMarker {
183187
fn is_root(&self) -> bool {
184-
true
188+
unreachable!()
185189
}
186190

187191
fn is_empty(&self) -> bool {
188-
true
192+
unreachable!()
189193
}
190194

191195
fn len(&self) -> usize {
192-
0
196+
unreachable!()
193197
}
194198
}
195199

196-
pub trait ConditionalDisplay {
197-
fn cond_fmt(&self, should_display: bool, f: &mut Formatter<'_>) -> Result<usize, fmt::Error>;
198-
}
199-
200200
impl ConditionalDisplay for RootMarker {
201201
fn cond_fmt(&self, _should_display: bool, _f: &mut Formatter<'_>) -> Result<usize, fmt::Error> {
202202
unreachable!()
203203
}
204204
}
205205

206+
impl Display for RootMarker {
207+
fn fmt(&self, _f: &mut Formatter<'_>) -> fmt::Result {
208+
unreachable!()
209+
}
210+
}
211+
206212
impl<B> ConditionalDisplay for BaseOption<B>
207213
where
208214
B: ConditionalDisplay,
@@ -223,7 +229,7 @@ where
223229

224230
impl<B, T> ConditionalDisplay for WrappedQueryString<B, T>
225231
where
226-
B: ConditionalDisplay + Identifyable,
232+
B: ConditionalDisplay + Identifiable,
227233
T: Display,
228234
{
229235
fn cond_fmt(&self, should_display: bool, f: &mut Formatter<'_>) -> Result<usize, fmt::Error> {
@@ -260,7 +266,7 @@ where
260266

261267
impl<B> BaseOption<B>
262268
where
263-
B: Identifyable + ConditionalDisplay,
269+
B: Identifiable + ConditionalDisplay,
264270
{
265271
fn is_empty(&self) -> bool {
266272
match self {
@@ -277,9 +283,9 @@ where
277283
}
278284
}
279285

280-
impl<B, T> Identifyable for WrappedQueryString<B, T>
286+
impl<B, T> Identifiable for WrappedQueryString<B, T>
281287
where
282-
B: ConditionalDisplay + Identifyable,
288+
B: ConditionalDisplay + Identifiable,
283289
T: Display,
284290
{
285291
fn is_root(&self) -> bool {
@@ -313,14 +319,8 @@ impl<T> KvpOption<T> {
313319
}
314320
}
315321

316-
impl Display for RootMarker {
317-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
318-
f.write_char('?')
319-
}
320-
}
321-
322322
impl Display for EmptyValue {
323-
fn fmt(&self, _f: &mut Formatter<'_>) -> std::fmt::Result {
323+
fn fmt(&self, _f: &mut Formatter<'_>) -> fmt::Result {
324324
Ok(())
325325
}
326326
}
@@ -363,7 +363,7 @@ where
363363

364364
impl<B, T> Display for WrappedQueryString<B, T>
365365
where
366-
B: ConditionalDisplay + Identifyable,
366+
B: ConditionalDisplay + Identifiable,
367367
T: Display,
368368
{
369369
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
@@ -380,7 +380,7 @@ where
380380

381381
impl<B, T> Debug for WrappedQueryString<B, T>
382382
where
383-
B: ConditionalDisplay + Identifyable,
383+
B: ConditionalDisplay + Identifiable,
384384
T: Display,
385385
{
386386
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
@@ -426,7 +426,7 @@ mod tests {
426426
assert_eq!(qs.len(), 4);
427427

428428
assert_eq!(
429-
qs.to_string(),
429+
format!("{qs}"),
430430
"?q=apple???&category=fruits%20and%20vegetables&tasty=true&weight=99.9"
431431
);
432432
}

0 commit comments

Comments
 (0)