mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-28 20:49:43 -05:00
6ca8bfad74
Also, extract some common functionality to clients/lib and provide unittests. Fixes issue #30
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package lib
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/attic-labs/noms/types"
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
func TestLibTestSuite(t *testing.T) {
|
|
suite.Run(t, &LibTestSuite{})
|
|
}
|
|
|
|
type LibTestSuite struct {
|
|
suite.Suite
|
|
}
|
|
|
|
func (suite *LibTestSuite) TestPrimitiveTypes() {
|
|
suite.EqualValues(types.NewString("expected"), NomsValueFromObject("expected"))
|
|
suite.EqualValues(types.Bool(false), NomsValueFromObject(false))
|
|
suite.EqualValues(types.Float64(1.7), NomsValueFromObject(1.7))
|
|
suite.False(NomsValueFromObject(1.7).Equals(types.Bool(true)))
|
|
}
|
|
|
|
func (suite *LibTestSuite) TestCompositeTypes() {
|
|
// [false true]
|
|
suite.EqualValues(
|
|
types.NewList().Append(types.Bool(false)).Append(types.Bool(true)),
|
|
NomsValueFromObject([]interface{}{false, true}))
|
|
|
|
// [[false true]]
|
|
suite.EqualValues(
|
|
types.NewList().Append(
|
|
types.NewList().Append(types.Bool(false)).Append(types.Bool(true))),
|
|
NomsValueFromObject([]interface{}{[]interface{}{false, true}}))
|
|
|
|
// {"string": "string",
|
|
// "list": [false true],
|
|
// "map": {"nested": "string"}
|
|
// }
|
|
m := types.NewMap(
|
|
types.NewString("string"), types.NewString("string"),
|
|
types.NewString("list"), types.NewList().Append(types.Bool(false)).Append(types.Bool(true)),
|
|
types.NewString("map"), types.NewMap(types.NewString("nested"), types.NewString("string")))
|
|
suite.EqualValues(m, NomsValueFromObject(map[string]interface{}{
|
|
"string": "string",
|
|
"list": []interface{}{false, true},
|
|
"map": map[string]interface{}{"nested": "string"},
|
|
}))
|
|
}
|