-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize a test suite for
wit-encoder
(#1626)
* change `wit-encoder` indent to 2 * test empty `Result`s in `wit-encoder` * import wit test files for `wit-encoder` * use external wit test file for `functions.rs` test * add `empty` test * add `wit-encoder` overlap tests * fix more existing tests * Add `include` capabilities to `wit-encoder` * tidy up * rebase on main * check in `.gitattributes` to normalize line endings Rebasing brok * remove additional wit files * inline tests
- Loading branch information
1 parent
8afdf05
commit 3e38098
Showing
18 changed files
with
314 additions
and
134 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
* text=auto | ||
*.waves text eol=lf | ||
*.out text eol=lf |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 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 std::fmt; | ||
|
||
use crate::{Ident, Render}; | ||
|
||
/// Enable the union of a world with another world | ||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub struct Include { | ||
use_path: Ident, | ||
include_names_list: Vec<String>, | ||
} | ||
|
||
impl Include { | ||
pub fn new(use_path: impl Into<Ident>) -> Self { | ||
Self { | ||
use_path: use_path.into(), | ||
include_names_list: vec![], | ||
} | ||
} | ||
} | ||
|
||
impl Render for Include { | ||
fn render(&self, f: &mut fmt::Formatter<'_>, opts: &crate::RenderOpts) -> fmt::Result { | ||
write!(f, "{}include {};\n", opts.spaces(), self.use_path)?; | ||
Ok(()) | ||
} | ||
} |
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 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 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,12 @@ | ||
use pretty_assertions::assert_eq; | ||
use wit_encoder::{Package, PackageName}; | ||
|
||
const PACKAGE: &str = indoc::indoc! {" | ||
package foo:empty; | ||
"}; | ||
|
||
#[test] | ||
fn concrete_types() { | ||
let package = Package::new(PackageName::new("foo", "empty", None)); | ||
assert_eq!(package.to_string(), PACKAGE); | ||
} |
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,88 +1,88 @@ | ||
use pretty_assertions::assert_eq; | ||
use wit_encoder::{Params, Result_, Results, StandaloneFunc, Type}; | ||
use wit_encoder::{ | ||
Interface, Package, PackageName, Params, Result_, Results, StandaloneFunc, Type, | ||
}; | ||
|
||
const PACKAGE: &str = "package foo:functions; | ||
const PACKAGE: &str = indoc::indoc! {" | ||
package foo:functions; | ||
interface functions { | ||
f1: func(); | ||
f2: func(a: u32); | ||
f3: func() -> u32; | ||
/// this is a documentation comment | ||
/// for the f4 function | ||
f4: func() -> tuple<u32, u32>; | ||
f5: func(a: f32, b: f32) -> tuple<u32, u32>; | ||
f6: func(a: option<u32>) -> result<u32, f32>; | ||
f7: func() -> (u: u32, f: f32); | ||
f8: func() -> (u: u32); | ||
f9: func() -> result<f32>; | ||
f10: func() -> result<_, f32>; | ||
f11: func() -> result; | ||
} | ||
"; | ||
interface functions { | ||
f1: func(); | ||
f2: func(a: u32); | ||
f4: func() -> u32; | ||
f6: func() -> tuple<u32, u32>; | ||
f7: func(a: f32, b: f32) -> tuple<u32, u32>; | ||
f8: func(a: option<u32>) -> result<u32, f32>; | ||
f9: func() -> (u: u32, f: f32); | ||
f10: func() -> (u: u32); | ||
f11: func() -> result<f32>; | ||
f12: func() -> result<_, f32>; | ||
f13: func() -> result; | ||
} | ||
"}; | ||
|
||
#[test] | ||
fn smoke() { | ||
let name = wit_encoder::PackageName::new("foo", "functions", None); | ||
let mut package = wit_encoder::Package::new(name); | ||
fn concrete_types() { | ||
let name = PackageName::new("foo", "functions", None); | ||
let mut package = Package::new(name); | ||
|
||
package.interface({ | ||
let mut interface = wit_encoder::Interface::new("functions"); | ||
let mut interface = Interface::new("functions"); | ||
interface.function(StandaloneFunc::new("f1")); | ||
interface.function({ | ||
let mut func = StandaloneFunc::new("f2"); | ||
func.params(Params::from_iter([("a", Type::U32)])); | ||
func | ||
}); | ||
interface.function({ | ||
let mut func = StandaloneFunc::new("f3"); | ||
func.results(Type::U32); | ||
let mut func = StandaloneFunc::new("f4"); | ||
func.results(Results::anon(Type::U32)); | ||
func | ||
}); | ||
interface.function({ | ||
let mut func = StandaloneFunc::new("f4"); | ||
func.results(Type::tuple(vec![Type::U32, Type::U32])); | ||
func.docs(Some("this is a documentation comment\nfor the f4 function")); | ||
let mut func = StandaloneFunc::new("f6"); | ||
func.results(Results::anon(Type::tuple(vec![Type::U32, Type::U32]))); | ||
func | ||
}); | ||
interface.function({ | ||
let mut func = StandaloneFunc::new("f5"); | ||
let mut func = StandaloneFunc::new("f7"); | ||
func.params(Params::from_iter([("a", Type::F32), ("b", Type::F32)])); | ||
func.results(Type::tuple(vec![Type::U32, Type::U32])); | ||
func | ||
}); | ||
interface.function({ | ||
let mut func = StandaloneFunc::new("f6"); | ||
let mut func = StandaloneFunc::new("f8"); | ||
func.params(Params::from_iter([("a", Type::option(Type::U32))])); | ||
func.results(Type::result(Result_::both(Type::U32, Type::F32))); | ||
func | ||
}); | ||
interface.function({ | ||
let mut func = StandaloneFunc::new("f7"); | ||
let mut func = StandaloneFunc::new("f9"); | ||
func.results(Results::named(vec![("u", Type::U32), ("f", Type::F32)])); | ||
func | ||
}); | ||
interface.function({ | ||
let mut func = StandaloneFunc::new("f8"); | ||
let mut func = StandaloneFunc::new("f10"); | ||
func.results(Results::named(vec![("u", Type::U32)])); | ||
func | ||
}); | ||
interface.function({ | ||
let mut func = StandaloneFunc::new("f9"); | ||
let mut func = StandaloneFunc::new("f11"); | ||
func.results(Type::result(Result_::ok(Type::F32))); | ||
func | ||
}); | ||
interface.function({ | ||
let mut func = StandaloneFunc::new("f10"); | ||
let mut func = StandaloneFunc::new("f12"); | ||
func.results(Type::result(Result_::err(Type::F32))); | ||
func | ||
}); | ||
interface.function({ | ||
let mut func = StandaloneFunc::new("f11"); | ||
let mut func = StandaloneFunc::new("f13"); | ||
func.results(Type::result(Result_::empty())); | ||
func | ||
}); | ||
interface | ||
}); | ||
|
||
assert_eq!(PACKAGE, package.to_string()); | ||
assert_eq!(package.to_string(), PACKAGE); | ||
} |
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,23 @@ | ||
use pretty_assertions::assert_eq; | ||
use wit_encoder::{Package, PackageName, StandaloneFunc, World}; | ||
|
||
const PACKAGE: &str = indoc::indoc! {" | ||
package foo:foo; | ||
world foo { | ||
import a: func(); | ||
export a: func(); | ||
} | ||
"}; | ||
|
||
#[test] | ||
fn concrete_types() { | ||
let mut package = Package::new(PackageName::new("foo", "foo", None)); | ||
|
||
let mut world = World::new("foo"); | ||
world.function_import(StandaloneFunc::new("a")); | ||
world.function_export(StandaloneFunc::new("a")); | ||
package.world(world); | ||
|
||
assert_eq!(package.to_string(), PACKAGE); | ||
} |
Oops, something went wrong.