]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-fulldeps/issue-2804.rs
Auto merge of #61212 - alexcrichton:skip-rustc, r=pietroalbini
[rust.git] / src / test / run-pass-fulldeps / issue-2804.rs
1 #![allow(non_camel_case_types)]
2 #![allow(dead_code)]
3 #![feature(rustc_private)]
4
5 extern crate serialize;
6
7 use std::collections::HashMap;
8 use serialize::json::{self, Json};
9 use std::option;
10
11 enum object {
12     bool_value(bool),
13     int_value(i64),
14 }
15
16 fn lookup(table: json::Object, key: String, default: String) -> String
17 {
18     match table.get(&key) {
19         option::Option::Some(&Json::String(ref s)) => {
20             s.to_string()
21         }
22         option::Option::Some(value) => {
23             println!("{} was expected to be a string but is a {}", key, value);
24             default
25         }
26         option::Option::None => {
27             default
28         }
29     }
30 }
31
32 fn add_interface(_store: isize, managed_ip: String, data: json::Json) -> (String, object)
33 {
34     match &data {
35         &Json::Object(ref interface) => {
36             let name = lookup(interface.clone(),
37                               "ifDescr".to_string(),
38                               "".to_string());
39             let label = format!("{}-{}", managed_ip, name);
40
41             (label, object::bool_value(false))
42         }
43         _ => {
44             println!("Expected dict for {} interfaces, found {}", managed_ip, data);
45             ("gnos:missing-interface".to_string(), object::bool_value(true))
46         }
47     }
48 }
49
50 fn add_interfaces(store: isize, managed_ip: String, device: HashMap<String, json::Json>)
51 -> Vec<(String, object)> {
52     match device["interfaces"] {
53         Json::Array(ref interfaces) =>
54         {
55           interfaces.iter().map(|interface| {
56                 add_interface(store, managed_ip.clone(), (*interface).clone())
57           }).collect()
58         }
59         _ =>
60         {
61             println!("Expected list for {} interfaces, found {}", managed_ip,
62                      device["interfaces"]);
63             Vec::new()
64         }
65     }
66 }
67
68 pub fn main() {}