-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved
riddle
syntax parsing and testing (#2324)
- Loading branch information
Showing
12 changed files
with
282 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,21 @@ | ||
use std::process::Command; | ||
|
||
pub fn run_riddle(input: &str) -> String { | ||
let mut command = Command::new("cargo.exe"); | ||
command.arg("install").arg("--path").arg("../../tools/riddle"); | ||
|
||
if !command.status().unwrap().success() { | ||
panic!("Failed to install riddle"); | ||
} | ||
|
||
let output = std::env::temp_dir().join(std::path::Path::new(input).with_extension("winmd").file_name().expect("file_name failed")).to_string_lossy().into_owned(); | ||
|
||
let mut command = Command::new("riddle.exe"); | ||
command.arg("-input").arg(input).arg("-output").arg(&output); | ||
|
||
if !command.status().unwrap().success() { | ||
panic!("Failed to run riddle"); | ||
} | ||
|
||
output | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mod TypeNamespace { | ||
enum TypeName { | ||
A, | ||
B, | ||
C = 42, | ||
D, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use test_riddle::run_riddle; | ||
use windows_metadata::reader::*; | ||
|
||
#[test] | ||
fn riddle_enum() { | ||
let output = run_riddle("tests/enum.idl"); | ||
let files = File::with_default(&[&output]).expect("Failed to open winmd files"); | ||
let reader = &Reader::new(&files); | ||
|
||
let def = reader.get(TypeName::new("TypeNamespace", "TypeName")).next().expect("Type missing"); | ||
assert_eq!(reader.type_def_kind(def), TypeKind::Enum); | ||
|
||
let fields: Vec<Field> = reader.type_def_fields(def).collect(); | ||
assert_eq!(fields.len(), 5); | ||
assert_eq!(reader.field_name(fields[0]), "value__"); | ||
|
||
assert_eq!(reader.field_name(fields[1]), "A"); | ||
assert_eq!(reader.field_name(fields[2]), "B"); | ||
assert_eq!(reader.field_name(fields[3]), "C"); | ||
assert_eq!(reader.field_name(fields[4]), "D"); | ||
|
||
assert!(matches!(reader.constant_value(reader.field_constant(fields[1]).expect("missing constant")), Value::I32(value) if value == 0)); | ||
assert!(matches!(reader.constant_value(reader.field_constant(fields[2]).expect("missing constant")), Value::I32(value) if value == 1)); | ||
assert!(matches!(reader.constant_value(reader.field_constant(fields[3]).expect("missing constant")), Value::I32(value) if value == 42)); | ||
assert!(matches!(reader.constant_value(reader.field_constant(fields[4]).expect("missing constant")), Value::I32(value) if value == 43)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mod TypeNamespace { | ||
struct TypeName{ | ||
a: i32, | ||
b: f32, | ||
c: u64, | ||
d: f64, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use test_riddle::run_riddle; | ||
use windows_metadata::reader::*; | ||
|
||
#[test] | ||
fn riddle_struct() { | ||
let output = run_riddle("tests/struct.idl"); | ||
let files = File::with_default(&[&output]).expect("Failed to open winmd files"); | ||
let reader = &Reader::new(&files); | ||
|
||
let def = reader.get(TypeName::new("TypeNamespace", "TypeName")).next().expect("Type missing"); | ||
assert_eq!(reader.type_def_kind(def), TypeKind::Struct); | ||
|
||
let fields: Vec<Field> = reader.type_def_fields(def).collect(); | ||
assert_eq!(fields.len(), 4); | ||
|
||
assert_eq!(reader.field_name(fields[0]), "a"); | ||
assert_eq!(reader.field_name(fields[1]), "b"); | ||
assert_eq!(reader.field_name(fields[2]), "c"); | ||
assert_eq!(reader.field_name(fields[3]), "d"); | ||
|
||
assert!(matches!(reader.field_type(fields[0], None), Type::I32)); | ||
assert!(matches!(reader.field_type(fields[1], None), Type::F32)); | ||
assert!(matches!(reader.field_type(fields[2], None), Type::U64)); | ||
assert!(matches!(reader.field_type(fields[3], None), Type::F64)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.