Skip to content

Instantly share code, notes, and snippets.

@WhiteAbeLincoln
Created December 18, 2025 00:14
Show Gist options
  • Select an option

  • Save WhiteAbeLincoln/9b0bf2f5a0cb0a412561d97b94b22355 to your computer and use it in GitHub Desktop.

Select an option

Save WhiteAbeLincoln/9b0bf2f5a0cb0a412561d97b94b22355 to your computer and use it in GitHub Desktop.
Test case for documentation vs regular comments in wit files
package componentize-py:test;
// copied from https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#wit-types
interface undocumented {
// undocumented function
doc-func: func();
/* undocumented resource */
resource resource-name {
// resource methods go here
method: func();
}
// "package of named fields"
record r {
a: u32,
b: string,
}
// values of this type will be one of the specified cases
variant human {
// commented case
baby,
child(u32), // optional type payload
adult,
}
/* similar to `variant`, but no type payloads */
enum errno {
too-big,
too-small,
too-fast,
too-slow,
}
// a bitflags type
flags permissions {
read,
// comment on flag
write,
exec,
}
// type aliases are allowed to primitive types and additionally here are some
// examples of other types
type t1 = u32;
type t2 = tuple<u32, u64>;
type t3 = string;
type t4 = option<u32>;
type t5 = result<_, errno>; // no "ok" type
type t6 = result<string>; // no "err" type
type t7 = result<char, errno>; // both types specified
type t8 = result; // no "ok" or "err" type
type t9 = list<string>;
type t10 = t9;
}
/**
* This is a documentation comment for the interface `documented`
*/
interface documented {
/// documented function
doc-func: func();
// some comment
/// plus documentation
comment-and-doc: func();
/// documentation plus
// another comment.
doc-and-comment: func();
/** documented resource */
resource resource-name {
/// documentation for resource method
method: func();
}
/// "package of named fields"
record r {
a: u32,
b: string,
}
/// values of this type will be one of the specified cases
variant human {
/// commented case
baby,
child(u32),
adult,
}
/**
* similar to `variant`, but no type payloads
*/
enum errno {
too-big,
too-small,
too-fast,
too-slow,
}
/// a bitflags type
flags permissions {
read,
/// comment on flag
write,
exec,
}
/// type aliases are allowed to primitive types and additionally here are some
/// examples of other types
type t1 = u32;
type t2 = tuple<u32, u64>;
type t3 = string;
type t4 = option<u32>;
type t5 = result<_, errno>; // no "ok" type
type t6 = result<string>; // no "err" type
type t7 = result<char, errno>; // both types specified
type t8 = result; // no "ok" or "err" type
type t9 = list<string>;
type t10 = t9;
}
world undocumented-test {
// undocumented import
import undocumented;
// undocumented export
export undocumented;
}
world doc-comment-test {
/// documentation on import
import documented;
/// documentation on export
export documented;
// plain comment
import undocumented;
// plain export comment
export undocumented;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment