github.com/MontFerret/ferret@v0.18.0/pkg/compiler/compiler_waitfor_event_ternary_test.go (about) 1 package compiler_test 2 3 import ( 4 "context" 5 "testing" 6 7 . "github.com/smartystreets/goconvey/convey" 8 ) 9 10 func TestWaitforEventWithinTernaryExpression(t *testing.T) { 11 SkipConvey("RETURN foo ? TRUE : (WAITFOR EVENT \"event\" IN obj)", t, func() { 12 c := newCompilerWithObservable() 13 14 out1, err := c.MustCompile(` 15 LET foo = FALSE 16 LET obj = X::VAL("event", ["data"]) 17 18 RETURN foo ? TRUE : (WAITFOR EVENT "event" IN obj) 19 `).Run(context.Background()) 20 21 So(err, ShouldBeNil) 22 So(string(out1), ShouldEqual, `"data"`) 23 24 out2, err := c.MustCompile(` 25 LET foo = TRUE 26 LET obj = X::VAL("event", ["data"]) 27 28 RETURN foo ? TRUE : (WAITFOR EVENT "event" IN obj) 29 `).Run(context.Background()) 30 31 So(err, ShouldBeNil) 32 So(string(out2), ShouldEqual, `true`) 33 }) 34 35 SkipConvey("RETURN foo ? (WAITFOR EVENT \"event1\" IN obj) : (WAITFOR EVENT \"event2\" IN obj)", t, func() { 36 c := newCompilerWithObservable() 37 38 out1, err := c.MustCompile(` 39 LET foo = FALSE 40 LET obj = X::VAL("event2", ["data2"]) 41 42 RETURN foo ? (WAITFOR EVENT "event1" IN obj) : (WAITFOR EVENT "event2" IN obj) 43 `).Run(context.Background()) 44 45 So(err, ShouldBeNil) 46 So(string(out1), ShouldEqual, `"data2"`) 47 48 c = newCompilerWithObservable() 49 out2, err := c.MustCompile(` 50 LET foo = TRUE 51 LET obj = X::VAL("event1", ["data1"]) 52 53 RETURN foo ? (WAITFOR EVENT "event1" IN obj) : (WAITFOR EVENT "event2" IN obj) 54 `).Run(context.Background()) 55 56 So(err, ShouldBeNil) 57 So(string(out2), ShouldEqual, `"data1"`) 58 }) 59 60 SkipConvey("RETURN foo ? (FOR i IN 1..3 RETURN i*2) : (WAITFOR EVENT \"event2\" IN obj)", t, func() { 61 c := newCompilerWithObservable() 62 63 out1, err := c.MustCompile(` 64 LET foo = FALSE 65 LET obj = X::VAL("event", ["data"]) 66 67 RETURN foo ? (FOR i IN 1..3 RETURN i*2) : (WAITFOR EVENT "event" IN obj) 68 `).Run(context.Background()) 69 70 So(err, ShouldBeNil) 71 So(string(out1), ShouldEqual, `"data"`) 72 73 out2, err := c.MustCompile(` 74 LET foo = TRUE 75 LET obj = X::VAL("event", ["data"]) 76 77 RETURN foo ? (FOR i IN 1..3 RETURN i*2) : (WAITFOR EVENT "event" IN obj) 78 `).Run(context.Background()) 79 80 So(err, ShouldBeNil) 81 So(string(out2), ShouldEqual, `[2,4,6]`) 82 }) 83 84 SkipConvey("RETURN foo ? (WAITFOR EVENT \"event\" IN obj) : (FOR i IN 1..3 RETURN i*2) ", t, func() { 85 c := newCompilerWithObservable() 86 87 out1, err := c.MustCompile(` 88 LET foo = FALSE 89 LET obj = X::VAL("event", ["data"], 1000) 90 91 RETURN foo ? (WAITFOR EVENT "event" IN obj) : (FOR i IN 1..3 RETURN i*2) 92 `).Run(context.Background()) 93 94 So(err, ShouldBeNil) 95 So(string(out1), ShouldEqual, `[2,4,6]`) 96 97 out2, err := c.MustCompile(` 98 LET foo = TRUE 99 LET obj = X::VAL("event", ["data"]) 100 101 RETURN foo ? (WAITFOR EVENT "event" IN obj) : (FOR i IN 1..3 RETURN i*2) 102 `).Run(context.Background()) 103 104 So(err, ShouldBeNil) 105 So(string(out2), ShouldEqual, `"data"`) 106 }) 107 }