From 35d09f532ab7844f28062f20b1b0e330cd83ca24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sedl=C3=A1=C4=8Dek?= Date: Fri, 22 Nov 2024 11:41:47 +0100 Subject: [PATCH] stream support, tests --- Makefile | 3 +++ _examples/e1.ridl | 7 +++++++ formatter/processor.go | 10 +++++++++- main_test.go | 14 ++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0140357..7c730e1 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,6 @@ rerun-install: rerun: rerun -watch . -ignore out -run sh -c 'go run . -s _examples/e1.ridl' + +test: + go test -v -coverprofile=coverage.txt -covermode=atomic ./... diff --git a/_examples/e1.ridl b/_examples/e1.ridl index 4d0a7fe..69d90ff 100755 --- a/_examples/e1.ridl +++ b/_examples/e1.ridl @@ -76,3 +76,10 @@ service ExampleService # oof @public - GetUser ( header : map < string , string > , userID : uint64 ) => ( code : uint32 , user : User ) - FindUser(s :SearchFilter) => (name: string, user: User) ###! last + + - stream Re cv (req : string ) + + - stream Sen d() => (resp: string) + + -stream Se ndAndRecv(req: string) => stream (resp: string) + -streamSe ndAndRecv(req: string) => stream (resp: string) diff --git a/formatter/processor.go b/formatter/processor.go index e5d6d45..93521dd 100644 --- a/formatter/processor.go +++ b/formatter/processor.go @@ -184,7 +184,15 @@ func (f *form) formatLine(line string) (string, error) { s, c := parseAndDivideInlineComment(line) parts := strings.Split(s, "=>") p1 := strings.TrimSpace(parts[0]) - methodName := strings.TrimPrefix(strings.TrimSpace(strings.ReplaceAll(strings.Split(p1, "(")[0], " ", "")), "-") + + methodName := strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(strings.Split(p1, "(")[0]), "-")) + methodName, isStreamInput := strings.CutPrefix(methodName, "stream ") + methodName = removeSpaces(methodName) + + if isStreamInput { + methodName = "stream " + methodName + } + inArgs, err := formatMethodArguments(p1) if err != nil { return line, err diff --git a/main_test.go b/main_test.go index 4d31632..a63edb9 100644 --- a/main_test.go +++ b/main_test.go @@ -162,6 +162,13 @@ service ExampleService # oof - GetUser ( header : map < string , string > , userID : uint64 ) => ( code : uint32 , user : User ) - FindUser(s :SearchFilter) => (name: string, user: User) ###! last + - stream Re cv (req : string ) + + + - stream Sen d() => (resp: string) + + -stream Se ndAndRecv(req: string) => stream (resp: string) + -streamSe ndAndRecv(req: string) => stream (resp: string) @@ -246,4 +253,11 @@ service ExampleService # oof @public - GetUser(header: map, userID: uint64) => (code: uint32, user: User) - FindUser(s: SearchFilter) => (name: string, user: User) ###! last + + - stream Recv(req: string) + + - stream Send() => (resp: string) + + - stream SendAndRecv(req: string) => stream (resp: string) + - streamSendAndRecv(req: string) => stream (resp: string) `