parse_qapi 0.1.2

A library to parser qemu's json like QAPI. This uses a nom parser to parse the json and the descriptions. This library is used by the qemu-rust-generator project to build the library
Documentation
extern crate nom;
extern crate parse_qapi;

use std::fs::File;
use std::io::prelude::*;

#[test]
fn test_block() {
    let mut f = File::open("tests/block.json").unwrap();
    let mut buf = String::new();
    f.read_to_string(&mut buf).unwrap();
    // Sanitize input
    let buf = buf.replace("\'", "\"");

    let result = parse_qapi::parse_sections(buf.as_bytes());
    // println!("Block Result: {:?}", result);
    match result {
        nom::IResult::Done(left, qemu_sections) => {
            println!("Block leftover: {}", String::from_utf8_lossy(left));
            println!("Block Result: {:?}", qemu_sections);
        }
        nom::IResult::Incomplete(needed) => {
            println!("Incomplete: {:?}", needed);
        }
        nom::IResult::Error(e) => {
            println!("Error: {:?}", e);
        }
    }
}

#[test]
fn test_block_core() {
    let mut f = File::open("tests/block-core.json").unwrap();
    let mut buf = String::new();
    f.read_to_string(&mut buf).unwrap();
    // Sanitize input
    let buf = buf.replace("\'", "\"");

    let result = parse_qapi::parse_sections(buf.as_bytes());
    // println!("Block Result: {:?}", result);
    match result {
        nom::IResult::Done(left, qemu_sections) => {
            println!("Block leftover: {}", String::from_utf8_lossy(left));
            println!("Block Result: {:?}", qemu_sections);
        }
        nom::IResult::Incomplete(needed) => {
            println!("Incomplete: {:?}", needed);
        }
        nom::IResult::Error(e) => {
            println!("Error: {:?}", e);
        }
    }
}

#[test]
fn test_common() {
    let mut f = File::open("tests/common.json").unwrap();
    let mut buf = String::new();
    f.read_to_string(&mut buf).unwrap();
    // Sanitize input
    let buf = buf.replace("\'", "\"");

    let result = parse_qapi::parse_sections(buf.as_bytes());
    match result {
        nom::IResult::Done(left, qemu_sections) => {
            println!("Common leftover: {}", String::from_utf8_lossy(left));
            println!("Common Result: {:?}", qemu_sections);
        }
        nom::IResult::Incomplete(needed) => {
            println!("Incomplete: {:?}", needed);
        }
        nom::IResult::Error(e) => {
            println!("Error: {:?}", e);
        }
    }
    // println!("Common Result: {:?}", result);
}

#[test]
fn test_qapi() {
    let mut f = File::open("tests/qapi.json").unwrap();
    let mut buf = String::new();
    f.read_to_string(&mut buf).unwrap();
    // Sanitize input
    let buf = buf.replace("\'", "\"");

    let result = parse_qapi::parse_sections(buf.as_bytes());
    match result {
        nom::IResult::Done(left, qemu_sections) => {
            println!("QAPI leftover: {}", String::from_utf8_lossy(left));
            println!("QAPI Result: {:?}", qemu_sections);
        }
        nom::IResult::Incomplete(needed) => {
            println!("Incomplete: {:?}", needed);
        }
        nom::IResult::Error(e) => {
            println!("Error: {:?}", e);
        }
    }
    // println!("QAPI Result: {:?}", result);
}

#[test]
fn test_event() {
    let mut f = File::open("tests/event.json").unwrap();
    let mut buf = String::new();
    f.read_to_string(&mut buf).unwrap();
    // Sanitize input
    let buf = buf.replace("\'", "\"");

    let result = parse_qapi::parse_sections(buf.as_bytes());
    match result {
        nom::IResult::Done(left, qemu_sections) => {
            println!("Event leftover: {}", String::from_utf8_lossy(left));
            println!("Event Result: {:?}", qemu_sections);
        }
        nom::IResult::Incomplete(needed) => {
            println!("Incomplete: {:?}", needed);
        }
        nom::IResult::Error(e) => {
            println!("Error: {:?}", e);
        }
    }
    // println!("QAPI Result: {:?}", result);
}