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