@@ -107,6 +107,59 @@ func (suite *UASTFilterSuite) TestFilterError() {
107107 suite .Equal (http .StatusBadRequest , res .Code )
108108}
109109
110+ type UASTModeSuite struct {
111+ suite.Suite
112+ handler http.Handler
113+ }
114+
115+ func TestUASTModeSuite (t * testing.T ) {
116+ q := new (UASTModeSuite )
117+ q .handler = lg .RequestLogger (logrus .New ())(handler .APIHandlerFunc (handler .Parse (bblfshServerURL ())))
118+
119+ if ! isIntegration () {
120+ t .Skip ("use the env var GITBASEPG_INTEGRATION_TESTS=true to run this test" )
121+ }
122+
123+ suite .Run (t , q )
124+ }
125+
126+ func (suite * UASTModeSuite ) TestSuccess () {
127+ testCases := []string {
128+ `{ "content": "console.log('test')", "language": "javascript", "mode": "" }` ,
129+ `{ "content": "console.log('test')", "language": "javascript", "mode": "native" }` ,
130+ `{ "content": "console.log('test')", "language": "javascript", "mode": "annotated" }` ,
131+ `{ "content": "console.log('test')", "language": "javascript", "mode": "semantic" }` ,
132+ }
133+
134+ for _ , tc := range testCases {
135+ suite .T ().Run (tc , func (t * testing.T ) {
136+ req , _ := http .NewRequest ("POST" , "/parse" , strings .NewReader (tc ))
137+
138+ res := httptest .NewRecorder ()
139+ suite .handler .ServeHTTP (res , req )
140+
141+ suite .Require ().Equal (http .StatusOK , res .Code , res .Body .String ())
142+
143+ var resBody serializer.Response
144+ err := json .Unmarshal (res .Body .Bytes (), & resBody )
145+ suite .Nil (err )
146+
147+ suite .Equal (res .Code , resBody .Status )
148+ suite .NotEmpty (resBody .Data )
149+ })
150+ }
151+ }
152+
153+ func (suite * UASTModeSuite ) TestWrongMode () {
154+ jsonRequest := `{ "content": "console.log('test')", "language": "javascript", "mode": "foo" }`
155+ req , _ := http .NewRequest ("POST" , "/parse" , strings .NewReader (jsonRequest ))
156+
157+ res := httptest .NewRecorder ()
158+ suite .handler .ServeHTTP (res , req )
159+
160+ suite .Equal (http .StatusBadRequest , res .Code )
161+ }
162+
110163// JSON: [<UAST(console.log("test"))>]
111164// Easy to obtain in the frontend with SELECT UAST('console.log("test")', 'JavaScript') AS uast
112165// Gitbase v0.18.0-beta.1, Bblfsh v2.9.2-drivers
0 commit comments