feat: add a histrical wit-bindgen
This commit is contained in:
344
__wasm/wit-bindgen-sample/wit-bindgen/crates/parser/tests/all.rs
Normal file
344
__wasm/wit-bindgen-sample/wit-bindgen/crates/parser/tests/all.rs
Normal file
@@ -0,0 +1,344 @@
|
||||
//! You can run this test suite with:
|
||||
//!
|
||||
//! cargo test --test all
|
||||
//!
|
||||
//! An argument can be passed as well to filter, based on filename, which test
|
||||
//! to run
|
||||
//!
|
||||
//! cargo test --test all foo.wit
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use rayon::prelude::*;
|
||||
use serde::Serialize;
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
|
||||
use wit_parser::*;
|
||||
|
||||
fn main() {
|
||||
let tests = find_tests();
|
||||
let filter = std::env::args().nth(1);
|
||||
|
||||
let tests = tests
|
||||
.par_iter()
|
||||
.filter_map(|test| {
|
||||
if let Some(filter) = &filter {
|
||||
if let Some(s) = test.to_str() {
|
||||
if !s.contains(filter) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
let contents = fs::read(test).unwrap();
|
||||
Some((test, contents))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
println!("running {} test files\n", tests.len());
|
||||
|
||||
let ntests = AtomicUsize::new(0);
|
||||
let errors = tests
|
||||
.par_iter()
|
||||
.filter_map(|(test, contents)| {
|
||||
Runner { ntests: &ntests }
|
||||
.run(test, contents)
|
||||
.context(format!("test {:?} failed", test))
|
||||
.err()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if !errors.is_empty() {
|
||||
for msg in errors.iter() {
|
||||
eprintln!("{:?}", msg);
|
||||
}
|
||||
|
||||
panic!("{} tests failed", errors.len())
|
||||
}
|
||||
|
||||
println!(
|
||||
"test result: ok. {} directives passed\n",
|
||||
ntests.load(SeqCst)
|
||||
);
|
||||
}
|
||||
|
||||
/// Recursively finds all tests in a whitelisted set of directories which we
|
||||
/// then load up and test in parallel.
|
||||
fn find_tests() -> Vec<PathBuf> {
|
||||
let mut tests = Vec::new();
|
||||
find_tests("tests/ui".as_ref(), &mut tests);
|
||||
tests.sort();
|
||||
return tests;
|
||||
|
||||
fn find_tests(path: &Path, tests: &mut Vec<PathBuf>) {
|
||||
for f in path.read_dir().unwrap() {
|
||||
let f = f.unwrap();
|
||||
if f.file_type().unwrap().is_dir() {
|
||||
find_tests(&f.path(), tests);
|
||||
continue;
|
||||
}
|
||||
|
||||
match f.path().extension().and_then(|s| s.to_str()) {
|
||||
Some("md") => {}
|
||||
Some("wit") => {}
|
||||
_ => continue,
|
||||
}
|
||||
tests.push(f.path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Runner<'a> {
|
||||
ntests: &'a AtomicUsize,
|
||||
}
|
||||
|
||||
impl Runner<'_> {
|
||||
fn run(&mut self, test: &Path, contents: &[u8]) -> Result<()> {
|
||||
let contents = str::from_utf8(contents)?;
|
||||
|
||||
let result = Interface::parse_file(test);
|
||||
|
||||
let result = if contents.contains("// parse-fail") {
|
||||
match result {
|
||||
Ok(_) => bail!("expected test to not parse but it did"),
|
||||
Err(mut e) => {
|
||||
if let Some(err) = e.downcast_mut::<io::Error>() {
|
||||
*err = io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"some generic platform-agnostic error message",
|
||||
);
|
||||
}
|
||||
normalize(test, &format!("{:?}", e))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let instance = result?;
|
||||
to_json(&instance)
|
||||
};
|
||||
|
||||
// "foo.wit" => "foo.wit.result"
|
||||
// "foo.wit.md" => "foo.wit.md.result"
|
||||
let result_file = if test.extension() == Some(OsStr::new("md"))
|
||||
&& test
|
||||
.file_stem()
|
||||
.and_then(|path| Path::new(path).extension())
|
||||
== Some(OsStr::new("wit"))
|
||||
{
|
||||
test.with_extension("md.result")
|
||||
} else {
|
||||
test.with_extension("wit.result")
|
||||
};
|
||||
if env::var_os("BLESS").is_some() {
|
||||
fs::write(&result_file, result)?;
|
||||
} else {
|
||||
let expected = fs::read_to_string(&result_file).context(format!(
|
||||
"failed to read test expectation file {:?}\nthis can be fixed with BLESS=1",
|
||||
result_file
|
||||
))?;
|
||||
let expected = normalize(test, &expected);
|
||||
if expected != result {
|
||||
bail!(
|
||||
"failed test: expected `{:?}` but found `{:?}`",
|
||||
expected,
|
||||
result
|
||||
);
|
||||
}
|
||||
}
|
||||
self.bump_ntests();
|
||||
return Ok(());
|
||||
|
||||
fn normalize(test: &Path, s: &str) -> String {
|
||||
s.replace(
|
||||
&test.display().to_string(),
|
||||
&test.display().to_string().replace("\\", "/"),
|
||||
)
|
||||
.replace("\\parse-fail\\", "/parse-fail/")
|
||||
.replace("\r\n", "\n")
|
||||
}
|
||||
}
|
||||
|
||||
fn bump_ntests(&self) {
|
||||
self.ntests.fetch_add(1, SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
fn to_json(i: &Interface) -> String {
|
||||
#[derive(Serialize)]
|
||||
struct Interface {
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
resources: Vec<Resource>,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
types: Vec<TypeDef>,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
functions: Vec<Function>,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
globals: Vec<Global>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Resource {
|
||||
name: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
supertype: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
foreign_module: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct TypeDef {
|
||||
idx: usize,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
name: Option<String>,
|
||||
#[serde(flatten)]
|
||||
ty: Type,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
foreign_module: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
enum Type {
|
||||
Primitive(String),
|
||||
Record { fields: Vec<(String, String)> },
|
||||
Flags { flags: Vec<String> },
|
||||
Enum { cases: Vec<String> },
|
||||
Variant { cases: Vec<(String, String)> },
|
||||
Tuple { types: Vec<String> },
|
||||
Option(String),
|
||||
Expected { ok: String, err: String },
|
||||
Future(String),
|
||||
Stream { element: String, end: String },
|
||||
List(String),
|
||||
Union { cases: Vec<String> },
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Function {
|
||||
name: String,
|
||||
#[serde(rename = "async", skip_serializing_if = "Option::is_none")]
|
||||
is_async: Option<bool>,
|
||||
params: Vec<String>,
|
||||
result: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Global {
|
||||
name: String,
|
||||
ty: String,
|
||||
}
|
||||
|
||||
let resources = i
|
||||
.resources
|
||||
.iter()
|
||||
.map(|(_, r)| Resource {
|
||||
name: r.name.clone(),
|
||||
supertype: r.supertype.as_ref().map(|supertype| supertype.clone()),
|
||||
foreign_module: r.foreign_module.clone(),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let types = i
|
||||
.types
|
||||
.iter()
|
||||
.map(|(i, r)| TypeDef {
|
||||
idx: i.index(),
|
||||
name: r.name.clone(),
|
||||
ty: translate_typedef(r),
|
||||
foreign_module: r.foreign_module.clone(),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let functions = i
|
||||
.functions
|
||||
.iter()
|
||||
.map(|f| Function {
|
||||
name: f.name.clone(),
|
||||
is_async: if f.is_async { Some(f.is_async) } else { None },
|
||||
params: f.params.iter().map(|(_, ty)| translate_type(ty)).collect(),
|
||||
result: translate_type(&f.result),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let globals = i
|
||||
.globals
|
||||
.iter()
|
||||
.map(|g| Global {
|
||||
name: g.name.clone(),
|
||||
ty: translate_type(&g.ty),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let iface = Interface {
|
||||
resources,
|
||||
types,
|
||||
functions,
|
||||
globals,
|
||||
};
|
||||
return serde_json::to_string_pretty(&iface).unwrap();
|
||||
|
||||
fn translate_typedef(ty: &wit_parser::TypeDef) -> Type {
|
||||
match &ty.kind {
|
||||
TypeDefKind::Type(t) => Type::Primitive(translate_type(t)),
|
||||
TypeDefKind::Record(r) => Type::Record {
|
||||
fields: r
|
||||
.fields
|
||||
.iter()
|
||||
.map(|f| (f.name.clone(), translate_type(&f.ty)))
|
||||
.collect(),
|
||||
},
|
||||
TypeDefKind::Tuple(t) => Type::Tuple {
|
||||
types: t.types.iter().map(|ty| translate_type(ty)).collect(),
|
||||
},
|
||||
TypeDefKind::Flags(r) => Type::Flags {
|
||||
flags: r.flags.iter().map(|f| f.name.clone()).collect(),
|
||||
},
|
||||
TypeDefKind::Enum(r) => Type::Enum {
|
||||
cases: r.cases.iter().map(|f| f.name.clone()).collect(),
|
||||
},
|
||||
TypeDefKind::Variant(v) => Type::Variant {
|
||||
cases: v
|
||||
.cases
|
||||
.iter()
|
||||
.map(|f| (f.name.clone(), translate_type(&f.ty)))
|
||||
.collect(),
|
||||
},
|
||||
TypeDefKind::Option(t) => Type::Option(translate_type(t)),
|
||||
TypeDefKind::Expected(e) => Type::Expected {
|
||||
ok: translate_type(&e.ok),
|
||||
err: translate_type(&e.err),
|
||||
},
|
||||
TypeDefKind::Future(t) => Type::Future(translate_type(t)),
|
||||
TypeDefKind::Stream(s) => Type::Stream {
|
||||
element: translate_type(&s.element),
|
||||
end: translate_type(&s.end),
|
||||
},
|
||||
TypeDefKind::List(ty) => Type::List(translate_type(ty)),
|
||||
TypeDefKind::Union(u) => Type::Union {
|
||||
cases: u.cases.iter().map(|c| translate_type(&c.ty)).collect(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn translate_type(ty: &wit_parser::Type) -> String {
|
||||
use wit_parser::Type;
|
||||
match ty {
|
||||
Type::Unit => format!("unit"),
|
||||
Type::Bool => format!("bool"),
|
||||
Type::U8 => format!("u8"),
|
||||
Type::U16 => format!("u16"),
|
||||
Type::U32 => format!("u32"),
|
||||
Type::U64 => format!("u64"),
|
||||
Type::S8 => format!("s8"),
|
||||
Type::S16 => format!("s16"),
|
||||
Type::S32 => format!("s32"),
|
||||
Type::S64 => format!("s64"),
|
||||
Type::Float32 => format!("float32"),
|
||||
Type::Float64 => format!("float64"),
|
||||
Type::Char => format!("char"),
|
||||
Type::String => format!("string"),
|
||||
Type::Handle(resource) => format!("handle-{}", resource.index()),
|
||||
Type::Id(id) => format!("type-{}", id.index()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
a: async func()
|
||||
b: async func(x: s32)
|
||||
c: async func() -> u32
|
||||
|
||||
resource y {
|
||||
a: async func()
|
||||
b: async func(x: s32)
|
||||
c: async func() -> u32
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"resources": [
|
||||
{
|
||||
"name": "y"
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
{
|
||||
"idx": 0,
|
||||
"primitive": "handle-0"
|
||||
}
|
||||
],
|
||||
"functions": [
|
||||
{
|
||||
"name": "a",
|
||||
"async": true,
|
||||
"params": [],
|
||||
"result": "unit"
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"async": true,
|
||||
"params": [
|
||||
"s32"
|
||||
],
|
||||
"result": "unit"
|
||||
},
|
||||
{
|
||||
"name": "c",
|
||||
"async": true,
|
||||
"params": [],
|
||||
"result": "u32"
|
||||
},
|
||||
{
|
||||
"name": "y::a",
|
||||
"async": true,
|
||||
"params": [
|
||||
"handle-0"
|
||||
],
|
||||
"result": "unit"
|
||||
},
|
||||
{
|
||||
"name": "y::b",
|
||||
"async": true,
|
||||
"params": [
|
||||
"handle-0",
|
||||
"s32"
|
||||
],
|
||||
"result": "unit"
|
||||
},
|
||||
{
|
||||
"name": "y::c",
|
||||
"async": true,
|
||||
"params": [
|
||||
"handle-0"
|
||||
],
|
||||
"result": "u32"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// hello
|
||||
// world
|
||||
// why, yes
|
||||
// this is a comment
|
||||
/* this too */ /* is a comment */
|
||||
/* this /* is /* a */ nested */ comment */
|
||||
|
||||
|
||||
type /* foo */ bar /* baz */ = //
|
||||
handle //
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
x
|
||||
|
||||
resource /* x */ x // ...
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"resources": [
|
||||
{
|
||||
"name": "x"
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
{
|
||||
"idx": 0,
|
||||
"name": "bar",
|
||||
"primitive": "handle-0"
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"primitive": "handle-0"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
# A Markdown file!
|
||||
|
||||
containing stuff, and also some code blocks, wit and other.
|
||||
|
||||
```wit
|
||||
x: func()
|
||||
```
|
||||
|
||||
Intervening content, including a non-wit codeblock:
|
||||
```js
|
||||
function func() {}
|
||||
```
|
||||
|
||||
```wit
|
||||
y: func()
|
||||
```
|
||||
|
||||
## A new section
|
||||
|
||||
In which, another wit code block!
|
||||
|
||||
```wit
|
||||
z: func()
|
||||
```
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"functions": [
|
||||
{
|
||||
"name": "x",
|
||||
"params": [],
|
||||
"result": "unit"
|
||||
},
|
||||
{
|
||||
"name": "y",
|
||||
"params": [],
|
||||
"result": "unit"
|
||||
},
|
||||
{
|
||||
"name": "z",
|
||||
"params": [],
|
||||
"result": "unit"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1,7 @@
|
||||
f1: func()
|
||||
f2: func(a: u32)
|
||||
f3: func(a: u32,)
|
||||
f4: func() -> u32
|
||||
f6: func() -> tuple<u32, u32>
|
||||
f7: func(a: float32, b: float32) -> tuple<u32, u32>
|
||||
f8: func(a: option<u32>) -> expected<u32, float32>
|
||||
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"types": [
|
||||
{
|
||||
"idx": 0,
|
||||
"tuple": {
|
||||
"types": [
|
||||
"u32",
|
||||
"u32"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"option": "u32"
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"expected": {
|
||||
"ok": "u32",
|
||||
"err": "float32"
|
||||
}
|
||||
}
|
||||
],
|
||||
"functions": [
|
||||
{
|
||||
"name": "f1",
|
||||
"params": [],
|
||||
"result": "unit"
|
||||
},
|
||||
{
|
||||
"name": "f2",
|
||||
"params": [
|
||||
"u32"
|
||||
],
|
||||
"result": "unit"
|
||||
},
|
||||
{
|
||||
"name": "f3",
|
||||
"params": [
|
||||
"u32"
|
||||
],
|
||||
"result": "unit"
|
||||
},
|
||||
{
|
||||
"name": "f4",
|
||||
"params": [],
|
||||
"result": "u32"
|
||||
},
|
||||
{
|
||||
"name": "f6",
|
||||
"params": [],
|
||||
"result": "type-0"
|
||||
},
|
||||
{
|
||||
"name": "f7",
|
||||
"params": [
|
||||
"float32",
|
||||
"float32"
|
||||
],
|
||||
"result": "type-0"
|
||||
},
|
||||
{
|
||||
"name": "f8",
|
||||
"params": [
|
||||
"type-1"
|
||||
],
|
||||
"result": "type-2"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
# Title
|
||||
|
||||
This file is like import-me.wit, but it's a Markdown file with embedded wit
|
||||
code blocks.
|
||||
|
||||
## `foo`
|
||||
```wit
|
||||
/// This is foo.
|
||||
type foo = u32
|
||||
```
|
||||
|
||||
## `x`
|
||||
```wit
|
||||
/// This is x.
|
||||
resource x
|
||||
```
|
||||
|
||||
## `handle`
|
||||
```wit
|
||||
/// This is handle.
|
||||
type %handle = handle x
|
||||
```
|
||||
|
||||
## `some-record`
|
||||
```wit
|
||||
/// This is some-record.
|
||||
type some-record = tuple<u32, u64, float32>
|
||||
```
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"resources": [
|
||||
{
|
||||
"name": "x"
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
{
|
||||
"idx": 0,
|
||||
"name": "foo",
|
||||
"primitive": "u32"
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"primitive": "handle-0"
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"name": "handle",
|
||||
"primitive": "handle-0"
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"name": "some-record",
|
||||
"tuple": {
|
||||
"types": [
|
||||
"u32",
|
||||
"u64",
|
||||
"float32"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
type foo = u32
|
||||
|
||||
resource x
|
||||
|
||||
type %handle = handle x
|
||||
|
||||
type some-record = tuple<u32, u64, float32>
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"resources": [
|
||||
{
|
||||
"name": "x"
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
{
|
||||
"idx": 0,
|
||||
"name": "foo",
|
||||
"primitive": "u32"
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"primitive": "handle-0"
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"name": "handle",
|
||||
"primitive": "handle-0"
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"name": "some-record",
|
||||
"tuple": {
|
||||
"types": [
|
||||
"u32",
|
||||
"u64",
|
||||
"float32"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// This test is like imports.wit, but uses import-me-too, which is a markdown
|
||||
// file instead of a plain wit file.
|
||||
|
||||
use { foo } from import-me-too
|
||||
use { foo as bar } from import-me-too
|
||||
use { x as import-me-x } from import-me-too
|
||||
|
||||
type x = foo
|
||||
type y = bar
|
||||
type z1 = import-me-x
|
||||
type z2 = handle import-me-x
|
||||
|
||||
use { %handle } from import-me-too
|
||||
resource xyz
|
||||
type my-handle = handle xyz
|
||||
type my-handle2 = xyz
|
||||
|
||||
use { some-record } from import-me-too
|
||||
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"resources": [
|
||||
{
|
||||
"name": "x",
|
||||
"foreign_module": "import-me-too"
|
||||
},
|
||||
{
|
||||
"name": "xyz"
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
{
|
||||
"idx": 0,
|
||||
"name": "foo",
|
||||
"primitive": "u32",
|
||||
"foreign_module": "import-me-too"
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"primitive": "handle-0",
|
||||
"foreign_module": "import-me-too"
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"name": "handle",
|
||||
"primitive": "handle-0",
|
||||
"foreign_module": "import-me-too"
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"name": "some-record",
|
||||
"tuple": {
|
||||
"types": [
|
||||
"u32",
|
||||
"u64",
|
||||
"float32"
|
||||
]
|
||||
},
|
||||
"foreign_module": "import-me-too"
|
||||
},
|
||||
{
|
||||
"idx": 4,
|
||||
"name": "x",
|
||||
"primitive": "type-0"
|
||||
},
|
||||
{
|
||||
"idx": 5,
|
||||
"name": "y",
|
||||
"primitive": "type-0"
|
||||
},
|
||||
{
|
||||
"idx": 6,
|
||||
"name": "z1",
|
||||
"primitive": "type-1"
|
||||
},
|
||||
{
|
||||
"idx": 7,
|
||||
"name": "z2",
|
||||
"primitive": "handle-0"
|
||||
},
|
||||
{
|
||||
"idx": 8,
|
||||
"primitive": "handle-1"
|
||||
},
|
||||
{
|
||||
"idx": 9,
|
||||
"name": "my-handle",
|
||||
"primitive": "handle-1"
|
||||
},
|
||||
{
|
||||
"idx": 10,
|
||||
"name": "my-handle2",
|
||||
"primitive": "type-8"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
use { foo } from import-me
|
||||
use { foo as bar } from import-me
|
||||
use { x as import-me-x } from import-me
|
||||
|
||||
type x = foo
|
||||
type y = bar
|
||||
type z1 = import-me-x
|
||||
type z2 = handle import-me-x
|
||||
|
||||
use { %handle } from import-me
|
||||
resource xyz
|
||||
type my-handle = handle xyz
|
||||
type my-handle2 = xyz
|
||||
|
||||
use { some-record } from import-me
|
||||
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"resources": [
|
||||
{
|
||||
"name": "x",
|
||||
"foreign_module": "import-me"
|
||||
},
|
||||
{
|
||||
"name": "xyz"
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
{
|
||||
"idx": 0,
|
||||
"name": "foo",
|
||||
"primitive": "u32",
|
||||
"foreign_module": "import-me"
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"primitive": "handle-0",
|
||||
"foreign_module": "import-me"
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"name": "handle",
|
||||
"primitive": "handle-0",
|
||||
"foreign_module": "import-me"
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"name": "some-record",
|
||||
"tuple": {
|
||||
"types": [
|
||||
"u32",
|
||||
"u64",
|
||||
"float32"
|
||||
]
|
||||
},
|
||||
"foreign_module": "import-me"
|
||||
},
|
||||
{
|
||||
"idx": 4,
|
||||
"name": "x",
|
||||
"primitive": "type-0"
|
||||
},
|
||||
{
|
||||
"idx": 5,
|
||||
"name": "y",
|
||||
"primitive": "type-0"
|
||||
},
|
||||
{
|
||||
"idx": 6,
|
||||
"name": "z1",
|
||||
"primitive": "type-1"
|
||||
},
|
||||
{
|
||||
"idx": 7,
|
||||
"name": "z2",
|
||||
"primitive": "handle-0"
|
||||
},
|
||||
{
|
||||
"idx": 8,
|
||||
"primitive": "handle-1"
|
||||
},
|
||||
{
|
||||
"idx": 9,
|
||||
"name": "my-handle",
|
||||
"primitive": "handle-1"
|
||||
},
|
||||
{
|
||||
"idx": 10,
|
||||
"name": "my-handle2",
|
||||
"primitive": "type-8"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
use * from import-me
|
||||
|
||||
type my-handle = handle x
|
||||
type my-handle2 = x
|
||||
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"resources": [
|
||||
{
|
||||
"name": "x",
|
||||
"foreign_module": "import-me"
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
{
|
||||
"idx": 0,
|
||||
"name": "foo",
|
||||
"primitive": "u32",
|
||||
"foreign_module": "import-me"
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"name": "handle",
|
||||
"primitive": "handle-0",
|
||||
"foreign_module": "import-me"
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"name": "some-record",
|
||||
"tuple": {
|
||||
"types": [
|
||||
"u32",
|
||||
"u64",
|
||||
"float32"
|
||||
]
|
||||
},
|
||||
"foreign_module": "import-me"
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"primitive": "handle-0",
|
||||
"foreign_module": "import-me"
|
||||
},
|
||||
{
|
||||
"idx": 4,
|
||||
"name": "my-handle",
|
||||
"primitive": "handle-0"
|
||||
},
|
||||
{
|
||||
"idx": 5,
|
||||
"name": "my-handle2",
|
||||
"primitive": "type-3"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
a: async
|
||||
@@ -0,0 +1,5 @@
|
||||
expected keyword `func`, found eof
|
||||
--> tests/ui/parse-fail/async.wit:3:1
|
||||
|
|
||||
3 |
|
||||
| ^
|
||||
@@ -0,0 +1,3 @@
|
||||
// parse-fail
|
||||
a: async()
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
expected keyword `func`, found '('
|
||||
--> tests/ui/parse-fail/async1.wit:2:9
|
||||
|
|
||||
2 | a: async()
|
||||
| ^
|
||||
@@ -0,0 +1,5 @@
|
||||
// parse-fail
|
||||
|
||||
type x = list<u32
|
||||
|
||||
type y = u32
|
||||
@@ -0,0 +1,5 @@
|
||||
expected '>', found keyword `type`
|
||||
--> tests/ui/parse-fail/bad-list.wit:5:1
|
||||
|
|
||||
5 | type y = u32
|
||||
| ^
|
||||
@@ -0,0 +1,5 @@
|
||||
// parse-fail
|
||||
|
||||
resource x {
|
||||
x: s32
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
globals not allowed in resources
|
||||
--> tests/ui/parse-fail/bad-resource.wit:4:3
|
||||
|
|
||||
4 | x: s32
|
||||
| ^
|
||||
@@ -0,0 +1,6 @@
|
||||
// parse-fail
|
||||
|
||||
resource x {
|
||||
x: func()
|
||||
x: func()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
"x" defined twice in this resource
|
||||
--> tests/ui/parse-fail/bad-resource2.wit:5:3
|
||||
|
|
||||
5 | x: func()
|
||||
| ^
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
use {} from foo
|
||||
@@ -0,0 +1,5 @@
|
||||
expected an identifier or string, found '}'
|
||||
--> tests/ui/parse-fail/bad-use.wit:2:6
|
||||
|
|
||||
2 | use {} from foo
|
||||
| ^
|
||||
@@ -0,0 +1,4 @@
|
||||
// parse-fail
|
||||
use { a } from
|
||||
|
||||
type foo = u32
|
||||
@@ -0,0 +1,5 @@
|
||||
expected an identifier or string, found keyword `type`
|
||||
--> tests/ui/parse-fail/bad-use2.wit:4:1
|
||||
|
|
||||
4 | type foo = u32
|
||||
| ^---
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
use * from type
|
||||
@@ -0,0 +1,5 @@
|
||||
expected an identifier or string, found keyword `type`
|
||||
--> tests/ui/parse-fail/bad-use3.wit:2:12
|
||||
|
|
||||
2 | use * from type
|
||||
| ^---
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
use { foo } from bar:
|
||||
@@ -0,0 +1,5 @@
|
||||
expected ':', found whitespace
|
||||
--> tests/ui/parse-fail/bad-use4.wit:2:22
|
||||
|
|
||||
2 | use { foo } from bar:
|
||||
| ^
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
use { foo } from bar:baz
|
||||
@@ -0,0 +1,5 @@
|
||||
expected ':', found an identifier
|
||||
--> tests/ui/parse-fail/bad-use5.wit:2:22
|
||||
|
|
||||
2 | use { foo } from bar:baz
|
||||
| ^
|
||||
@@ -0,0 +1,3 @@
|
||||
// parse-fail
|
||||
|
||||
use { foo } from import-me::bar
|
||||
@@ -0,0 +1,5 @@
|
||||
`bar` not defined in `import-me`
|
||||
--> tests/ui/parse-fail/bad-use6.wit:3:29
|
||||
|
|
||||
3 | use { foo } from import-me::bar
|
||||
| ^--
|
||||
@@ -0,0 +1,3 @@
|
||||
// parse-fail
|
||||
|
||||
use from import-me
|
||||
@@ -0,0 +1,5 @@
|
||||
expected '{', found keyword `from`
|
||||
--> tests/ui/parse-fail/bad-use7.wit:3:5
|
||||
|
|
||||
3 | use from import-me
|
||||
| ^
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
type foo = foo
|
||||
@@ -0,0 +1,5 @@
|
||||
type can recursively refer to itself
|
||||
--> tests/ui/parse-fail/cycle.wit:2:6
|
||||
|
|
||||
2 | type foo = foo
|
||||
| ^--
|
||||
@@ -0,0 +1,3 @@
|
||||
// parse-fail
|
||||
type foo = bar
|
||||
type bar = foo
|
||||
@@ -0,0 +1,5 @@
|
||||
type can recursively refer to itself
|
||||
--> tests/ui/parse-fail/cycle2.wit:2:6
|
||||
|
|
||||
2 | type foo = bar
|
||||
| ^--
|
||||
@@ -0,0 +1,3 @@
|
||||
// parse-fail
|
||||
type foo = bar
|
||||
type bar = option<foo>
|
||||
@@ -0,0 +1,5 @@
|
||||
type can recursively refer to itself
|
||||
--> tests/ui/parse-fail/cycle3.wit:2:6
|
||||
|
|
||||
2 | type foo = bar
|
||||
| ^--
|
||||
@@ -0,0 +1,3 @@
|
||||
// parse-fail
|
||||
type foo = bar
|
||||
record bar { x: foo }
|
||||
@@ -0,0 +1,5 @@
|
||||
type can recursively refer to itself
|
||||
--> tests/ui/parse-fail/cycle4.wit:2:6
|
||||
|
|
||||
2 | type foo = bar
|
||||
| ^--
|
||||
@@ -0,0 +1,3 @@
|
||||
// parse-fail
|
||||
type foo = bar
|
||||
type bar = list<foo>
|
||||
@@ -0,0 +1,5 @@
|
||||
type can recursively refer to itself
|
||||
--> tests/ui/parse-fail/cycle5.wit:2:6
|
||||
|
|
||||
2 | type foo = bar
|
||||
| ^--
|
||||
@@ -0,0 +1,3 @@
|
||||
// parse-fail
|
||||
|
||||
type
|
||||
@@ -0,0 +1,5 @@
|
||||
expected an identifier or string, found eof
|
||||
--> tests/ui/parse-fail/dangling-type.wit:4:1
|
||||
|
|
||||
4 |
|
||||
| ^
|
||||
@@ -0,0 +1,4 @@
|
||||
// parse-fail
|
||||
|
||||
foo: func()
|
||||
foo: func()
|
||||
@@ -0,0 +1,5 @@
|
||||
"foo" defined twice
|
||||
--> tests/ui/parse-fail/duplicate-functions.wit:4:1
|
||||
|
|
||||
4 | foo: func()
|
||||
| ^--
|
||||
@@ -0,0 +1,4 @@
|
||||
// parse-fail
|
||||
|
||||
resource a
|
||||
resource a
|
||||
@@ -0,0 +1,5 @@
|
||||
resource "a" defined twice
|
||||
--> tests/ui/parse-fail/duplicate-resource.wit:4:10
|
||||
|
|
||||
4 | resource a
|
||||
| ^
|
||||
@@ -0,0 +1,4 @@
|
||||
// parse-fail
|
||||
|
||||
type foo = s32
|
||||
type foo = s32
|
||||
@@ -0,0 +1,5 @@
|
||||
type "foo" defined twice
|
||||
--> tests/ui/parse-fail/duplicate-type.wit:4:6
|
||||
|
|
||||
4 | type foo = s32
|
||||
| ^--
|
||||
@@ -0,0 +1,3 @@
|
||||
// parse-fail
|
||||
a: s32
|
||||
a: u32
|
||||
@@ -0,0 +1,5 @@
|
||||
"a" defined twice
|
||||
--> tests/ui/parse-fail/duplicate-value.wit:3:1
|
||||
|
|
||||
3 | a: u32
|
||||
| ^
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
enum t {}
|
||||
@@ -0,0 +1,5 @@
|
||||
empty enum
|
||||
--> tests/ui/parse-fail/empty-enum.wit:2:6
|
||||
|
|
||||
2 | enum t {}
|
||||
| ^
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
union t {}
|
||||
@@ -0,0 +1,5 @@
|
||||
empty union
|
||||
--> tests/ui/parse-fail/empty-union.wit:2:7
|
||||
|
|
||||
2 | union t {}
|
||||
| ^
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
variant t {}
|
||||
@@ -0,0 +1,5 @@
|
||||
empty variant
|
||||
--> tests/ui/parse-fail/empty-variant1.wit:2:9
|
||||
|
|
||||
2 | variant t {}
|
||||
| ^
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
type foo = handle foo
|
||||
@@ -0,0 +1,5 @@
|
||||
no resource named `foo`
|
||||
--> tests/ui/parse-fail/handle-no-resource.wit:2:19
|
||||
|
|
||||
2 | type foo = handle foo
|
||||
| ^--
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
use { nonexistent } from import-me
|
||||
@@ -0,0 +1,5 @@
|
||||
name not defined in submodule
|
||||
--> tests/ui/parse-fail/import-bad.wit:2:7
|
||||
|
|
||||
2 | use { nonexistent } from import-me
|
||||
| ^----------
|
||||
@@ -0,0 +1,3 @@
|
||||
// parse-fail
|
||||
use { foo } from import-me
|
||||
use { foo } from import-me
|
||||
@@ -0,0 +1,5 @@
|
||||
type "foo" defined twice
|
||||
--> tests/ui/parse-fail/import-bad2.wit:3:7
|
||||
|
|
||||
3 | use { foo } from import-me
|
||||
| ^--
|
||||
@@ -0,0 +1,3 @@
|
||||
// parse-fail
|
||||
use { bar } from import-me
|
||||
use { bar } from import-me
|
||||
@@ -0,0 +1,5 @@
|
||||
resource "bar" defined twice
|
||||
--> tests/ui/parse-fail/import-bad3.wit:3:7
|
||||
|
|
||||
3 | use { bar } from import-me
|
||||
| ^--
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
use { bar, bar } from import-me
|
||||
@@ -0,0 +1,5 @@
|
||||
resource "bar" defined twice
|
||||
--> tests/ui/parse-fail/import-bad4.wit:2:12
|
||||
|
|
||||
2 | use { bar, bar } from import-me
|
||||
| ^--
|
||||
@@ -0,0 +1,3 @@
|
||||
// parse-fail
|
||||
use { foo } from import-me
|
||||
use * from import-me
|
||||
@@ -0,0 +1,5 @@
|
||||
type "foo" defined twice
|
||||
--> tests/ui/parse-fail/import-bad5.wit:3:12
|
||||
|
|
||||
3 | use * from import-me
|
||||
| ^--------
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
use { foo } from import-cycle2-v2
|
||||
@@ -0,0 +1 @@
|
||||
file `tests/ui/parse-fail/import-cycle2-v1.wit` recursively imports itself
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
use { foo } from import-cycle2-v1
|
||||
@@ -0,0 +1 @@
|
||||
file `tests/ui/parse-fail/import-cycle2-v2.wit` recursively imports itself
|
||||
@@ -0,0 +1,2 @@
|
||||
type foo = u32
|
||||
resource bar
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"resources": [
|
||||
{
|
||||
"name": "bar"
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
{
|
||||
"idx": 0,
|
||||
"name": "foo",
|
||||
"primitive": "u32"
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"primitive": "handle-0"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
use { foo } from import1
|
||||
@@ -0,0 +1 @@
|
||||
file `tests/ui/parse-fail/import1.wit` recursively imports itself
|
||||
@@ -0,0 +1,7 @@
|
||||
// parse-fail
|
||||
|
||||
hello
|
||||
|
||||
```wit
|
||||
type foo = bar
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
no type named `bar`
|
||||
--> tests/ui/parse-fail/invalid-md.md:6:12
|
||||
|
|
||||
6 | type foo = bar
|
||||
| ^--
|
||||
@@ -0,0 +1,2 @@
|
||||
// parse-fail
|
||||
abcd
|
||||
@@ -0,0 +1,5 @@
|
||||
expected ':', found eof
|
||||
--> tests/ui/parse-fail/invalid-toplevel.wit:3:1
|
||||
|
|
||||
3 |
|
||||
| ^
|
||||
@@ -0,0 +1,3 @@
|
||||
// parse-fail
|
||||
|
||||
type option = u32
|
||||
@@ -0,0 +1,5 @@
|
||||
expected an identifier or string, found keyword `option`
|
||||
--> tests/ui/parse-fail/keyword.wit:3:6
|
||||
|
|
||||
3 | type option = u32
|
||||
| ^-----
|
||||
@@ -0,0 +1,3 @@
|
||||
// parse-fail
|
||||
|
||||
type foo = bar
|
||||
@@ -0,0 +1,5 @@
|
||||
no type named `bar`
|
||||
--> tests/ui/parse-fail/undefined-typed.wit:3:12
|
||||
|
|
||||
3 | type foo = bar
|
||||
| ^--
|
||||
@@ -0,0 +1,5 @@
|
||||
unterminated string literal
|
||||
--> tests/ui/parse-fail/unterminated-string.wit:3:1
|
||||
|
|
||||
3 | "
|
||||
| ^
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user