]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-2804.rs
test: Make manual changes to deal with the fallout from removal of
[rust.git] / src / test / run-pass / issue-2804.rs
1 // ignore-fast
2
3 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
4 // file at the top-level directory of this distribution and at
5 // http://rust-lang.org/COPYRIGHT.
6 //
7 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 // option. This file may not be copied, modified, or distributed
11 // except according to those terms.
12
13 extern crate collections;
14 extern crate serialize;
15
16 use collections::HashMap;
17 use serialize::json;
18 use std::option;
19 use std::vec_ng::Vec;
20
21 enum object {
22     bool_value(bool),
23     int_value(i64),
24 }
25
26 fn lookup(table: ~json::Object, key: ~str, default: ~str) -> ~str
27 {
28     match table.find(&key) {
29         option::Some(&json::String(ref s)) => {
30             (*s).clone()
31         }
32         option::Some(value) => {
33             println!("{} was expected to be a string but is a {:?}", key, value);
34             default
35         }
36         option::None => {
37             default
38         }
39     }
40 }
41
42 fn add_interface(_store: int, managed_ip: ~str, data: json::Json) -> (~str, object)
43 {
44     match &data {
45         &json::Object(ref interface) => {
46             let name = lookup((*interface).clone(), ~"ifDescr", ~"");
47             let label = format!("{}-{}", managed_ip, name);
48
49             (label, bool_value(false))
50         }
51         _ => {
52             println!("Expected dict for {} interfaces but found {:?}", managed_ip, data);
53             (~"gnos:missing-interface", bool_value(true))
54         }
55     }
56 }
57
58 fn add_interfaces(store: int, managed_ip: ~str, device: HashMap<~str, json::Json>)
59 -> Vec<(~str, object)> {
60     match device.get(&~"interfaces")
61     {
62         &json::List(ref interfaces) =>
63         {
64           interfaces.iter().map(|interface| {
65                 add_interface(store, managed_ip.clone(), (*interface).clone())
66           }).collect()
67         }
68         _ =>
69         {
70             println!("Expected list for {} interfaces but found {:?}", managed_ip,
71                    device.get(&~"interfaces"));
72             Vec::new()
73         }
74     }
75 }
76
77 pub fn main() {}