Newer
Older
use tiled::{Map, TiledError, PropertyValue, parse, parse_file, parse_tileset};
fn read_from_file(p: &Path) -> Result<Map, TiledError> {
let file = File::open(p).unwrap();

Doug Reeves
committed
fn read_from_file_with_path(p: &Path) -> Result<Map, TiledError> {
return parse_file(p);
}
#[test]
fn test_gzip_and_zlib_encoded_and_raw_are_the_same() {
let z = read_from_file(&Path::new("assets/tiled_base64_zlib.tmx")).unwrap();
let g = read_from_file(&Path::new("assets/tiled_base64_gzip.tmx")).unwrap();
let r = read_from_file(&Path::new("assets/tiled_base64.tmx")).unwrap();
let c = read_from_file(&Path::new("assets/tiled_csv.tmx")).unwrap();
assert_eq!(z, g);
assert_eq!(z, r);

Doug Reeves
committed
#[test]
fn test_external_tileset() {
let r = read_from_file(&Path::new("assets/tiled_base64.tmx")).unwrap();
let e = read_from_file_with_path(&Path::new("assets/tiled_base64_external.tmx")).unwrap();
assert_eq!(r, e);
}
#[test]
fn test_just_tileset() {
let r = read_from_file(&Path::new("assets/tiled_base64.tmx")).unwrap();
let t = parse_tileset(File::open(Path::new("assets/tilesheet.tsx")).unwrap(), 1).unwrap();
assert_eq!(r.tilesets[0], t);
}
#[test]
fn test_image_layers() {
let r = read_from_file(&Path::new("assets/tiled_image_layers.tmx")).unwrap();
assert_eq!(r.image_layers.len(), 2);
{
let first = &r.image_layers[0];
assert_eq!(first.name, "Image Layer 1");
assert!(first.image.is_none(), "{}'s image should be None", first.name);
}
{
let second = &r.image_layers[1];
assert_eq!(second.name, "Image Layer 2");
let image = second.image.as_ref().expect(&format!("{}'s image shouldn't be None", second.name));
assert_eq!(image.source, "tilesheet.png");
assert_eq!(image.width, 448);
assert_eq!(image.height, 192);
}
}
#[test]
fn test_tile_property() {
let r = read_from_file(&Path::new("assets/tiled_base64.tmx")).unwrap();
let prop_value: String = if let Some(&PropertyValue::StringValue(ref v)) = r.tilesets[0].tiles[0].properties.get("a tile property") {
v.clone()
} else {
String::new()
};
assert_eq!("123", prop_value);
}
#[test]
fn test_object_group_property() {
let r = read_from_file(&Path::new("assets/tiled_object_groups.tmx")).unwrap();
let prop_value: bool = if let Some(&PropertyValue::BoolValue(ref v)) = r.object_groups[0].properties.get("an object group property") {
*v
} else {
false
};
assert!(prop_value);
}