-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from TennyZhuang/uitest
add a bunch of ui tests
- Loading branch information
Showing
14 changed files
with
554 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use ref_stable_lru::LruCache; | ||
use std::num::NonZeroUsize; | ||
|
||
fn main() { | ||
let mut cache: LruCache<&'static str, String> = LruCache::new(NonZeroUsize::new(3).unwrap()); | ||
|
||
let out = cache.scope(|mut handle, mut perm| { | ||
handle.put("a", "bb".to_string(), &mut perm); | ||
handle.put("b", "cc".to_string(), &mut perm); | ||
handle.put("c", "dd".to_string(), &mut perm); | ||
|
||
let futs = ["a", "b", "c"].iter().map(|k| { | ||
let v = handle.get(k, &perm).unwrap(); | ||
|
||
async { | ||
// Assert v is a reference. | ||
let v: &String = v; | ||
v.get(..1).unwrap().to_string() | ||
} | ||
}); | ||
|
||
let fut = async { | ||
let out = futures::future::join_all(futs).await; | ||
out.join(" ") | ||
}; | ||
|
||
futures::executor::block_on(fut) | ||
}); | ||
|
||
assert_eq!(out, "b c d".to_string()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use ref_stable_lru::LruCache; | ||
use std::num::NonZeroUsize; | ||
|
||
fn main() { | ||
let mut cache: LruCache<&'static str, String> = LruCache::new(NonZeroUsize::new(3).unwrap()); | ||
|
||
let out = cache.scope(|mut handle, mut perm| { | ||
handle.put("a", "b".to_string(), &mut perm); | ||
handle.put("b", "c".to_string(), &mut perm); | ||
handle.put("c", "d".to_string(), &mut perm); | ||
|
||
// Success here, since `x`, `y` and `z` actually borrowed `perm` instead of `handle`. | ||
let x = handle.get(&"a", &perm).unwrap().as_str(); | ||
let y = handle.get(&"b", &perm).unwrap().as_str(); | ||
let z = handle.get(&"c", &perm).unwrap().as_str(); | ||
[x, y, z].join(" ") | ||
}); | ||
|
||
assert_eq!(out, "b c d".to_string()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use ref_stable_lru::LruCache; | ||
use std::num::NonZeroUsize; | ||
|
||
fn main() { | ||
let mut cache: LruCache<&'static str, String> = LruCache::new(NonZeroUsize::new(2).unwrap()); | ||
|
||
let x = cache.get(&"a").unwrap().as_str(); | ||
// Should failed here, since `x` already mutually borrowed cache. | ||
let y = cache.get(&"b").unwrap().as_str(); | ||
let z = cache.get(&"c").unwrap().as_str(); | ||
[x, y, z].join(" "); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0499]: cannot borrow `cache` as mutable more than once at a time | ||
--> tests/ui/double-get-without-scope.rs:9:13 | ||
| | ||
7 | let x = cache.get(&"a").unwrap().as_str(); | ||
| ----- first mutable borrow occurs here | ||
8 | // Should failed here, since `x` already mutually borrowed cache. | ||
9 | let y = cache.get(&"b").unwrap().as_str(); | ||
| ^^^^^ second mutable borrow occurs here | ||
10 | let z = cache.get(&"c").unwrap().as_str(); | ||
11 | [x, y, z].join(" "); | ||
| - first borrow later used here | ||
|
||
error[E0499]: cannot borrow `cache` as mutable more than once at a time | ||
--> tests/ui/double-get-without-scope.rs:10:13 | ||
| | ||
7 | let x = cache.get(&"a").unwrap().as_str(); | ||
| ----- first mutable borrow occurs here | ||
... | ||
10 | let z = cache.get(&"c").unwrap().as_str(); | ||
| ^^^^^ second mutable borrow occurs here | ||
11 | [x, y, z].join(" "); | ||
| - first borrow later used here |
Oops, something went wrong.