github.com/wit-ai/wit-go/v2@v2.0.2/language_detection_test.go (about)

     1  // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
     2  
     3  package witai
     4  
     5  import (
     6  	"net/http"
     7  	"net/http/httptest"
     8  	"testing"
     9  )
    10  
    11  func TestLocales(t *testing.T) {
    12  	testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
    13  		_, _ = res.Write(
    14  			[]byte(`{
    15  				"detected_locales": [
    16  					{
    17  						"locale": "en_XX",
    18  						"confidence": 1
    19  					}
    20  				]
    21  			}`),
    22  		)
    23  	}))
    24  	defer func() { testServer.Close() }()
    25  
    26  	c := NewClient(unitTestToken)
    27  	c.APIBase = testServer.URL
    28  	l, err := c.Detect("Hello world")
    29  
    30  	if err != nil {
    31  		t.Fatalf("nil error expected, got %v", err)
    32  	}
    33  
    34  	if l.DetectedLocales[0].Locale != "en_XX" {
    35  		t.Fatalf("lang=en expected, got %v", l.DetectedLocales[0].Locale)
    36  	}
    37  }