Add a test
This commit is contained in:
		
							
								
								
									
										20
									
								
								examples/materials.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								examples/materials.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
{
 | 
			
		||||
	"materials": {
 | 
			
		||||
		"metal": {
 | 
			
		||||
			"reflectivity": 1.0
 | 
			
		||||
		},
 | 
			
		||||
		"plastic": {
 | 
			
		||||
			"reflectivity": 0.5
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
	"entities": [
 | 
			
		||||
		{
 | 
			
		||||
			"name": "hero",
 | 
			
		||||
			"material": "metal"
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			"name": "monster",
 | 
			
		||||
			"material": "plastic"
 | 
			
		||||
		}
 | 
			
		||||
	]
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										20
									
								
								examples/materials.ron
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								examples/materials.ron
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
Scene( // class name is optional
 | 
			
		||||
	materials: { // this is a map
 | 
			
		||||
		"metal": (
 | 
			
		||||
			reflectivity: 1.0,
 | 
			
		||||
		),
 | 
			
		||||
		"plastic": (
 | 
			
		||||
			reflectivity: 0.5,
 | 
			
		||||
		),
 | 
			
		||||
	},
 | 
			
		||||
	entities: [ // this is an array
 | 
			
		||||
		(
 | 
			
		||||
			name: "hero",
 | 
			
		||||
			material: "metal",
 | 
			
		||||
		),
 | 
			
		||||
		(
 | 
			
		||||
			name: "monster",
 | 
			
		||||
			material: "plastic",
 | 
			
		||||
		),
 | 
			
		||||
	],
 | 
			
		||||
)
 | 
			
		||||
@@ -2,7 +2,7 @@ use clap::{Parser, ValueEnum};
 | 
			
		||||
use serde::de::Deserializer;
 | 
			
		||||
use std::io::{Read, Write};
 | 
			
		||||
 | 
			
		||||
#[derive(Parser)]
 | 
			
		||||
#[derive(Debug, Parser)]
 | 
			
		||||
#[clap(author, version, about, long_about = None)]
 | 
			
		||||
pub struct Opt {
 | 
			
		||||
    /// Input type
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										36
									
								
								tests/integration.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								tests/integration.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
use tradaf::*;
 | 
			
		||||
 | 
			
		||||
fn example_to_vec(file: &str) -> Vec<u8> {
 | 
			
		||||
    use std::fs::File;
 | 
			
		||||
    use std::io::prelude::*;
 | 
			
		||||
 | 
			
		||||
    let mut f = File::open(file).unwrap();
 | 
			
		||||
    let mut buffer = vec![];
 | 
			
		||||
    f.read_to_end(&mut buffer).unwrap();
 | 
			
		||||
    buffer
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn example_to_string(file: &str) -> String {
 | 
			
		||||
    let buffer = example_to_vec(file);
 | 
			
		||||
    String::from_utf8(buffer).unwrap()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[test]
 | 
			
		||||
fn ron_to_json() {
 | 
			
		||||
    let opt = Opt {
 | 
			
		||||
        input: Input::Ron,
 | 
			
		||||
        output: Output::Json,
 | 
			
		||||
        pretty: true,
 | 
			
		||||
        no_newline: false,
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let input = example_to_vec("examples/materials.ron");
 | 
			
		||||
 | 
			
		||||
    let mut output = vec![];
 | 
			
		||||
    transcode(opt, &mut input.as_slice(), &mut output);
 | 
			
		||||
    let out = String::from_utf8(output).unwrap();
 | 
			
		||||
 | 
			
		||||
    let control = example_to_string("examples/materials.json");
 | 
			
		||||
 | 
			
		||||
    assert_eq!(control, out);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user