]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass-fulldeps/issue-2804.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(rustc_private)]
13 extern crate serialize
;
15 use std
::collections
::HashMap
;
16 use serialize
::json
::{self, Json}
;
24 fn lookup(table
: json
::Object
, key
: String
, default: String
) -> String
26 match table
.get(&key
) {
27 option
::Option
::Some(&Json
::String(ref s
)) => {
30 option
::Option
::Some(value
) => {
31 println
!("{} was expected to be a string but is a {}", key
, value
);
34 option
::Option
::None
=> {
40 fn add_interface(_store
: isize, managed_ip
: String
, data
: json
::Json
) -> (String
, object
)
43 &Json
::Object(ref interface
) => {
44 let name
= lookup(interface
.clone(),
45 "ifDescr".to_string(),
47 let label
= format
!("{}-{}", managed_ip
, name
);
49 (label
, object
::bool_value(false))
52 println
!("Expected dict for {} interfaces, found {}", managed_ip
, data
);
53 ("gnos:missing-interface".to_string(), object
::bool_value(true))
58 fn add_interfaces(store
: isize, managed_ip
: String
, device
: HashMap
<String
, json
::Json
>)
59 -> Vec
<(String
, object
)> {
60 match device
["interfaces"] {
61 Json
::Array(ref interfaces
) =>
63 interfaces
.iter().map(|interface
| {
64 add_interface(store
, managed_ip
.clone(), (*interface
).clone())
69 println
!("Expected list for {} interfaces, found {}", managed_ip
,
70 device
["interfaces"]);