github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/types/value_test.go (about)

     1  /*
     2   * Copyright 2018 Dgraph Labs, Inc. and Contributors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package types
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/stretchr/testify/require"
    23  )
    24  
    25  func TestTypeForValue(t *testing.T) {
    26  	tests := []struct {
    27  		in  string
    28  		out TypeID
    29  	}{
    30  		{`true`, BoolID},
    31  		{`TRUE`, BoolID},
    32  		{`True`, BoolID},
    33  		{`t`, DefaultID},
    34  		{`false`, BoolID},
    35  		{`FALSE`, BoolID},
    36  		{`False`, BoolID},
    37  		{`f`, DefaultID},
    38  		{`2018`, IntID},
    39  		{`2018-10`, DateTimeID},
    40  		{`2018-10-03`, DateTimeID},
    41  		{`2018-10-03T20:47:53Z`, DateTimeID},
    42  		{`123`, IntID},
    43  		{`-123`, IntID},
    44  		{`+123`, IntID},
    45  		{`0001`, IntID},
    46  		{`+0`, IntID},
    47  		{`-0`, IntID},
    48  		{`1World`, DefaultID},
    49  		{`3.14159`, FloatID},
    50  		{`-273.15`, FloatID},
    51  		{`2.99792e8`, FloatID},
    52  		{`9.1095E-28`, FloatID},
    53  		{`-.0`, FloatID},
    54  		{`+.0`, FloatID},
    55  		{`.1`, FloatID},
    56  		{`1.`, FloatID},
    57  		{`1-800-4GOLANG`, DefaultID},
    58  		{`+1800-446-5264`, DefaultID},
    59  		{`212.555.9876`, DefaultID},
    60  		{`testing`, DefaultID},
    61  	}
    62  	for _, tc := range tests {
    63  		out, _ := TypeForValue([]byte(tc.in))
    64  		require.Equal(t, tc.out, out, "%s != %s", tc.in, tc.out.Enum())
    65  	}
    66  }