-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathpaths.rs
87 lines (71 loc) · 1.48 KB
/
paths.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#![allow(clippy::disallowed_names)]
mod bar {
#[faux::create]
pub struct Bar {
a: i32,
}
#[faux::methods]
impl Bar {
pub fn new() -> Bar {
Bar { a: 10 }
}
pub fn get(&self) -> i32 {
self.a
}
pub fn num() -> i32 {
4
}
}
}
mod foo {
#[faux::create]
pub struct Foo {
f: &'static str,
}
#[faux::methods]
impl Foo {
pub fn new(f: &'static str) -> Self {
Foo { f }
}
pub fn get(&self) -> &'static str {
self.f
}
}
}
mod other {
use crate::foo;
#[faux::methods(path = "crate")]
impl foo::Foo {
pub fn other_new() -> foo::Foo {
foo::Foo::new("hello")
}
pub fn get_chunk(&self, chunk: usize) -> &'static str {
&self.get()[0..chunk]
}
}
}
#[faux::methods]
impl bar::Bar {
pub fn add(&self) -> i32 {
self.get() + bar::Bar::num()
}
}
#[test]
fn real() {
use crate::bar::Bar;
use crate::foo::Foo;
let foo = Foo::other_new();
assert_eq!(foo.get_chunk(1), "h");
let bar = Bar::new();
assert_eq!(bar.add(), 14);
}
#[test]
fn mocked() {
use crate::{bar::Bar, foo::Foo};
let mut foo = Foo::faux();
faux::when!(foo.get_chunk).then(|_| "hello");
assert_eq!(foo.get_chunk(1), "hello");
let mut bar = Bar::faux();
faux::when!(bar.add).then(|_| 3);
assert_eq!(bar.add(), 3);
}