Debian Codegraph @

src/tests/key.rs

raw symbols SCIP
1 //! Test keys other than String.
2
3 use superrust-analyzer cargo strfmt 0.2.4 tests/::superrust-analyzer cargo strfmt 0.2.4 crate/::*;
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#;
6
7 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
8 fn test_key_u32rust-analyzer cargo strfmt 0.2.4 tests/key/test_key_u32().() {
9 let mut vars: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<u32, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().();
10 vars.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(0, "X".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
11
12 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("hi {0}".formatrust-analyzer cargo strfmt 0.2.4 impl#[str][Format]format().(&vars).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "hi X");
13 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("hi {0}".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().formatrust-analyzer cargo strfmt 0.2.4 impl#[String][Format]format().(&vars).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "hi X");
14 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
15 "hi {1}".formatrust-analyzer cargo strfmt 0.2.4 impl#[str][Format]format().(&vars),
16 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#::KeyErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#KeyError#("Invalid key: 1".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))
17 );
18 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
19 "hi {you}".formatrust-analyzer cargo strfmt 0.2.4 impl#[str][Format]format().(&vars),
20 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#::KeyErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#KeyError#("Invalid key: you".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))
21 );
22 }
23
24 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
25 fn test_key_i32rust-analyzer cargo strfmt 0.2.4 tests/key/test_key_i32().() {
26 let mut vars: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<i32, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().();
27 vars.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1, "X".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
28
29 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("hi {-1}".formatrust-analyzer cargo strfmt 0.2.4 impl#[str][Format]format().(&vars).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "hi X");
30 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("hi {-1}".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().formatrust-analyzer cargo strfmt 0.2.4 impl#[String][Format]format().(&vars).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "hi X");
31 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
32 "hi {1}".formatrust-analyzer cargo strfmt 0.2.4 impl#[str][Format]format().(&vars),
33 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#::KeyErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#KeyError#("Invalid key: 1".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))
34 );
35 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
36 "hi {you}".formatrust-analyzer cargo strfmt 0.2.4 impl#[str][Format]format().(&vars),
37 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#::KeyErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#KeyError#("Invalid key: you".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))
38 );
39 }
40
41 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)]
42 enum Keyrust-analyzer cargo strfmt 0.2.4 tests/key/Key# {
43 Zerorust-analyzer cargo strfmt 0.2.4 tests/key/Key#Zero#,
44 Onerust-analyzer cargo strfmt 0.2.4 tests/key/Key#One#,
45 Tworust-analyzer cargo strfmt 0.2.4 tests/key/Key#Two#,
46 }
47
48 impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for Keyrust-analyzer cargo strfmt 0.2.4 tests/key/Key# {
49 type Errrust-analyzer cargo strfmt 0.2.4 tests/key/impl#[Key][FromStr]Err# = FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#;
50
51 fn from_strrust-analyzer cargo strfmt 0.2.4 tests/key/impl#[Key][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo strfmt 0.2.4 types/Result#<Selfrust-analyzer cargo strfmt 0.2.4 tests/key/impl#[Key][FromStr]> {
52 match s {
53 "Zero" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Keyrust-analyzer cargo strfmt 0.2.4 tests/key/Key#::Zerorust-analyzer cargo strfmt 0.2.4 tests/key/Key#Zero#),
54 "One" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Keyrust-analyzer cargo strfmt 0.2.4 tests/key/Key#::Onerust-analyzer cargo strfmt 0.2.4 tests/key/Key#One#),
55 "Two" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Keyrust-analyzer cargo strfmt 0.2.4 tests/key/Key#::Tworust-analyzer cargo strfmt 0.2.4 tests/key/Key#Two#),
56 _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#::KeyErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#KeyError#(s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())),
57 }
58 }
59 }
60
61 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
62 fn test_key_enumrust-analyzer cargo strfmt 0.2.4 tests/key/test_key_enum().() {
63 let mut vars: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Keyrust-analyzer cargo strfmt 0.2.4 tests/key/Key#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().();
64 vars.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(Keyrust-analyzer cargo strfmt 0.2.4 tests/key/Key#::Zerorust-analyzer cargo strfmt 0.2.4 tests/key/Key#Zero#, "X".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
65
66 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("hi {Zero}".formatrust-analyzer cargo strfmt 0.2.4 impl#[str][Format]format().(&vars).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "hi X");
67 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("hi {Zero}".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().formatrust-analyzer cargo strfmt 0.2.4 impl#[String][Format]format().(&vars).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "hi X");
68 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
69 "hi {One}".formatrust-analyzer cargo strfmt 0.2.4 impl#[str][Format]format().(&vars),
70 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#::KeyErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#KeyError#("Invalid key: One".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))
71 );
72 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
73 "hi {you}".formatrust-analyzer cargo strfmt 0.2.4 impl#[str][Format]format().(&vars),
74 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#::KeyErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#KeyError#("Invalid key: you".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))
75 );
76 }