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