internal/warpc: Improve the JS plugin API

* Move the error handling into commons and make sure the error returned also returns message errors
* Make the protocol version an int so it can be more easily compared
This commit is contained in:
Bjørn Erik Pedersen
2024-09-12 09:13:47 +02:00
parent fe7e137e28
commit 28f621d4a7
9 changed files with 68 additions and 43 deletions

View File

@@ -45,28 +45,44 @@ func TestKatex(t *testing.T) {
defer d.Close()
ctx := context.Background()
runExpression := func(c *qt.C, id uint32, expression string) (Message[KatexOutput], error) {
c.Helper()
input := KatexInput{
Expression: "c = \\pm\\sqrt{a^2 + b^2}",
Options: KatexOptions{
Output: "html",
DisplayMode: true,
},
ctx := context.Background()
input := KatexInput{
Expression: expression,
Options: KatexOptions{
Output: "html",
DisplayMode: true,
ThrowOnError: true,
},
}
message := Message[KatexInput]{
Header: Header{
Version: currentVersion,
ID: uint32(id),
},
Data: input,
}
return d.Execute(ctx, message)
}
message := Message[KatexInput]{
Header: Header{
Version: currentVersion,
ID: uint32(32),
},
Data: input,
}
c.Run("Simple", func(c *qt.C) {
id := uint32(32)
result, err := runExpression(c, id, "c = \\pm\\sqrt{a^2 + b^2}")
c.Assert(err, qt.IsNil)
c.Assert(result.GetID(), qt.Equals, id)
})
result, err := d.Execute(ctx, message)
c.Assert(err, qt.IsNil)
c.Assert(result.GetID(), qt.Equals, message.GetID())
c.Run("Invalid expression", func(c *qt.C) {
id := uint32(32)
result, err := runExpression(c, id, "c & \\foo\\")
c.Assert(err, qt.IsNotNil)
c.Assert(result.GetID(), qt.Equals, id)
})
}
func TestGreet(t *testing.T) {