package export_wit_world
import (
"fmt"
leaf "wit_component/my_test_leaf_interface"
test "wit_component/my_test_test_interface"
)
func Run() {
{
tx, rx := test.MakeStreamTestThing()
defer tx.Drop()
defer rx.Drop()
stream := test.ShortReadsTest(rx)
defer stream.Drop()
tx.WriteAll([]*test.TestThing{
test.MakeTestThing("a"),
test.MakeTestThing("b"),
test.MakeTestThing("c"),
})
tx.Drop()
things := []*test.TestThing{}
for !stream.WriterDropped() {
buffer := make([]*test.TestThing, 1)
count := stream.Read(buffer)
if count == 1 {
things = append(things, buffer[0])
}
}
assertEqual(things[0].Get(), "a")
assertEqual(things[1].Get(), "b")
assertEqual(things[2].Get(), "c")
}
{
tx, rx := test.MakeStreamMyTestLeafInterfaceLeafThing()
defer tx.Drop()
defer rx.Drop()
stream := test.ShortReadsLeaf(rx)
defer stream.Drop()
tx.WriteAll([]*leaf.LeafThing{
leaf.MakeLeafThing("a"),
leaf.MakeLeafThing("b"),
leaf.MakeLeafThing("c"),
})
tx.Drop()
things := []*leaf.LeafThing{}
for !stream.WriterDropped() {
buffer := make([]*leaf.LeafThing, 1)
count := stream.Read(buffer)
if count == 1 {
things = append(things, buffer[0])
}
}
assertEqual(things[0].Get(), "a")
assertEqual(things[1].Get(), "b")
assertEqual(things[2].Get(), "c")
}
{
tx1, rx1 := test.MakeFutureTestThing()
tx2, rx2 := test.MakeFutureTestThing()
f1, f2 := test.DroppedReaderTest(rx1, rx2)
{
thing := test.MakeTestThing("a")
assert(!tx1.Write(thing))
assert(tx2.Write(thing))
}
{
f1.Drop()
thing := f2.Read()
assertEqual(thing.Get(), "a")
}
}
{
tx1, rx1 := test.MakeFutureMyTestLeafInterfaceLeafThing()
tx2, rx2 := test.MakeFutureMyTestLeafInterfaceLeafThing()
f1, f2 := test.DroppedReaderLeaf(rx1, rx2)
{
thing := leaf.MakeLeafThing("a")
assert(!tx1.Write(thing))
assert(tx2.Write(thing))
}
{
f1.Drop()
thing := f2.Read()
assertEqual(thing.Get(), "a")
}
}
}
func assertEqual[T comparable](a T, b T) {
if a != b {
panic(fmt.Sprintf("%v not equal to %v", a, b))
}
}
func assert(v bool) {
if !v {
panic("assertion failed")
}
}