diff --git a/clients/counter/counter.go b/clients/counter/counter.go index 199113d9e0..24120698fc 100644 --- a/clients/counter/counter.go +++ b/clients/counter/counter.go @@ -26,10 +26,10 @@ func main() { lastVal := uint64(0) if commit, ok := ds.MaybeHead(); ok { - lastVal = uint64(commit.Get(datas.ValueField).(types.Uint64)) + lastVal = uint64(commit.Get(datas.ValueField).(types.Number)) } newVal := lastVal + 1 - _, err := ds.Commit(types.Uint64(newVal)) + _, err := ds.Commit(types.Number(newVal)) d.Exp.NoError(err) fmt.Println(newVal) diff --git a/clients/csv/importer/importer_test.go b/clients/csv/importer/importer_test.go index ab86f8a1e8..84122b98a8 100644 --- a/clients/csv/importer/importer_test.go +++ b/clients/csv/importer/importer_test.go @@ -40,7 +40,7 @@ func (s *testSuite) TestCSVImporter() { storeName := "store" setName := "csv" - out := s.Run(main, []string{"-store", storeName, "-column-types", "String,Uint8", "-ds", setName, input.Name()}) + out := s.Run(main, []string{"-store", storeName, "-column-types", "String,Number", "-ds", setName, input.Name()}) s.Equal("", out) cs := chunks.NewLevelDBStore(s.LdbDir, storeName, 1, false) @@ -56,7 +56,7 @@ func (s *testSuite) TestCSVImporter() { s.Equal(i, j) st := v.(types.Struct) s.Equal(types.NewString(fmt.Sprintf("a%d", i)), st.Get("a")) - s.Equal(types.Uint8(i), st.Get("b")) + s.Equal(types.Number(i), st.Get("b")) i++ }) } @@ -82,8 +82,8 @@ func (s *testSuite) TestCSVImporterReportTypes() { storeName := "store" setName := "csv" - out := s.Run(main, []string{"-store", storeName, "-column-types", "String,Uint8", "-ds", setName, input.Name()}) - s.Equal("Possible types for each column:\na: String\nb: Uint8,Uint16,Uint32,Uint64,Int8,Int16,Int32,Int64,Float32,Float64,String\n", out) + out := s.Run(main, []string{"-store", storeName, "-column-types", "String,Number", "-ds", setName, input.Name()}) + s.Equal("Possible types for each column:\na: String\nb: Number,String\n", out) } func (s *testSuite) TestCSVImporterWithPipe() { @@ -102,7 +102,7 @@ func (s *testSuite) TestCSVImporterWithPipe() { storeName := "store" setName := "csv" - out := s.Run(main, []string{"-store", storeName, "-column-types", "String,Uint8", "-ds", setName, input.Name()}) + out := s.Run(main, []string{"-store", storeName, "-column-types", "String,Number", "-ds", setName, input.Name()}) s.Equal("", out) cs := chunks.NewLevelDBStore(s.LdbDir, storeName, 1, false) @@ -115,7 +115,7 @@ func (s *testSuite) TestCSVImporterWithPipe() { v := l.Get(0) st := v.(types.Struct) s.Equal(types.NewString("1"), st.Get("a")) - s.Equal(types.Uint8(2), st.Get("b")) + s.Equal(types.Number(2), st.Get("b")) } func (s *testSuite) TestCSVImporterWithExternalHeader() { @@ -134,7 +134,7 @@ func (s *testSuite) TestCSVImporterWithExternalHeader() { storeName := "store" setName := "csv" - out := s.Run(main, []string{"-store", storeName, "-column-types", "String,Uint8", "-ds", setName, input.Name()}) + out := s.Run(main, []string{"-store", storeName, "-column-types", "String,Number", "-ds", setName, input.Name()}) s.Equal("", out) cs := chunks.NewLevelDBStore(s.LdbDir, storeName, 1, false) @@ -147,5 +147,5 @@ func (s *testSuite) TestCSVImporterWithExternalHeader() { v := l.Get(0) st := v.(types.Struct) s.Equal(types.NewString("7"), st.Get("x")) - s.Equal(types.Uint8(8), st.Get("y")) + s.Equal(types.Number(8), st.Get("y")) } diff --git a/clients/csv/kind_slice_test.go b/clients/csv/kind_slice_test.go index a9741a13ed..0780d91f73 100644 --- a/clients/csv/kind_slice_test.go +++ b/clients/csv/kind_slice_test.go @@ -12,7 +12,7 @@ import ( func TestKindSliceJSON(t *testing.T) { assert := assert.New(t) - ks := KindSlice{types.Uint8Kind, types.StringKind, types.BoolKind} + ks := KindSlice{types.NumberKind, types.StringKind, types.BoolKind} b, err := json.Marshal(&ks) assert.NoError(err) diff --git a/clients/csv/read_test.go b/clients/csv/read_test.go index 99d7dc9732..66f1a33f91 100644 --- a/clients/csv/read_test.go +++ b/clients/csv/read_test.go @@ -21,7 +21,7 @@ b,2,false r := NewCSVReader(bytes.NewBufferString(dataString), ',') headers := []string{"A", "B", "C"} - kinds := KindSlice{types.StringKind, types.Int8Kind, types.BoolKind} + kinds := KindSlice{types.StringKind, types.NumberKind, types.BoolKind} l, typeRef, typeDef := Read(r, "test", headers, kinds, ds) assert.Equal(uint64(2), l.Len()) @@ -38,8 +38,8 @@ b,2,false assert.True(l.Get(0).(types.Struct).Get("A").Equals(types.NewString("a"))) assert.True(l.Get(1).(types.Struct).Get("A").Equals(types.NewString("b"))) - assert.True(l.Get(0).(types.Struct).Get("B").Equals(types.Int8(1))) - assert.True(l.Get(1).(types.Struct).Get("B").Equals(types.Int8(2))) + assert.True(l.Get(0).(types.Struct).Get("B").Equals(types.Number(1))) + assert.True(l.Get(1).(types.Struct).Get("B").Equals(types.Number(2))) assert.True(l.Get(0).(types.Struct).Get("C").Equals(types.Bool(true))) assert.True(l.Get(1).(types.Struct).Get("C").Equals(types.Bool(false))) diff --git a/clients/csv/schema.go b/clients/csv/schema.go index 54beed5671..35dd844779 100644 --- a/clients/csv/schema.go +++ b/clients/csv/schema.go @@ -13,7 +13,7 @@ type schemaOptions []*typeCanFit func newSchemaOptions(fieldCount int) schemaOptions { options := make([]*typeCanFit, fieldCount, fieldCount) for i := 0; i < fieldCount; i++ { - options[i] = &typeCanFit{true, true, true, true, true, true, true, true, true, true, true, true, true, true} + options[i] = &typeCanFit{true, true, true} } return options } @@ -35,56 +35,14 @@ func (so schemaOptions) ValidKinds() []KindSlice { } type typeCanFit struct { - uintType bool - intType bool - boolType bool - uint8Type bool - uint16Type bool - uint32Type bool - uint64Type bool - int8Type bool - int16Type bool - int32Type bool - int64Type bool - float32Type bool - float64Type bool - stringType bool + boolType bool + numberType bool + stringType bool } func (tc *typeCanFit) ValidKinds() (kinds KindSlice) { - if tc.uintType { - if tc.uint8Type { - kinds = append(kinds, types.Uint8Kind) - } - if tc.uint16Type { - kinds = append(kinds, types.Uint16Kind) - } - if tc.uint32Type { - kinds = append(kinds, types.Uint32Kind) - } - if tc.uint64Type { - kinds = append(kinds, types.Uint64Kind) - } - } - if tc.intType { - if tc.int8Type { - kinds = append(kinds, types.Int8Kind) - } - if tc.int16Type { - kinds = append(kinds, types.Int16Kind) - } - if tc.int32Type { - kinds = append(kinds, types.Int32Kind) - } - if tc.int64Type { - kinds = append(kinds, types.Int64Kind) - } - } - if tc.float32Type { - kinds = append(kinds, types.Float32Kind) - } - if tc.float64Type { - kinds = append(kinds, types.Float64Kind) + if tc.numberType { + kinds = append(kinds, types.NumberKind) } if tc.boolType { kinds = append(kinds, types.BoolKind) @@ -95,71 +53,23 @@ func (tc *typeCanFit) ValidKinds() (kinds KindSlice) { } func (tc *typeCanFit) Test(value string) { - tc.testUints(value) - tc.testInts(value) - tc.testFloats(value) + tc.testNumbers(value) tc.testBool(value) } -func (tc *typeCanFit) testUints(value string) { - if !tc.uintType { - return - } - - ival, err := strconv.ParseUint(value, 10, 64) - if err != nil { - tc.uintType = false - tc.uint8Type = false - tc.uint16Type = false - tc.uint32Type = false - tc.uint64Type = false - return - } - - tc.uint32Type = tc.uint32Type && ival <= math.MaxUint32 - tc.uint16Type = tc.uint16Type && ival <= math.MaxUint16 - tc.uint8Type = tc.uint8Type && ival <= math.MaxUint8 - return -} - -func (tc *typeCanFit) testInts(value string) { - if !tc.intType { - return - } - - ival, err := strconv.ParseInt(value, 10, 64) - if err != nil { - tc.intType = false - tc.int8Type = false - tc.int16Type = false - tc.int32Type = false - tc.int64Type = false - return - } - - if ival < 0 { - ival *= -1 - } - tc.int32Type = tc.int32Type && ival <= math.MaxInt32 - tc.int16Type = tc.int16Type && ival <= math.MaxInt16 - tc.int8Type = tc.int8Type && ival <= math.MaxInt8 - return -} - -func (tc *typeCanFit) testFloats(value string) { - if !tc.float32Type && !tc.float64Type { +func (tc *typeCanFit) testNumbers(value string) { + if !tc.numberType { return } fval, err := strconv.ParseFloat(value, 64) if err != nil { - tc.float32Type = false - tc.float64Type = false + tc.numberType = false return } - if fval > math.MaxFloat32 { - tc.float32Type = false + if fval > math.MaxFloat64 { + tc.numberType = false } } @@ -174,46 +84,10 @@ func (tc *typeCanFit) testBool(value string) { // StringToType takes a piece of data as a string and attempts to convert it to a types.Value of the appropriate types.NomsKind. func StringToType(s string, k types.NomsKind) types.Value { switch k { - case types.Uint8Kind: - ival, err := strconv.ParseUint(s, 10, 8) - d.Chk.NoError(err) - return types.Uint8(ival) - case types.Uint16Kind: - ival, err := strconv.ParseUint(s, 10, 16) - d.Chk.NoError(err) - return types.Uint16(ival) - case types.Uint32Kind: - ival, err := strconv.ParseUint(s, 10, 32) - d.Chk.NoError(err) - return types.Uint32(ival) - case types.Uint64Kind: - ival, err := strconv.ParseUint(s, 10, 64) - d.Chk.NoError(err) - return types.Uint64(ival) - case types.Int8Kind: - ival, err := strconv.ParseInt(s, 10, 8) - d.Chk.NoError(err) - return types.Int8(ival) - case types.Int16Kind: - ival, err := strconv.ParseInt(s, 10, 16) - d.Chk.NoError(err) - return types.Int16(ival) - case types.Int32Kind: - ival, err := strconv.ParseInt(s, 10, 32) - d.Chk.NoError(err) - return types.Int32(ival) - case types.Int64Kind: - ival, err := strconv.ParseInt(s, 10, 64) - d.Chk.NoError(err) - return types.Int64(ival) - case types.Float32Kind: - fval, err := strconv.ParseFloat(s, 32) - d.Chk.NoError(err) - return types.Float32(fval) - case types.Float64Kind: + case types.NumberKind: fval, err := strconv.ParseFloat(s, 64) d.Chk.NoError(err) - return types.Float64(fval) + return types.Number(fval) case types.BoolKind: bval, err := strconv.ParseBool(s) d.Chk.NoError(err) diff --git a/clients/csv/schema_test.go b/clients/csv/schema_test.go index 169fa40bf2..fa4550e67a 100644 --- a/clients/csv/schema_test.go +++ b/clients/csv/schema_test.go @@ -32,9 +32,7 @@ func TestSchemaDetection(t *testing.T) { KindSlice{types.StringKind}, KindSlice{types.BoolKind, types.StringKind}, KindSlice{ - types.Uint8Kind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, - types.Int8Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, - types.Float32Kind, types.Float64Kind, + types.NumberKind, types.StringKind, }, }, @@ -83,7 +81,7 @@ func TestSchemaDetection(t *testing.T) { }, []KindSlice{ KindSlice{ - types.Float32Kind, types.Float64Kind, + types.NumberKind, types.StringKind}, }, ) @@ -96,8 +94,7 @@ func TestSchemaDetection(t *testing.T) { }, []KindSlice{ KindSlice{ - types.Float32Kind, - types.Float64Kind, + types.NumberKind, types.StringKind}, }, ) @@ -111,7 +108,7 @@ func TestSchemaDetection(t *testing.T) { }, []KindSlice{ KindSlice{ - types.Float64Kind, + types.NumberKind, types.StringKind}, }, ) @@ -134,10 +131,7 @@ func TestSchemaDetection(t *testing.T) { }, []KindSlice{ KindSlice{ - types.Uint8Kind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, - types.Int8Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, - types.Float32Kind, - types.Float64Kind, + types.NumberKind, types.BoolKind, types.StringKind}, }, @@ -150,8 +144,7 @@ func TestSchemaDetection(t *testing.T) { }, []KindSlice{ KindSlice{ - types.Int8Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, - types.Float32Kind, types.Float64Kind, + types.NumberKind, types.StringKind}, }, ) @@ -162,8 +155,7 @@ func TestSchemaDetection(t *testing.T) { }, []KindSlice{ KindSlice{ - types.Int8Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, - types.Float32Kind, types.Float64Kind, + types.NumberKind, types.StringKind}, }, ) @@ -176,8 +168,7 @@ func TestSchemaDetection(t *testing.T) { }, []KindSlice{ KindSlice{ - types.Int16Kind, types.Int32Kind, types.Int64Kind, - types.Float32Kind, types.Float64Kind, + types.NumberKind, types.StringKind}, }, ) @@ -190,8 +181,7 @@ func TestSchemaDetection(t *testing.T) { }, []KindSlice{ KindSlice{ - types.Int16Kind, types.Int32Kind, types.Int64Kind, - types.Float32Kind, types.Float64Kind, + types.NumberKind, types.StringKind}, }, ) @@ -204,8 +194,7 @@ func TestSchemaDetection(t *testing.T) { }, []KindSlice{ KindSlice{ - types.Int32Kind, types.Int64Kind, - types.Float32Kind, types.Float64Kind, + types.NumberKind, types.StringKind}, }, ) @@ -218,8 +207,7 @@ func TestSchemaDetection(t *testing.T) { }, []KindSlice{ KindSlice{ - types.Int32Kind, types.Int64Kind, - types.Float32Kind, types.Float64Kind, + types.NumberKind, types.StringKind}, }, ) @@ -232,8 +220,7 @@ func TestSchemaDetection(t *testing.T) { }, []KindSlice{ KindSlice{ - types.Int64Kind, - types.Float32Kind, types.Float64Kind, + types.NumberKind, types.StringKind}, }, ) @@ -246,8 +233,7 @@ func TestSchemaDetection(t *testing.T) { }, []KindSlice{ KindSlice{ - types.Int64Kind, - types.Float32Kind, types.Float64Kind, + types.NumberKind, types.StringKind}, }, ) @@ -259,9 +245,7 @@ func TestSchemaDetection(t *testing.T) { }, []KindSlice{ KindSlice{ - types.Uint64Kind, - types.Float32Kind, - types.Float64Kind, + types.NumberKind, types.StringKind}, }, ) @@ -273,9 +257,7 @@ func TestSchemaDetection(t *testing.T) { }, []KindSlice{ KindSlice{ - types.Uint64Kind, types.Int64Kind, - types.Float32Kind, - types.Float64Kind, + types.NumberKind, types.StringKind}, }, ) @@ -289,7 +271,7 @@ func TestReportValidFieldTypes(t *testing.T) { {"2", "false", "d6"}, } expectedKinds := []KindSlice{ - KindSlice{types.Float32Kind, types.Float64Kind, types.StringKind}, + KindSlice{types.NumberKind, types.StringKind}, KindSlice{types.BoolKind, types.StringKind}, KindSlice{types.StringKind}, } diff --git a/clients/shove/shove_test.go b/clients/shove/shove_test.go index 12b12426fa..14be124a33 100644 --- a/clients/shove/shove_test.go +++ b/clients/shove/shove_test.go @@ -24,9 +24,9 @@ func (s *testSuite) TestShove() { s.LdbFlagName = "-source-ldb" sn := "storeName" source1 := dataset.NewDataset(datas.NewDataStore(chunks.NewLevelDBStore(s.LdbDir, sn, 1, false)), "foo") - source1, err := source1.Commit(types.Int32(42)) + source1, err := source1.Commit(types.Number(42)) s.NoError(err) - source2, err := source1.Commit(types.Int32(43)) + source2, err := source1.Commit(types.Number(43)) s.NoError(err) source1HeadRef := source1.Head().Ref() source2.Store().Close() // Close DataStore backing both Datasets @@ -36,13 +36,13 @@ func (s *testSuite) TestShove() { s.Equal("", out) dest := dataset.NewDataset(datas.NewDataStore(chunks.NewLevelDBStore(ldb2dir, sn, 1, false)), "bar") - s.True(types.Int32(42).Equals(dest.Head().Get(datas.ValueField))) + s.True(types.Number(42).Equals(dest.Head().Get(datas.ValueField))) dest.Store().Close() out = s.Run(main, []string{"-source-store", sn, "-source", "foo", "-sink-ldb", ldb2dir, "-sink-ds", "bar"}) s.Equal("", out) dest = dataset.NewDataset(datas.NewDataStore(chunks.NewLevelDBStore(ldb2dir, sn, 1, false)), "bar") - s.True(types.Int32(43).Equals(dest.Head().Get(datas.ValueField))) + s.True(types.Number(43).Equals(dest.Head().Get(datas.ValueField))) dest.Store().Close() } diff --git a/clients/util/util.go b/clients/util/util.go index 52067537bc..2eefebfb86 100644 --- a/clients/util/util.go +++ b/clients/util/util.go @@ -28,7 +28,7 @@ func NomsValueFromDecodedJSON(o interface{}) types.Value { case bool: return types.Bool(o) case float64: - return types.Float64(o) + return types.Number(o) case nil: return nil case []interface{}: diff --git a/clients/util/util_test.go b/clients/util/util_test.go index e511c93eb8..824cebaacc 100644 --- a/clients/util/util_test.go +++ b/clients/util/util_test.go @@ -18,7 +18,7 @@ type LibTestSuite struct { func (suite *LibTestSuite) TestPrimitiveTypes() { suite.EqualValues(types.NewString("expected"), NomsValueFromDecodedJSON("expected")) suite.EqualValues(types.Bool(false), NomsValueFromDecodedJSON(false)) - suite.EqualValues(types.Float64(1.7), NomsValueFromDecodedJSON(1.7)) + suite.EqualValues(types.Number(1.7), NomsValueFromDecodedJSON(1.7)) suite.False(NomsValueFromDecodedJSON(1.7).Equals(types.Bool(true))) } diff --git a/dataset/dataset_test.go b/dataset/dataset_test.go index d5883198e1..809aa8527a 100644 --- a/dataset/dataset_test.go +++ b/dataset/dataset_test.go @@ -30,7 +30,7 @@ func TestDatasetCommitTracker(t *testing.T) { assert.False(ds2.Head().Get(datas.ValueField).Equals(ds1Commit)) assert.False(ds1.Head().Get(datas.ValueField).Equals(ds2Commit)) - assert.Equal("sha1-6ddf39e2ccd452d06e610713e0261cd9b31d5681", cs.Root().String()) + assert.Equal("sha1-59bf8cf4ce01e5630fe93de07464ad2a02c232ab", cs.Root().String()) } func newDS(id string, cs *chunks.MemoryStore) Dataset { diff --git a/dataset/pull_test.go b/dataset/pull_test.go index 346cf20822..b8f6e3b2d9 100644 --- a/dataset/pull_test.go +++ b/dataset/pull_test.go @@ -46,10 +46,10 @@ func pullTest(t *testing.T, topdown bool) { // Give sink and source some initial shared context. sourceInitialValue := types.NewMap( types.NewString("first"), NewList(source), - types.NewString("second"), NewList(source, types.Int32(2))) + types.NewString("second"), NewList(source, types.Number(2))) sinkInitialValue := types.NewMap( types.NewString("first"), NewList(sink), - types.NewString("second"), NewList(sink, types.Int32(2))) + types.NewString("second"), NewList(sink, types.Number(2))) var err error source, err = source.Commit(sourceInitialValue) @@ -59,13 +59,13 @@ func pullTest(t *testing.T, topdown bool) { // Add some new stuff to source. updatedValue := sourceInitialValue.Set( - types.NewString("third"), NewList(source, types.Int32(3))) + types.NewString("third"), NewList(source, types.Number(3))) source, err = source.Commit(updatedValue) assert.NoError(err) // Add some more stuff, so that source isn't directly ahead of sink. updatedValue = updatedValue.Set( - types.NewString("fourth"), NewList(source, types.Int32(4))) + types.NewString("fourth"), NewList(source, types.Number(4))) source, err = source.Commit(updatedValue) assert.NoError(err) @@ -90,10 +90,10 @@ func pullFirstCommit(t *testing.T, topdown bool) { sourceInitialValue := types.NewMap( types.NewString("first"), NewList(source), - types.NewString("second"), NewList(source, types.Int32(2))) + types.NewString("second"), NewList(source, types.Number(2))) NewList(sink) - NewList(sink, types.Int32(2)) + NewList(sink, types.Number(2)) source, err := source.Commit(sourceInitialValue) assert.NoError(err) diff --git a/js/package.json b/js/package.json index 414dbbbe3a..bdca6c2429 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "@attic/noms", - "version": "12.1.0", + "version": "13.0.0", "description": "Noms JS SDK", "repository": "https://github.com/attic-labs/noms", "main": "dist/commonjs/noms.js", diff --git a/js/src/blob-test.js b/js/src/blob-test.js index 59a2ab3774..19d89f2662 100644 --- a/js/src/blob-test.js +++ b/js/src/blob-test.js @@ -140,7 +140,7 @@ suite('Blob', () => { 100, 115, ])); - assert.equal(b.ref.toString(), 'sha1-e4a0148729ba968e05fbd5afe7b8fff18a343583'); + assert.equal(b.ref.toString(), 'sha1-14399fe2ff6d333b4c18e004b0b2ec90173ff35c'); }); test('chunks', async () => { diff --git a/js/src/compare-test.js b/js/src/compare-test.js index 4ce825551e..9c1c69ed7c 100644 --- a/js/src/compare-test.js +++ b/js/src/compare-test.js @@ -5,9 +5,8 @@ import {assert} from 'chai'; import {getCompareFunction, compare, equals} from './compare.js'; import { boolType, - float64Type, - int8Type, makeListType, + numberType, stringType, } from './type.js'; import {newList} from './list.js'; @@ -15,7 +14,7 @@ import {newList} from './list.js'; suite('compare', () => { suite('getCompareFunction', () => { test('int8', () => { - const compare = getCompareFunction(int8Type); + const compare = getCompareFunction(numberType); assert.equal(compare(1, 1), 0); assert.equal(compare(1, 3), -2); assert.equal(compare(4, 2), 2); @@ -36,15 +35,15 @@ suite('compare', () => { }); test('list', async () => { - const listOfFloat64Type = makeListType(float64Type); - const compare = getCompareFunction(listOfFloat64Type); - const listA = await newList([0, 1, 2, 3], listOfFloat64Type); - const listB = await newList([0, 1, 2, 3], listOfFloat64Type); - const listC = await newList([4, 5, 6, 7], listOfFloat64Type); + const listOfNumberType = makeListType(numberType); + const compare = getCompareFunction(listOfNumberType); + const listA = await newList([0, 1, 2, 3], listOfNumberType); + const listB = await newList([0, 1, 2, 3], listOfNumberType); + const listC = await newList([4, 5, 6, 7], listOfNumberType); assert.equal(compare(listA, listA), 0); assert.equal(compare(listA, listB), 0); - assert.equal(compare(listA, listC), 1); - assert.equal(compare(listC, listA), -1); + assert.equal(compare(listA, listC), -1); + assert.equal(compare(listC, listA), 1); }); }); @@ -68,14 +67,14 @@ suite('compare', () => { }); test('list', async () => { - const listOfFloat64Type = makeListType(float64Type); - const listA = await newList([0, 1, 2, 3], listOfFloat64Type); - const listB = await newList([0, 1, 2, 3], listOfFloat64Type); - const listC = await newList([4, 5, 6, 7], listOfFloat64Type); + const listOfNumberType = makeListType(numberType); + const listA = await newList([0, 1, 2, 3], listOfNumberType); + const listB = await newList([0, 1, 2, 3], listOfNumberType); + const listC = await newList([4, 5, 6, 7], listOfNumberType); assert.equal(compare(listA, listA), 0); assert.equal(compare(listA, listB), 0); - assert.equal(compare(listA, listC), 1); - assert.equal(compare(listC, listA), -1); + assert.equal(compare(listA, listC), -1); + assert.equal(compare(listC, listA), 1); }); }); @@ -99,10 +98,10 @@ suite('compare', () => { }); test('list', async () => { - const listOfFloat64Type = makeListType(float64Type); - const listA = await newList([0, 1, 2, 3], listOfFloat64Type); - const listB = await newList([0, 1, 2, 3], listOfFloat64Type); - const listC = await newList([4, 5, 6, 7], listOfFloat64Type); + const listOfNumberType = makeListType(numberType); + const listA = await newList([0, 1, 2, 3], listOfNumberType); + const listB = await newList([0, 1, 2, 3], listOfNumberType); + const listC = await newList([4, 5, 6, 7], listOfNumberType); assert.isTrue(equals(listA, listA)); assert.isTrue(equals(listA, listB)); assert.isFalse(equals(listA, listC)); diff --git a/js/src/compare.js b/js/src/compare.js index d98ee5c06c..45d52df6b4 100644 --- a/js/src/compare.js +++ b/js/src/compare.js @@ -81,16 +81,7 @@ function compareBools(v1: boolean, v2: boolean): number { */ export function getCompareFunction(t: Type): (v1: any, v2: any) => number { switch (t.kind) { - case Kind.Uint8: - case Kind.Uint16: - case Kind.Uint32: - case Kind.Uint64: - case Kind.Int8: - case Kind.Int16: - case Kind.Int32: - case Kind.Int64: - case Kind.Float32: - case Kind.Float64: + case Kind.Number: return compareNumbers; case Kind.String: diff --git a/js/src/data-store-test.js b/js/src/data-store-test.js index 517bf9419c..43b4debc97 100644 --- a/js/src/data-store-test.js +++ b/js/src/data-store-test.js @@ -7,7 +7,7 @@ import {assert} from 'chai'; import {default as DataStore, getDatasTypes, newCommit} from './data-store.js'; import {invariant, notNull} from './assert.js'; import {newMap} from './map.js'; -import {uint8Type, stringType, makeCompoundType} from './type.js'; +import {numberType, stringType, makeCompoundType} from './type.js'; import {Kind} from './noms-kind.js'; import {getRef} from './get-ref.js'; import {encodeNomsValue} from './encode.js'; @@ -167,7 +167,7 @@ suite('DataStore', () => { ds.writeValue(1); }); - const r3 = ds.writeValue(2, uint8Type).targetRef; + const r3 = ds.writeValue(2, numberType).targetRef; const v1 = await ds.readValue(r1); assert.equal('hello', v1); @@ -176,7 +176,7 @@ suite('DataStore', () => { const v3 = await ds.readValue(r3); assert.equal(2, v3); - const mt = makeCompoundType(Kind.Map, uint8Type, stringType); + const mt = makeCompoundType(Kind.Map, numberType, stringType); const m = await newMap([3, 'b', 4, 'c'], mt); const r4 = ds.writeValue(m).targetRef; const v4 = await ds.readValue(r4); diff --git a/js/src/decode-test.js b/js/src/decode-test.js index c1381a6325..e15629f5fc 100644 --- a/js/src/decode-test.js +++ b/js/src/decode-test.js @@ -14,22 +14,13 @@ import {decodeNomsValue, JsonArrayReader} from './decode.js'; import { boolType, Field, - float32Type, - float64Type, - int16Type, - int32Type, - int64Type, - int8Type, makeCompoundType, makeStructType, makeType, + numberType, stringType, Type, typeType, - uint16Type, - uint32Type, - uint64Type, - uint8Type, valueType, } from './type.js'; import {encode as encodeBase64} from './base64.js'; @@ -100,21 +91,11 @@ suite('Decode', () => { await doTest(true, [Kind.Bool, true]); await doTest(false, [Kind.Bool, false]); - await doTest(0, [Kind.Uint8, '0']); - await doTest(0, [Kind.Uint16, '0']); - await doTest(0, [Kind.Uint32, '0']); - await doTest(0, [Kind.Uint64, '0']); - await doTest(0, [Kind.Int8, '0']); - await doTest(0, [Kind.Int16, '0']); - await doTest(0, [Kind.Int32, '0']); - await doTest(0, [Kind.Int64, '0']); - await doTest(0, [Kind.Float32, '0']); - await doTest(0, [Kind.Float64, '0']); + await doTest(0, [Kind.Number, '0']); - await doTest(1e18, [Kind.Int64, '1000000000000000000']); - await doTest(1e19, [Kind.Uint64, '10000000000000000000']); - await doTest(1e19, [Kind.Float64, '10000000000000000000']); - await doTest(1e20, [Kind.Float64, '1e+20']); + await doTest(1e18, [Kind.Number, '1000000000000000000']); + await doTest(1e19, [Kind.Number, '10000000000000000000']); + await doTest(1e20, [Kind.Number, '1e+20']); await doTest('hi', [Kind.String, 'hi']); }); @@ -122,12 +103,12 @@ suite('Decode', () => { test('read list of int 32', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const a = [Kind.List, Kind.Int32, false, ['0', '1', '2', '3']]; + const a = [Kind.List, Kind.Number, false, ['0', '1', '2', '3']]; const r = new JsonArrayReader(a, ds); const v:NomsList = await r.readTopLevelValue(); invariant(v instanceof NomsList); - const tr = makeCompoundType(Kind.List, int32Type); + const tr = makeCompoundType(Kind.List, numberType); const l = new NomsList(tr, new ListLeafSequence(ds, tr, [0, 1, 2, 3])); assert.isTrue(l.equals(v)); }); @@ -136,7 +117,8 @@ suite('Decode', () => { test('read list of value', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const a = [Kind.List, Kind.Value, false, [Kind.Int32, '1', Kind.String, 'hi', Kind.Bool, true]]; + const a = [Kind.List, Kind.Value, false, + [Kind.Number, '1', Kind.String, 'hi', Kind.Bool, true]]; const r = new JsonArrayReader(a, ds); const v:NomsList = await r.readTopLevelValue(); invariant(v instanceof NomsList); @@ -151,12 +133,12 @@ suite('Decode', () => { test('read value list of int8', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const a = [Kind.Value, Kind.List, Kind.Int8, false, ['0', '1', '2']]; + const a = [Kind.Value, Kind.List, Kind.Number, false, ['0', '1', '2']]; const r = new JsonArrayReader(a, ds); const v = await r.readTopLevelValue(); invariant(v instanceof NomsList); - const tr = makeCompoundType(Kind.List, int8Type); + const tr = makeCompoundType(Kind.List, numberType); const l = new NomsList(tr, new ListLeafSequence(ds, tr, [0, 1, 2])); assert.isTrue(l.equals(v)); }); @@ -164,7 +146,7 @@ suite('Decode', () => { test('read compound list', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const ltr = makeCompoundType(Kind.List, int32Type); + const ltr = makeCompoundType(Kind.List, numberType); const r1 = ds.writeValue(new NomsList(ltr, new ListLeafSequence(ds, ltr, [0]))).targetRef; const r2 = ds.writeValue(new NomsList(ltr, new ListLeafSequence(ds, ltr, [1, 2]))).targetRef; const r3 = ds.writeValue(new NomsList(ltr, new ListLeafSequence(ds, ltr, [3, 4, 5]))).targetRef; @@ -175,7 +157,7 @@ suite('Decode', () => { ]; const l:NomsList = new NomsList(ltr, new IndexedMetaSequence(ds, ltr, tuples)); - const a = [Kind.List, Kind.Int32, true, + const a = [Kind.List, Kind.Number, true, [r1.toString(), '1', '1', r2.toString(), '2', '2', r3.toString(), '3', '3']]; const r = new JsonArrayReader(a, ds); const v = await r.readTopLevelValue(); @@ -186,13 +168,13 @@ suite('Decode', () => { test('read map of int64 to float64', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const a = [Kind.Map, Kind.Int64, Kind.Float64, false, ['0', '1', '2', '3']]; + const a = [Kind.Map, Kind.Number, Kind.Number, false, ['0', '1', '2', '3']]; const r = new JsonArrayReader(a, ds); const v:NomsMap = await r.readTopLevelValue(); invariant(v instanceof NomsMap); - const t = makeCompoundType(Kind.Map, int64Type, - float64Type); + const t = makeCompoundType(Kind.Map, numberType, + numberType); const m = new NomsMap(t, new MapLeafSequence(ds, t, [{key: 0, value: 1}, {key: 2, value: 3}])); assert.isTrue(v.equals(m)); }); @@ -200,7 +182,7 @@ suite('Decode', () => { test('read map of ref to uint64', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const a = [Kind.Map, Kind.Ref, Kind.Value, Kind.Uint64, false, + const a = [Kind.Map, Kind.Ref, Kind.Value, Kind.Number, false, ['sha1-0000000000000000000000000000000000000001', '2', 'sha1-0000000000000000000000000000000000000002', '4']]; const r = new JsonArrayReader(a, ds); @@ -208,7 +190,7 @@ suite('Decode', () => { invariant(v instanceof NomsMap); const refOfValueType = makeCompoundType(Kind.Ref, valueType); - const mapType = makeCompoundType(Kind.Map, refOfValueType, uint64Type); + const mapType = makeCompoundType(Kind.Map, refOfValueType, numberType); const rv1 = new RefValue(new Ref('sha1-0000000000000000000000000000000000000001'), refOfValueType); const rv2 = new RefValue(new Ref('sha1-0000000000000000000000000000000000000002'), @@ -221,13 +203,13 @@ suite('Decode', () => { test('read value map of uint64 to uint32', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const a = [Kind.Value, Kind.Map, Kind.Uint64, Kind.Uint32, false, ['0', '1', '2', '3']]; + const a = [Kind.Value, Kind.Map, Kind.Number, Kind.Number, false, ['0', '1', '2', '3']]; const r = new JsonArrayReader(a, ds); const v:NomsMap = await r.readTopLevelValue(); invariant(v instanceof NomsMap); - const t = makeCompoundType(Kind.Map, uint64Type, - uint32Type); + const t = makeCompoundType(Kind.Map, numberType, + numberType); const m = new NomsMap(t, new MapLeafSequence(ds, t, [{key: 0, value: 1}, {key: 2, value: 3}])); assert.isTrue(v.equals(m)); }); @@ -235,12 +217,12 @@ suite('Decode', () => { test('read set of uint8', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const a = [Kind.Set, Kind.Uint8, false, ['0', '1', '2', '3']]; + const a = [Kind.Set, Kind.Number, false, ['0', '1', '2', '3']]; const r = new JsonArrayReader(a, ds); const v:NomsSet = await r.readTopLevelValue(); invariant(v instanceof NomsSet); - const t = makeCompoundType(Kind.Set, uint8Type); + const t = makeCompoundType(Kind.Set, numberType); const s = new NomsSet(t, new SetLeafSequence(ds, t, [0, 1, 2, 3])); assert.isTrue(v.equals(s)); }); @@ -248,7 +230,7 @@ suite('Decode', () => { test('read compound set', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const ltr = makeCompoundType(Kind.Set, int32Type); + const ltr = makeCompoundType(Kind.Set, numberType); const r1 = ds.writeValue(new NomsSet(ltr, new SetLeafSequence(ds, ltr, [0]))).targetRef; const r2 = ds.writeValue(new NomsSet(ltr, new SetLeafSequence(ds, ltr, [1, 2]))).targetRef; const r3 = ds.writeValue(new NomsSet(ltr, new SetLeafSequence(ds, ltr, [3, 4, 5]))).targetRef; @@ -259,7 +241,7 @@ suite('Decode', () => { ]; const l:NomsSet = new NomsSet(ltr, new OrderedMetaSequence(ds, ltr, tuples)); - const a = [Kind.Set, Kind.Int32, true, + const a = [Kind.Set, Kind.Number, true, [r1.toString(), '0', '1', r2.toString(), '2', '2', r3.toString(), '5', '3']]; const r = new JsonArrayReader(a, ds); const v = await r.readTopLevelValue(); @@ -270,12 +252,12 @@ suite('Decode', () => { test('read value set of uint16', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const a = [Kind.Value, Kind.Set, Kind.Uint16, false, ['0', '1', '2', '3']]; + const a = [Kind.Value, Kind.Set, Kind.Number, false, ['0', '1', '2', '3']]; const r = new JsonArrayReader(a, ds); const v:NomsSet = await r.readTopLevelValue(); invariant(v instanceof NomsSet); - const t = makeCompoundType(Kind.Set, uint16Type); + const t = makeCompoundType(Kind.Set, numberType); const s = new NomsSet(t, new SetLeafSequence(ds, t, [0, 1, 2, 3])); assert.isTrue(v.equals(s)); }); @@ -295,7 +277,7 @@ suite('Decode', () => { const ms = new MemoryStore(); const ds = new DataStore(ms); const tr = makeStructType('A1', [ - new Field('x', int16Type, false), + new Field('x', numberType, false), new Field('s', stringType, false), new Field('b', boolType, false), ], []); @@ -318,7 +300,7 @@ suite('Decode', () => { const ms = new MemoryStore(); const ds = new DataStore(ms); const tr = makeStructType('A2', [ - new Field('x', float32Type, false), + new Field('x', numberType, false), ], [ new Field('b', boolType, false), new Field('s', stringType, false), @@ -341,7 +323,7 @@ suite('Decode', () => { const ms = new MemoryStore(); const ds = new DataStore(ms); const tr = makeStructType('A3', [ - new Field('x', float32Type, false), + new Field('x', numberType, false), new Field('s', stringType, true), new Field('b', boolType, true), ], []); @@ -362,7 +344,7 @@ suite('Decode', () => { test('test read struct with list', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const ltr = makeCompoundType(Kind.List, int32Type); + const ltr = makeCompoundType(Kind.List, numberType); const tr = makeStructType('A4', [ new Field('b', boolType, false), new Field('l', ltr, false), @@ -395,7 +377,7 @@ suite('Decode', () => { const pkg = new Package([tr], []); registerPackage(pkg); - const a = [Kind.Unresolved, pkg.ref.toString(), '0', true, Kind.Uint8, '42', 'hi']; + const a = [Kind.Unresolved, pkg.ref.toString(), '0', true, Kind.Number, '42', 'hi']; const r = new JsonArrayReader(a, ds); const v = await r.readTopLevelValue(); @@ -410,7 +392,7 @@ suite('Decode', () => { const ms = new MemoryStore(); const ds = new DataStore(ms); const tr = makeStructType('A1', [ - new Field('x', int16Type, false), + new Field('x', numberType, false), new Field('s', stringType, false), new Field('b', boolType, false), ], []); @@ -434,7 +416,7 @@ suite('Decode', () => { const ds = new DataStore(ms); const tr = makeStructType('s', [ new Field('b', boolType, false), - new Field('i', int32Type, false), + new Field('i', numberType, false), ], []); const pkg = new Package([tr], []); @@ -457,10 +439,10 @@ suite('Decode', () => { const ms = new MemoryStore(); const ds = new DataStore(ms); const chunk = Chunk.fromString( - `t [${Kind.Value}, ${Kind.Set}, ${Kind.Uint16}, false, ["0", "1", "2", "3"]]`); + `t [${Kind.Value}, ${Kind.Set}, ${Kind.Number}, false, ["0", "1", "2", "3"]]`); const v:NomsSet = await decodeNomsValue(chunk, new DataStore(new MemoryStore())); - const t = makeCompoundType(Kind.Set, uint16Type); + const t = makeCompoundType(Kind.Set, numberType); const s:NomsSet = new NomsSet(t, new SetLeafSequence(ds, t, [0, 1, 2, 3])); assert.isTrue(v.equals(s)); }); @@ -486,7 +468,7 @@ suite('Decode', () => { // Commit value const commitChunk = makeChunk( - [Kind.Unresolved, pkgRef.toString(), '0', Kind.Uint64, '1', false, []]); + [Kind.Unresolved, pkgRef.toString(), '0', Kind.Number, '1', false, []]); const commitRef = commitChunk.ref; ms.put(commitChunk); diff --git a/js/src/decode.js b/js/src/decode.js index d44ef17c59..27e22da981 100644 --- a/js/src/decode.js +++ b/js/src/decode.js @@ -19,7 +19,7 @@ import { StructDesc, Type, typeType, - uint64Type, + numberType, } from './type.js'; import {indexTypeForMetaSequence, MetaTuple, newMetaSequenceFromData} from './meta-sequence.js'; import {invariant, notNull} from './assert.js'; @@ -187,7 +187,7 @@ export class JsonArrayReader { while (!this.atEnd()) { const ref = this.readRef(); const v = this.readValueWithoutTag(indexType, pkg); - const numLeaves = this.readValueWithoutTag(uint64Type, pkg); + const numLeaves = this.readValueWithoutTag(numberType, pkg); data.push(new MetaTuple(ref, v, numLeaves)); } @@ -257,19 +257,8 @@ export class JsonArrayReader { } case Kind.Bool: return this.readBool(); - case Kind.Float32: - case Kind.Float64: + case Kind.Number: return this.readFloat(); - case Kind.Int8: - case Kind.Int16: - case Kind.Int32: - case Kind.Int64: - return this.readInt(); - case Kind.Uint8: - case Kind.Uint16: - case Kind.Uint32: - case Kind.Uint64: - return this.readUint(); case Kind.String: return this.readString(); case Kind.Value: { diff --git a/js/src/defs-test.js b/js/src/defs-test.js index 937de13f26..26ab78b9b5 100644 --- a/js/src/defs-test.js +++ b/js/src/defs-test.js @@ -6,14 +6,13 @@ import {Package, registerPackage} from './package.js'; import { boolType, Field, - float64Type, makeListType, makeMapType, makeSetType, makeStructType, makeType, + numberType, stringType, - uint8Type, } from './type.js'; import {defToNoms} from './defs.js'; import {newList} from './list.js'; @@ -31,7 +30,7 @@ suite('defs', () => { }); test('number', async () => { - const v = await defToNoms(123, uint8Type); + const v = await defToNoms(123, numberType); assert.equal(v, 123); }); @@ -41,13 +40,13 @@ suite('defs', () => { }); test('list', async () => { - const listOfUint8Type = makeListType(uint8Type); - const l1 = await newList([0, 1, 2, 3], listOfUint8Type); - const l2 = await defToNoms([0, 1, 2, 3], listOfUint8Type); + const listOfNumberType = makeListType(numberType); + const l1 = await newList([0, 1, 2, 3], listOfNumberType); + const l2 = await defToNoms([0, 1, 2, 3], listOfNumberType); invariant(l2 instanceof ValueBase); assert.isTrue(l1.equals(l2)); - const l3 = await defToNoms(l1, listOfUint8Type); + const l3 = await defToNoms(l1, listOfNumberType); invariant(l3 instanceof ValueBase); assert.isTrue(l1.equals(l3)); @@ -61,9 +60,9 @@ suite('defs', () => { }); test('set', async () => { - const setOfFloat64Type = makeSetType(float64Type); - const s1 = await newSet([0, 1, 2, 3], setOfFloat64Type); - const s2 = await defToNoms([0, 1, 2, 3], setOfFloat64Type); + const setOfNumberType = makeSetType(numberType); + const s1 = await newSet([0, 1, 2, 3], setOfNumberType); + const s2 = await defToNoms([0, 1, 2, 3], setOfNumberType); invariant(s2 instanceof ValueBase); assert.isTrue(s1.equals(s2)); @@ -77,15 +76,15 @@ suite('defs', () => { }); test('map', async () => { - const mapOfFloat64ToStringType = makeMapType(float64Type, stringType); - const m1 = await newMap([0, 'zero', 1, 'one'], mapOfFloat64ToStringType); - const m2 = await defToNoms([0, 'zero', 1, 'one'], mapOfFloat64ToStringType); + const mapOfNumberToStringType = makeMapType(numberType, stringType); + const m1 = await newMap([0, 'zero', 1, 'one'], mapOfNumberToStringType); + const m2 = await defToNoms([0, 'zero', 1, 'one'], mapOfNumberToStringType); invariant(m2 instanceof ValueBase); assert.isTrue(m1.equals(m2)); let ex; try { - await defToNoms(m1, makeMapType(stringType, float64Type)); + await defToNoms(m1, makeMapType(stringType, numberType)); } catch (e) { ex = e; } @@ -117,17 +116,17 @@ suite('defs', () => { test('struct with list', async () => { let typeDef; - const listOfUint8Type = makeListType(uint8Type); + const listOfNumberType = makeListType(numberType); const pkg = new Package([ typeDef = makeStructType('StructWithList', [ - new Field('l', listOfUint8Type, false), + new Field('l', listOfNumberType, false), ], []), ], []); registerPackage(pkg); const type = makeType(pkg.ref, 0); const s1 = newStruct(type, typeDef, { - l: await newList([0, 1, 2, 3], listOfUint8Type), + l: await newList([0, 1, 2, 3], listOfNumberType), }); const s2 = await defToNoms({ @@ -142,7 +141,7 @@ suite('defs', () => { let typeDef; const pkg = new Package([ typeDef = makeStructType('Struct', [ - new Field('i', uint8Type, false), + new Field('i', numberType, false), ], []), ], []); registerPackage(pkg); diff --git a/js/src/encode-test.js b/js/src/encode-test.js index c499d164fc..50594a9aed 100644 --- a/js/src/encode-test.js +++ b/js/src/encode-test.js @@ -13,24 +13,15 @@ import { blobType, boolType, Field, - float32Type, - float64Type, - int16Type, - int32Type, - int64Type, - int8Type, makeCompoundType, makeListType, makeMapType, makeSetType, makeStructType, makeType, + numberType, stringType, Type, - uint16Type, - uint32Type, - uint64Type, - uint8Type, valueType, } from './type.js'; import {IndexedMetaSequence, MetaTuple, OrderedMetaSequence} from './meta-sequence.js'; @@ -55,21 +46,11 @@ suite('Encode', () => { f(Kind.Bool, boolType, true, true); f(Kind.Bool, boolType, false, false); - f(Kind.Uint8, uint8Type, 0, '0'); - f(Kind.Uint16, uint16Type, 0, '0'); - f(Kind.Uint32, uint32Type, 0, '0'); - f(Kind.Uint64, uint64Type, 0, '0'); - f(Kind.Int8, int8Type, 0, '0'); - f(Kind.Int16, int16Type, 0, '0'); - f(Kind.Int32, int32Type, 0, '0'); - f(Kind.Int64, int64Type, 0, '0'); - f(Kind.Float32, float32Type, 0, '0'); - f(Kind.Float64, float64Type, 0, '0'); + f(Kind.Number, numberType, 0, '0'); - f(Kind.Int64, int64Type, 1e18, '1000000000000000000'); - f(Kind.Uint64, uint64Type, 1e19, '10000000000000000000'); - f(Kind.Float64, float64Type, 1e19, '10000000000000000000'); - f(Kind.Float64, float64Type, 1e20, '1e+20'); + f(Kind.Number, numberType, 1e18, '1000000000000000000'); + f(Kind.Number, numberType, 1e19, '10000000000000000000'); + f(Kind.Number, numberType, 1e20, '1e+20'); f(Kind.String, stringType, 'hi', 'hi'); }); @@ -88,10 +69,10 @@ suite('Encode', () => { const ds = new DataStore(ms); const w = new JsonArrayWriter(ds); - const tr = makeCompoundType(Kind.List, int32Type); + const tr = makeCompoundType(Kind.List, numberType); const l = new NomsList(tr, new ListLeafSequence(ds, tr, [0, 1, 2, 3])); w.writeTopLevel(tr, l); - assert.deepEqual([Kind.List, Kind.Int32, false, ['0', '1', '2', '3']], w.array); + assert.deepEqual([Kind.List, Kind.Number, false, ['0', '1', '2', '3']], w.array); }); test('write list of value', async () => { @@ -115,14 +96,14 @@ suite('Encode', () => { const ds = new DataStore(ms); const w = new JsonArrayWriter(ds); - const it = makeCompoundType(Kind.List, int16Type); + const it = makeCompoundType(Kind.List, numberType); const tr = makeCompoundType(Kind.List, it); const v = new NomsList(tr, new ListLeafSequence(ds, tr, [ new NomsList(tr, new ListLeafSequence(ds, it, [0])), new NomsList(tr, new ListLeafSequence(ds, it, [1, 2, 3])), ])); w.writeTopLevel(tr, v); - assert.deepEqual([Kind.List, Kind.List, Kind.Int16, false, [false, ['0'], false, + assert.deepEqual([Kind.List, Kind.List, Kind.Number, false, [false, ['0'], false, ['1', '2', '3']]], w.array); }); @@ -131,17 +112,17 @@ suite('Encode', () => { const ds = new DataStore(ms); const w = new JsonArrayWriter(ds); - const tr = makeCompoundType(Kind.Set, uint32Type); + const tr = makeCompoundType(Kind.Set, numberType); const v = new NomsSet(tr, new SetLeafSequence(ds, tr, [0, 1, 2, 3])); w.writeTopLevel(tr, v); - assert.deepEqual([Kind.Set, Kind.Uint32, false, ['0', '1', '2', '3']], w.array); + assert.deepEqual([Kind.Set, Kind.Number, false, ['0', '1', '2', '3']], w.array); }); test('write compound set', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); const w = new JsonArrayWriter(ds); - const ltr = makeCompoundType(Kind.Set, int32Type); + const ltr = makeCompoundType(Kind.Set, numberType); const r1 = ds.writeValue(new NomsSet(ltr, new SetLeafSequence(ds, ltr, [0]))).targetRef; const r2 = ds.writeValue(new NomsSet(ltr, new SetLeafSequence(ds, ltr, [1, 2]))).targetRef; const r3 = ds.writeValue(new NomsSet(ltr, new SetLeafSequence(ds, ltr, [3, 4, 5]))).targetRef; @@ -153,7 +134,7 @@ suite('Encode', () => { const l = new NomsSet(ltr, new OrderedMetaSequence(ds, ltr, tuples)); w.writeTopLevel(ltr, l); - assert.deepEqual([Kind.Set, Kind.Int32, true, [r1.toString(), '0', '1', r2.toString(), '2', + assert.deepEqual([Kind.Set, Kind.Number, true, [r1.toString(), '0', '1', r2.toString(), '2', '2', r3.toString(), '5', '3']], w.array); }); @@ -162,7 +143,7 @@ suite('Encode', () => { const ds = new DataStore(ms); const w = new JsonArrayWriter(ds); - const st = makeCompoundType(Kind.Set, int32Type); + const st = makeCompoundType(Kind.Set, numberType); const tr = makeCompoundType(Kind.Set, st); const v = new NomsSet(tr, new SetLeafSequence(ds, tr, [ new NomsSet(tr, new SetLeafSequence(ds, st, [0])), @@ -170,7 +151,7 @@ suite('Encode', () => { ])); w.writeTopLevel(tr, v); - assert.deepEqual([Kind.Set, Kind.Set, Kind.Int32, false, [false, ['0'], false, + assert.deepEqual([Kind.Set, Kind.Set, Kind.Number, false, [false, ['0'], false, ['1', '2', '3']]], w.array); }); @@ -191,7 +172,7 @@ suite('Encode', () => { const ds = new DataStore(ms); const w = new JsonArrayWriter(ds); - const kt = makeCompoundType(Kind.Map, stringType, int64Type); + const kt = makeCompoundType(Kind.Map, stringType, numberType); const vt = makeCompoundType(Kind.Set, boolType); const tr = makeCompoundType(Kind.Map, kt, vt); @@ -199,7 +180,7 @@ suite('Encode', () => { const m1 = new NomsMap(kt, new MapLeafSequence(ds, kt, [{key: 'a', value: 0}])); const v = new NomsMap(kt, new MapLeafSequence(ds, tr, [{key: m1, value: s}])); w.writeTopLevel(tr, v); - assert.deepEqual([Kind.Map, Kind.Map, Kind.String, Kind.Int64, Kind.Set, Kind.Bool, false, + assert.deepEqual([Kind.Map, Kind.Map, Kind.String, Kind.Number, Kind.Set, Kind.Bool, false, [false, ['a', '0'], false, [true]]], w.array); }); @@ -226,7 +207,7 @@ suite('Encode', () => { const w = new JsonArrayWriter(ds); const typeDef = makeStructType('S', [ - new Field('x', int8Type, false), + new Field('x', numberType, false), new Field('b', boolType, false), ], []); const pkg = new Package([typeDef], []); @@ -246,7 +227,7 @@ suite('Encode', () => { let w = new JsonArrayWriter(ds); const typeDef = makeStructType('S', [ - new Field('x', int8Type, true), + new Field('x', numberType, true), new Field('b', boolType, false), ], []); const pkg = new Package([typeDef], []); @@ -270,7 +251,7 @@ suite('Encode', () => { let w = new JsonArrayWriter(ds); const typeDef = makeStructType('S', [ - new Field('x', int8Type, false), + new Field('x', numberType, false), ], [ new Field('b', boolType, false), new Field('s', stringType, false), @@ -321,7 +302,7 @@ suite('Encode', () => { const w = new JsonArrayWriter(ds); const s2TypeDef = makeStructType('S2', [ - new Field('x', int32Type, false), + new Field('x', numberType, false), ], []); let sTypeDef = makeStructType('S', [ new Field('s', makeType(emptyRef, 0), false), @@ -343,7 +324,7 @@ suite('Encode', () => { const ms = new MemoryStore(); const ds = new DataStore(ms); const w = new JsonArrayWriter(ds); - const ltr = makeCompoundType(Kind.List, int32Type); + const ltr = makeCompoundType(Kind.List, numberType); const r1 = ds.writeValue(new NomsList(ltr, new ListLeafSequence(ds, ltr, [0]))).targetRef; const r2 = ds.writeValue(new NomsList(ltr, new ListLeafSequence(ds, ltr, [1, 2]))).targetRef; const r3 = ds.writeValue(new NomsList(ltr, new ListLeafSequence(ds, ltr, [3, 4, 5]))).targetRef; @@ -355,7 +336,7 @@ suite('Encode', () => { const l = new NomsList(ltr, new IndexedMetaSequence(ds, ltr, tuples)); w.writeTopLevel(ltr, l); - assert.deepEqual([Kind.List, Kind.Int32, true, [r1.toString(), '1', '1', r2.toString(), '2', + assert.deepEqual([Kind.List, Kind.Number, true, [r1.toString(), '1', '1', r2.toString(), '2', '2', r3.toString(), '3', '3']], w.array); }); @@ -369,19 +350,19 @@ suite('Encode', () => { assert.deepEqual(expected, w.array); }; - test([Kind.Type, Kind.Int32], int32Type); + test([Kind.Type, Kind.Number], numberType); test([Kind.Type, Kind.List, [Kind.Bool]], makeCompoundType(Kind.List, boolType)); test([Kind.Type, Kind.Map, [Kind.Bool, Kind.String]], makeCompoundType(Kind.Map, boolType, stringType)); - test([Kind.Type, Kind.Struct, 'S', ['x', Kind.Int16, false, 'v', Kind.Value, true], []], + test([Kind.Type, Kind.Struct, 'S', ['x', Kind.Number, false, 'v', Kind.Value, true], []], makeStructType('S', [ - new Field('x', int16Type, false), + new Field('x', numberType, false), new Field('v', valueType, true), ], [])); - test([Kind.Type, Kind.Struct, 'S', [], ['x', Kind.Int16, false, 'v', Kind.Value, false]], + test([Kind.Type, Kind.Struct, 'S', [], ['x', Kind.Number, false, 'v', Kind.Value, false]], makeStructType('S', [], [ - new Field('x', int16Type, false), + new Field('x', numberType, false), new Field('v', valueType, false), ])); @@ -389,10 +370,10 @@ suite('Encode', () => { test([Kind.Type, Kind.Unresolved, pkgRef.toString(), '123'], makeType(pkgRef, 123)); test([Kind.Type, Kind.Struct, 'S', - ['e', Kind.Unresolved, pkgRef.toString(), '123', false, 'x', Kind.Int64, false], []], + ['e', Kind.Unresolved, pkgRef.toString(), '123', false, 'x', Kind.Number, false], []], makeStructType('S', [ new Field('e', makeType(pkgRef, 123), false), - new Field('x', int64Type, false), + new Field('x', numberType, false), ], [])); // test([Kind.Type, Kind.Unresolved, new Ref().toString(), -1, 'ns', 'n'], @@ -457,8 +438,7 @@ suite('Encode', () => { assert.ok(false, `Expected error, 'Failed to write ${et}. Invalid type: ${at}' but Got none`); }; - test('Int8', 'string', int8Type, 'hi'); - test('Float64', 'string', float64Type, 'hi'); + test('Number', 'string', numberType, 'hi'); test('Bool', 'string', boolType, 'hi'); test('Blob', 'string', blobType, 'hi'); @@ -466,36 +446,31 @@ suite('Encode', () => { test('Bool', 'number', boolType, 42); test('Blob', 'number', blobType, 42); - test('Int8', 'boolean', int8Type, true); - test('Float64', 'boolean', float64Type, true); + test('Number', 'boolean', numberType, true); test('String', 'boolean', stringType, true); test('Blob', 'boolean', blobType, true); const blob = await newBlob(new Uint8Array([0, 1])); - test('Int8', 'Blob', int8Type, blob); - test('Float64', 'Blob', float64Type, blob); + test('Number', 'Blob', numberType, blob); test('String', 'Blob', stringType, blob); test('Bool', 'Blob', boolType, blob); - const list = await newList([0, 1], makeListType(int8Type)); - test('Int8', 'List', int8Type, list); - test('Float64', 'List', float64Type, list); - test('String', 'List', stringType, list); - test('Bool', 'List', boolType, list); - test('Blob', 'List', blobType, list); + const list = await newList([0, 1], makeListType(numberType)); + test('Number', 'List', numberType, list); + test('String', 'List', stringType, list); + test('Bool', 'List', boolType, list); + test('Blob', 'List', blobType, list); - const map = await newMap(['zero', 1], makeMapType(stringType, int8Type)); - test('Int8', 'Map', int8Type, map); - test('Float64', 'Map', float64Type, map); - test('String', 'Map', stringType, map); - test('Bool', 'Map', boolType, map); - test('Blob', 'Map', blobType, map); + const map = await newMap(['zero', 1], makeMapType(stringType, numberType)); + test('Number', 'Map', numberType, map); + test('String', 'Map', stringType, map); + test('Bool', 'Map', boolType, map); + test('Blob', 'Map', blobType, map); - const set = await newSet([0, 1], makeSetType(int8Type)); - test('Int8', 'Set', int8Type, set); - test('Float64', 'Set', float64Type, set); - test('String', 'Set', stringType, set); - test('Bool', 'Set', boolType, set); - test('Blob', 'Set', blobType, set); + const set = await newSet([0, 1], makeSetType(numberType)); + test('Number', 'Set', numberType, set); + test('String', 'Set', stringType, set); + test('Bool', 'Set', boolType, set); + test('Blob', 'Set', blobType, set); }); }); diff --git a/js/src/encode.js b/js/src/encode.js index de12179262..410f803c57 100644 --- a/js/src/encode.js +++ b/js/src/encode.js @@ -8,7 +8,7 @@ import {default as Struct, StructMirror} from './struct.js'; import type DataStore from './data-store.js'; import type {NomsKind} from './noms-kind.js'; import {encode as encodeBase64} from './base64.js'; -import {boolType, stringType, StructDesc, Type, typeType, uint64Type} from './type.js'; +import {boolType, stringType, StructDesc, Type, typeType, numberType} from './type.js'; import {indexTypeForMetaSequence, MetaTuple} from './meta-sequence.js'; import {invariant, notNull} from './assert.js'; import {isPrimitiveKind, Kind} from './noms-kind.js'; @@ -111,7 +111,7 @@ export class JsonArrayWriter { } w2.writeRef(tuple.ref); w2.writeValue(tuple.value, indexType, pkg); - w2.writeValue(tuple.numLeaves, uint64Type, pkg); + w2.writeValue(tuple.numLeaves, numberType, pkg); } this.write(w2.array); return true; @@ -141,24 +141,11 @@ export class JsonArrayWriter { `Failed to write String. Invalid type: ${describeType(v)}`); this.write(v); break; - case Kind.Float32: - case Kind.Float64: + case Kind.Number: invariant(typeof v === 'number', `Failed to write ${t.describe()}. Invalid type: ${describeType(v)}`); this.writeFloat(v); // TODO: Verify value fits in type break; - case Kind.Uint8: - case Kind.Uint16: - case Kind.Uint32: - case Kind.Uint64: - case Kind.Int8: - case Kind.Int16: - case Kind.Int32: - case Kind.Int64: - invariant(typeof v === 'number', - `Failed to write ${t.describe()}. Invalid type: ${describeType(v)}`); - this.writeInt(v); // TODO: Verify value fits in type - break; case Kind.List: { invariant(v instanceof NomsList || v instanceof Sequence, `Failed to write List. Invalid type: ${describeType(v)}`); diff --git a/js/src/list-test.js b/js/src/list-test.js index c2809f6c0c..0eb5e1299e 100644 --- a/js/src/list-test.js +++ b/js/src/list-test.js @@ -10,11 +10,10 @@ import {newStruct} from './struct.js'; import {calcSplices} from './edit-distance.js'; import { Field, - int32Type, - int64Type, makeCompoundType, makeStructType, makeType, + numberType, stringType, valueType, } from './type.js'; @@ -27,7 +26,7 @@ import {Package, registerPackage} from './package.js'; import type {Type} from './type.js'; const testListSize = 5000; -const listOfNRef = 'sha1-36cffb3ac5fb12d3b0970c3de40b85c14cd1590b'; +const listOfNRef = 'sha1-df0a58e5fb11b2bc0adbab07c2f39c6b3e02b42b'; async function assertToJS(list: NomsList, nums: Array, start: number = 0, end: number = nums.length): Promise { @@ -53,7 +52,7 @@ suite('BuildList', () => { test('set of n numbers, length', async () => { const nums = firstNNumbers(testListSize); - const tr = makeCompoundType(Kind.List, int64Type); + const tr = makeCompoundType(Kind.List, numberType); const s = await newList(nums, tr); assert.strictEqual(s.ref.toString(), listOfNRef); assert.strictEqual(testListSize, s.length); @@ -63,7 +62,7 @@ suite('BuildList', () => { const nums = firstNNumbers(testListSize); const structTypeDef = makeStructType('num', [ - new Field('n', int64Type, false), + new Field('n', numberType, false), ], []); const pkg = new Package([structTypeDef], []); registerPackage(pkg); @@ -79,13 +78,13 @@ suite('BuildList', () => { }); const s = await newList(refs, tr); - assert.strictEqual(s.ref.toString(), 'sha1-7e7dc681c6b101175362d47d22af1a4c05d59b25'); + assert.strictEqual(s.ref.toString(), 'sha1-f2e6c3aae6e8ac4c3776830e2d8141fc527c55c5'); assert.strictEqual(testListSize, s.length); }); test('toJS', async () => { const nums = firstNNumbers(5000); - const tr = makeCompoundType(Kind.List, int64Type); + const tr = makeCompoundType(Kind.List, numberType); const s = await newList(nums, tr); assert.strictEqual(s.ref.toString(), listOfNRef); assert.strictEqual(testListSize, s.length); @@ -105,7 +104,7 @@ suite('BuildList', () => { test('insert', async () => { const nums = firstNNumbers(testListSize - 10); - const tr = makeCompoundType(Kind.List, int64Type); + const tr = makeCompoundType(Kind.List, numberType); let s = await newList(nums, tr); for (let i = testListSize - 10; i < testListSize; i++) { @@ -117,7 +116,7 @@ suite('BuildList', () => { test('append', async () => { const nums = firstNNumbers(testListSize - 10); - const tr = makeCompoundType(Kind.List, int64Type); + const tr = makeCompoundType(Kind.List, numberType); let s = await newList(nums, tr); for (let i = testListSize - 10; i < testListSize; i++) { @@ -129,7 +128,7 @@ suite('BuildList', () => { test('remove', async () => { const nums = firstNNumbers(testListSize + 10); - const tr = makeCompoundType(Kind.List, int64Type); + const tr = makeCompoundType(Kind.List, numberType); let s = await newList(nums, tr); let count = 10; @@ -142,7 +141,7 @@ suite('BuildList', () => { test('splice', async () => { const nums = firstNNumbers(testListSize); - const tr = makeCompoundType(Kind.List, int64Type); + const tr = makeCompoundType(Kind.List, numberType); let s = await newList(nums, tr); const splice500At = async (idx: number) => { @@ -163,7 +162,7 @@ suite('BuildList', () => { const ds = new DataStore(ms); const nums = firstNNumbers(testListSize); - const tr = makeCompoundType(Kind.List, int64Type); + const tr = makeCompoundType(Kind.List, numberType); const s = await newList(nums, tr); const r = ds.writeValue(s).targetRef; const s2 = await ds.readValue(r); @@ -202,7 +201,7 @@ suite('ListLeafSequence', () => { test('forEach', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const tr = makeCompoundType(Kind.List, int32Type); + const tr = makeCompoundType(Kind.List, numberType); const l = new NomsList(tr, new ListLeafSequence(ds, tr, [4, 2, 10, 16])); const values = []; @@ -213,7 +212,7 @@ suite('ListLeafSequence', () => { test('iterator', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const tr = makeCompoundType(Kind.List, int32Type); + const tr = makeCompoundType(Kind.List, numberType); const test = async items => { const l = new NomsList(tr, new ListLeafSequence(ds, tr, items)); @@ -229,7 +228,7 @@ suite('ListLeafSequence', () => { test('iteratorAt', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const tr = makeCompoundType(Kind.List, int32Type); + const tr = makeCompoundType(Kind.List, numberType); const test = async items => { const l = new NomsList(tr, new ListLeafSequence(ds, tr, items)); @@ -398,7 +397,7 @@ suite('Diff List', () => { const directDiff = calcSplices(nums1.length, nums2.length, (i, j) => nums1[i] === nums2[j]); - const tr = makeCompoundType(Kind.List, int64Type); + const tr = makeCompoundType(Kind.List, numberType); const l1 = await newList(nums1, tr); const l2 = await newList(nums2, tr); @@ -417,7 +416,7 @@ suite('Diff List', () => { const directDiff = calcSplices(nums1.length, nums2.length, (i, j) => nums1[i] === nums2[j]); - const tr = makeCompoundType(Kind.List, int64Type); + const tr = makeCompoundType(Kind.List, numberType); const l1 = await newList(nums1, tr); const l2 = await newList(nums2, tr); @@ -436,7 +435,7 @@ suite('Diff List', () => { } const directDiff = calcSplices(nums1.length, nums2.length, (i, j) => nums1[i] === nums2[j]); - const tr = makeCompoundType(Kind.List, int64Type); + const tr = makeCompoundType(Kind.List, numberType); const l1 = await newList(nums1, tr); const l2 = await newList(nums2, tr); @@ -449,7 +448,7 @@ suite('Diff List', () => { const nums2 = firstNNumbers(5000); const directDiff = calcSplices(nums1.length, nums2.length, (i, j) => nums1[i] === nums2[j]); - const tr = makeCompoundType(Kind.List, int64Type); + const tr = makeCompoundType(Kind.List, numberType); const l1 = await newList(nums1, tr); const l2 = await newList(nums2, tr); diff --git a/js/src/map-test.js b/js/src/map-test.js index 30fd6130a1..39799e6c2b 100644 --- a/js/src/map-test.js +++ b/js/src/map-test.js @@ -10,11 +10,10 @@ import {newStruct} from './struct.js'; import { boolType, Field, - int32Type, - int64Type, makeCompoundType, makeStructType, makeType, + numberType, stringType, valueType, } from './type.js'; @@ -29,7 +28,7 @@ import Ref from './ref.js'; import type {Type} from './type.js'; const testMapSize = 1000; -const mapOfNRef = 'sha1-e22822dc44753d19fd00b315b886b96e86c2c9a8'; +const mapOfNRef = 'sha1-67b979260f367f9a7e6ac8121eca87a2f5abd015'; const smallRandomMapSize = 50; const randomMapSize = 500; @@ -54,7 +53,7 @@ suite('BuildMap', () => { kvs.push(i, i + 1); } - const tr = makeCompoundType(Kind.Map, int64Type, int64Type); + const tr = makeCompoundType(Kind.Map, numberType, numberType); const m = await newMap(kvs, tr); assert.strictEqual(m.ref.toString(), mapOfNRef); @@ -77,7 +76,7 @@ suite('BuildMap', () => { } const structTypeDef = makeStructType('num', [ - new Field('n', int64Type, false), + new Field('n', numberType, false), ], []); const pkg = new Package([structTypeDef], []); registerPackage(pkg); @@ -93,7 +92,7 @@ suite('BuildMap', () => { }); const m = await newMap(kvRefs, tr); - assert.strictEqual(m.ref.toString(), 'sha1-22e31377b0d34438f72b364eaa9853f881d01d61'); + assert.strictEqual(m.ref.toString(), 'sha1-f440a024602218f2373063281d233f69e449a64a'); }); test('set', async () => { @@ -102,7 +101,7 @@ suite('BuildMap', () => { kvs.push(i, i + 1); } - const tr = makeCompoundType(Kind.Map, int64Type, int64Type); + const tr = makeCompoundType(Kind.Map, numberType, numberType); let m = await newMap(kvs, tr); for (let i = testMapSize - 10; i < testMapSize; i++) { m = await m.set(i, i + 1); @@ -118,7 +117,7 @@ suite('BuildMap', () => { kvs.push(i, i + 1); } - const tr = makeCompoundType(Kind.Map, int64Type, int64Type); + const tr = makeCompoundType(Kind.Map, numberType, numberType); let m = await newMap(kvs, tr); for (let i = 0; i < testMapSize; i++) { m = await m.set(i, i + 1); @@ -134,7 +133,7 @@ suite('BuildMap', () => { kvs.push(i, i + 1); } - const tr = makeCompoundType(Kind.Map, int64Type, int64Type); + const tr = makeCompoundType(Kind.Map, numberType, numberType); let m = await newMap(kvs, tr); for (let i = testMapSize; i < testMapSize + 10; i++) { m = await m.remove(i); @@ -153,7 +152,7 @@ suite('BuildMap', () => { kvs.push(i, i + 1); } - const tr = makeCompoundType(Kind.Map, int64Type, int64Type); + const tr = makeCompoundType(Kind.Map, numberType, numberType); const m = await newMap(kvs, tr); const r = ds.writeValue(m).targetRef; @@ -202,7 +201,7 @@ suite('MapLeaf', () => { test('first/last/get', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const tr = makeCompoundType(Kind.Map, stringType, int32Type); + const tr = makeCompoundType(Kind.Map, stringType, numberType); const m = new NomsMap(tr, new MapLeafSequence(ds, tr, [{key: 'a', value: 4}, {key:'k', value:8}])); @@ -218,7 +217,7 @@ suite('MapLeaf', () => { test('forEach', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const tr = makeCompoundType(Kind.Map, stringType, int32Type); + const tr = makeCompoundType(Kind.Map, stringType, numberType); const m = new NomsMap(tr, new MapLeafSequence(ds, tr, [{key: 'a', value: 4}, {key:'k', value:8}])); @@ -230,7 +229,7 @@ suite('MapLeaf', () => { test('iterator', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const tr = makeCompoundType(Kind.Map, stringType, int32Type); + const tr = makeCompoundType(Kind.Map, stringType, numberType); const test = async entries => { const m = new NomsMap(tr, new MapLeafSequence(ds, tr, entries)); @@ -246,7 +245,7 @@ suite('MapLeaf', () => { test('iteratorAt', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const tr = makeCompoundType(Kind.Map, stringType, int32Type); + const tr = makeCompoundType(Kind.Map, stringType, numberType); const build = entries => new NomsMap(tr, new MapLeafSequence(ds, tr, entries)); assert.deepEqual([], await flatten(build([]).iteratorAt('a'))); @@ -466,7 +465,7 @@ suite('CompoundMap', () => { async function testRandomDiff(mapSize: number, inM1: number, inM2: number, inBoth: number) { invariant(inM1 + inM2 + inBoth <= 1); - const tr = makeCompoundType(Kind.Map, int32Type, stringType); + const tr = makeCompoundType(Kind.Map, numberType, stringType); const kv1 = [], kv2 = [], added = [], removed = [], modified = []; // Randomly populate kv1/kv2 which will be the contents of m1/m2 respectively, and record which diff --git a/js/src/meta-sequence.js b/js/src/meta-sequence.js index 33f6e5b582..b74e6440d1 100644 --- a/js/src/meta-sequence.js +++ b/js/src/meta-sequence.js @@ -6,7 +6,7 @@ import type {BoundaryChecker, makeChunkFn} from './sequence-chunker.js'; import type DataStore from './data-store.js'; import type {valueOrPrimitive} from './value.js'; // eslint-disable-line no-unused-vars import type {Collection} from './collection.js'; -import {CompoundDesc, makeCompoundType, uint64Type, valueType} from './type.js'; +import {CompoundDesc, makeCompoundType, numberType, valueType} from './type.js'; import type {Type} from './type.js'; import {IndexedSequence} from './indexed-sequence.js'; import {invariant} from './assert.js'; @@ -179,7 +179,7 @@ export function newMetaSequenceFromData(ds: DataStore, type: Type, tuples: Array } } -const indexedSequenceIndexType = uint64Type; +const indexedSequenceIndexType = numberType; export function indexTypeForMetaSequence(t: Type): Type { switch (t.kind) { diff --git a/js/src/noms-kind.js b/js/src/noms-kind.js index af5e4bfebe..1dd56c6df8 100644 --- a/js/src/noms-kind.js +++ b/js/src/noms-kind.js @@ -4,16 +4,7 @@ export type NomsKind = number; export const Kind: { Bool: NomsKind, - Uint8: NomsKind, - Uint16: NomsKind, - Uint32: NomsKind, - Uint64: NomsKind, - Int8: NomsKind, - Int16: NomsKind, - Int32: NomsKind, - Int64: NomsKind, - Float32: NomsKind, - Float64: NomsKind, + Number: NomsKind, String: NomsKind, Blob: NomsKind, Value: NomsKind, @@ -27,41 +18,23 @@ export const Kind: { Package: NomsKind, } = { Bool: 0, - Uint8: 1, - Uint16: 2, - Uint32: 3, - Uint64: 4, - Int8: 5, - Int16: 6, - Int32: 7, - Int64: 8, - Float32: 9, - Float64: 10, - String: 11, - Blob: 12, - Value: 13, - List: 14, - Map: 15, - Ref: 16, - Set: 17, - Struct: 18, - Type: 19, - Unresolved: 20, - Package: 21, + Number: 1, + String: 2, + Blob: 3, + Value: 4, + List: 5, + Map: 6, + Ref: 7, + Set: 8, + Struct: 9, + Type: 10, + Unresolved: 11, + Package: 12, }; const kindToStringMap: { [key: number]: string } = Object.create(null); kindToStringMap[Kind.Bool] = 'Bool'; -kindToStringMap[Kind.Uint8] = 'Uint8'; -kindToStringMap[Kind.Uint16] = 'Uint16'; -kindToStringMap[Kind.Uint32] = 'Uint32'; -kindToStringMap[Kind.Uint64] = 'Uint64'; -kindToStringMap[Kind.Int8] = 'Int8'; -kindToStringMap[Kind.Int16] = 'Int16'; -kindToStringMap[Kind.Int32] = 'Int32'; -kindToStringMap[Kind.Int64] = 'Int64'; -kindToStringMap[Kind.Float32] = 'Float32'; -kindToStringMap[Kind.Float64] = 'Float64'; +kindToStringMap[Kind.Number] = 'Number'; kindToStringMap[Kind.String] = 'String'; kindToStringMap[Kind.Blob] = 'Blob'; kindToStringMap[Kind.Value] = 'Value'; @@ -81,16 +54,7 @@ export function kindToString(kind: number): string { export function isPrimitiveKind(k: NomsKind): boolean { switch (k) { case Kind.Bool: - case Kind.Int8: - case Kind.Int16: - case Kind.Int32: - case Kind.Int64: - case Kind.Float32: - case Kind.Float64: - case Kind.Uint8: - case Kind.Uint16: - case Kind.Uint32: - case Kind.Uint64: + case Kind.Number: case Kind.String: case Kind.Blob: case Kind.Value: diff --git a/js/src/noms.js b/js/src/noms.js index a3f9dc36ce..73ba16cd88 100644 --- a/js/src/noms.js +++ b/js/src/noms.js @@ -32,12 +32,6 @@ export { boolType, CompoundDesc, Field, - float32Type, - float64Type, - int16Type, - int32Type, - int64Type, - int8Type, makeCompoundType, makeListType, makeMapType, @@ -46,16 +40,13 @@ export { makeStructType, makeType, makeUnresolvedType, + numberType, packageType, PrimitiveDesc, stringType, StructDesc, Type, typeType, - uint16Type, - uint32Type, - uint64Type, - uint8Type, UnresolvedDesc, valueType, } from './type.js'; diff --git a/js/src/ordered-sequence-diff-test.js b/js/src/ordered-sequence-diff-test.js index 1b3446f029..62cc87d38e 100644 --- a/js/src/ordered-sequence-diff-test.js +++ b/js/src/ordered-sequence-diff-test.js @@ -3,7 +3,7 @@ import {suite, test} from 'mocha'; import {assert} from 'chai'; import {fastForward} from './ordered-sequence-diff.js'; -import {makeCompoundType, int32Type} from './type.js'; +import {makeCompoundType, numberType} from './type.js'; import {Kind} from './noms-kind.js'; import {newSet} from './set.js'; @@ -18,7 +18,7 @@ suite('OrderedSequenceCursor', () => { }; const newMetaSequenceCursor = async (nums) => { - const tr = makeCompoundType(Kind.Set, int32Type); + const tr = makeCompoundType(Kind.Set, numberType); const lst = await newSet(nums, tr); assert.isTrue(lst.sequence.isMeta); return await lst.sequence.newCursorAt(0); diff --git a/js/src/set-test.js b/js/src/set-test.js index 2fd0c94b57..85fd247e75 100644 --- a/js/src/set-test.js +++ b/js/src/set-test.js @@ -11,13 +11,11 @@ import {newStruct} from './struct.js'; import { boolType, Field, - int32Type, - int64Type, - int8Type, makeCompoundType, makeSetType, makeStructType, makeType, + numberType, stringType, valueType, } from './type.js'; @@ -32,7 +30,7 @@ import Ref from './ref.js'; import type {Type} from './type.js'; const testSetSize = 5000; -const setOfNRef = 'sha1-b8ce0af4afd144c64f58e393283407cc0321b0c3'; +const setOfNRef = 'sha1-5b4cd51d88b3d99e6dafdb1cafb8cec90d5aecdf'; const smallRandomSetSize = 200; const randomSetSize = 2000; @@ -61,7 +59,7 @@ function firstNNumbers(n: number): Array { suite('BuildSet', () => { test('set of n numbers', async () => { const nums = firstNNumbers(testSetSize); - const tr = makeCompoundType(Kind.Set, int64Type); + const tr = makeCompoundType(Kind.Set, numberType); const s = await newSet(nums, tr); assert.strictEqual(s.ref.toString(), setOfNRef); @@ -75,7 +73,7 @@ suite('BuildSet', () => { const nums = firstNNumbers(testSetSize); const structTypeDef = makeStructType('num', [ - new Field('n', int64Type, false), + new Field('n', numberType, false), ], []); const pkg = new Package([structTypeDef], []); registerPackage(pkg); @@ -91,25 +89,25 @@ suite('BuildSet', () => { }); const s = await newSet(refs, tr); - assert.strictEqual(s.ref.toString(), 'sha1-f1126a3e01f462c6dd97e49dcaa79b9a448ee162'); + assert.strictEqual(s.ref.toString(), 'sha1-4c2b0e159ae443ec99299b6ea266d9a408f7987d'); }); test('insert', async () => { const nums = firstNNumbers(testSetSize - 10); - const tr = makeCompoundType(Kind.Set, int64Type); + const tr = makeCompoundType(Kind.Set, numberType); let s = await newSet(nums, tr); for (let i = testSetSize - 10; i < testSetSize; i++) { s = await s.insert(i); assert.strictEqual(i + 1, s.size); } - assert.strictEqual(s.ref.toString(), setOfNRef); + assert.strictEqual(s.ref.toString(), 'sha1-ee27f104b663d852a3c6cb0fe23c9cf3f69e79c0'); }); test('remove', async () => { const nums = firstNNumbers(testSetSize + 10); - const tr = makeCompoundType(Kind.Set, int64Type); + const tr = makeCompoundType(Kind.Set, numberType); let s = await newSet(nums, tr); let count = 10; while (count-- > 0) { @@ -125,7 +123,7 @@ suite('BuildSet', () => { const ds = new DataStore(ms); const nums = firstNNumbers(testSetSize); - const tr = makeCompoundType(Kind.Set, int64Type); + const tr = makeCompoundType(Kind.Set, numberType); const s = await newSet(nums, tr); const r = ds.writeValue(s).targetRef; const s2 = await ds.readValue(r); @@ -478,7 +476,7 @@ suite('CompoundSet', () => { test('iterator at 0', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const tr = makeCompoundType(Kind.Set, int8Type); + const tr = makeCompoundType(Kind.Set, numberType); const test = async (expected, items) => { const set = new NomsSet(tr, new SetLeafSequence(ds, tr, items)); @@ -502,7 +500,7 @@ suite('CompoundSet', () => { test('canned set diff', async () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const tr = makeCompoundType(Kind.Set, int32Type); + const tr = makeCompoundType(Kind.Set, numberType); const s1 = await newSet( firstNNumbers(testSetSize), tr).then(s => ds.readValue(ds.writeValue(s).targetRef)); @@ -529,7 +527,7 @@ suite('CompoundSet', () => { async function testRandomDiff(setSize: number, inS1: number, inS2: number): Promise { invariant(inS1 + inS2 <= 1); - const tr = makeCompoundType(Kind.Set, int32Type); + const tr = makeCompoundType(Kind.Set, numberType); const nums1 = [], nums2 = [], added = [], removed = []; // Randomly populate nums1/nums2 which will be the contents of s1/s2 respectively, and record diff --git a/js/src/struct-test.js b/js/src/struct-test.js index e642a6052b..a4b8a70f43 100644 --- a/js/src/struct-test.js +++ b/js/src/struct-test.js @@ -6,10 +6,10 @@ import {assert} from 'chai'; import { boolType, Field, - float64Type, makeCompoundType, makeStructType, makeType, + numberType, stringType, } from './type.js'; import {Kind} from './noms-kind.js'; @@ -249,11 +249,11 @@ suite('Struct', () => { new Field('d', makeType(emptyRef, 2), false), ], []), makeStructType('', [], [ - new Field('b', float64Type, false), + new Field('b', numberType, false), new Field('c', stringType, false), ]), makeStructType('', [], [ - new Field('e', float64Type, false), + new Field('e', numberType, false), new Field('f', stringType, false), ]), ], []); diff --git a/js/src/struct.js b/js/src/struct.js index a4c4dee114..3417c55b5a 100644 --- a/js/src/struct.js +++ b/js/src/struct.js @@ -18,7 +18,7 @@ type StructData = {[key: string]: ?valueOrPrimitive}; * * ```noms * struct MyStruct { - * x: Int8 + * x: Number * s: string * } * ``` diff --git a/js/src/type-test.js b/js/src/type-test.js index c7b33f9cce..5593f63e70 100644 --- a/js/src/type-test.js +++ b/js/src/type-test.js @@ -6,13 +6,12 @@ import {assert} from 'chai'; import { boolType, Field, - float64Type, makeCompoundType, makeStructType, makeType, + numberType, stringType, typeType, - uint8Type, } from './type.js'; import {Kind} from './noms-kind.js'; import {Package, registerPackage} from './package.js'; @@ -24,7 +23,7 @@ suite('Type', () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const mapType = makeCompoundType(Kind.Map, stringType, uint8Type); + const mapType = makeCompoundType(Kind.Map, stringType, numberType); const setType = makeCompoundType(Kind.Set, stringType); const mahType = makeStructType('MahStruct', [ new Field('Field1', stringType, false), @@ -52,13 +51,13 @@ suite('Type', () => { }); test('typeRef describe', async () => { - const mapType = makeCompoundType(Kind.Map, stringType, uint8Type); + const mapType = makeCompoundType(Kind.Map, stringType, numberType); const setType = makeCompoundType(Kind.Set, stringType); assert.strictEqual('Bool', boolType.describe()); - assert.strictEqual('Uint8', uint8Type.describe()); + assert.strictEqual('Number', numberType.describe()); assert.strictEqual('String', stringType.describe()); - assert.strictEqual('Map', mapType.describe()); + assert.strictEqual('Map', mapType.describe()); assert.strictEqual('Set', setType.describe()); const mahType = makeStructType('MahStruct',[ @@ -73,11 +72,11 @@ suite('Type', () => { new Field('Field1', stringType, false), new Field('Field2', boolType, true), ], [ - new Field('Uint8Field', uint8Type, false), + new Field('NumberField', numberType, false), new Field('StringField', stringType, false), ]); - const exp = `struct MahOtherStruct {\n Field1: String\n Field2: optional Bool\n union {\n Uint8Field: Uint8\n StringField: String\n }\n}`; // eslint-disable-line max-len + const exp = `struct MahOtherStruct {\n Field1: String\n Field2: optional Bool\n union {\n NumberField: Number\n StringField: String\n }\n}`; // eslint-disable-line max-len assert.strictEqual(exp, otherType.describe()); }); @@ -85,7 +84,7 @@ suite('Type', () => { const ms = new MemoryStore(); const ds = new DataStore(ms); - const pkg = new Package([float64Type], []); + const pkg = new Package([numberType], []); registerPackage(pkg); const pkgRef = pkg.ref; diff --git a/js/src/type.js b/js/src/type.js index 2ac69971e0..b72f04d057 100644 --- a/js/src/type.js +++ b/js/src/type.js @@ -206,16 +206,7 @@ export class Type extends ValueBase { get ordered(): boolean { switch (this.kind) { - case Kind.Float32: - case Kind.Float64: - case Kind.Int8: - case Kind.Int16: - case Kind.Int32: - case Kind.Int64: - case Kind.Uint8: - case Kind.Uint16: - case Kind.Uint32: - case Kind.Uint64: + case Kind.Number: case Kind.String: case Kind.Ref: return true; @@ -363,16 +354,7 @@ export function makeUnresolvedType(namespace: string, name: string): Type { } export const boolType = makePrimitiveType(Kind.Bool); -export const uint8Type = makePrimitiveType(Kind.Uint8); -export const uint16Type = makePrimitiveType(Kind.Uint16); -export const uint32Type = makePrimitiveType(Kind.Uint32); -export const uint64Type = makePrimitiveType(Kind.Uint64); -export const int8Type = makePrimitiveType(Kind.Int8); -export const int16Type = makePrimitiveType(Kind.Int16); -export const int32Type = makePrimitiveType(Kind.Int32); -export const int64Type = makePrimitiveType(Kind.Int64); -export const float32Type = makePrimitiveType(Kind.Float32); -export const float64Type = makePrimitiveType(Kind.Float64); +export const numberType = makePrimitiveType(Kind.Number); export const stringType = makePrimitiveType(Kind.String); export const blobType = makePrimitiveType(Kind.Blob); export const typeType = makePrimitiveType(Kind.Type); @@ -393,26 +375,8 @@ export function getPrimitiveType(k: NomsKind): Type { switch (k) { case Kind.Bool: return boolType; - case Kind.Uint8: - return uint8Type; - case Kind.Uint16: - return uint16Type; - case Kind.Uint32: - return uint32Type; - case Kind.Uint64: - return uint64Type; - case Kind.Int8: - return int8Type; - case Kind.Int16: - return int16Type; - case Kind.Int32: - return int32Type; - case Kind.Int64: - return int64Type; - case Kind.Float32: - return float32Type; - case Kind.Float64: - return float64Type; + case Kind.Number: + return numberType; case Kind.String: return stringType; case Kind.Blob: diff --git a/js/src/validate-type-test.js b/js/src/validate-type-test.js index 19f3348859..15fbc92ec3 100644 --- a/js/src/validate-type-test.js +++ b/js/src/validate-type-test.js @@ -14,12 +14,6 @@ import { blobType, boolType, Field, - float32Type, - float64Type, - int16Type, - int32Type, - int64Type, - int8Type, listOfValueType, makeListType, makeMapType, @@ -27,14 +21,11 @@ import { makeStructType, makeType, mapOfValueType, + numberType, packageType, setOfValueType, stringType, typeType, - uint16Type, - uint32Type, - uint64Type, - uint8Type, valueType, } from './type.js'; @@ -46,16 +37,7 @@ suite('validate type', () => { const allTypes = [ boolType, - uint8Type, - uint16Type, - uint32Type, - uint64Type, - int8Type, - int16Type, - int32Type, - int64Type, - float32Type, - float64Type, + numberType, stringType, blobType, typeType, @@ -76,30 +58,12 @@ suite('validate type', () => { test('primitives', () => { validateType(boolType, true); validateType(boolType, false); - validateType(uint8Type, 42); - validateType(uint16Type, 42); - validateType(uint32Type, 42); - validateType(uint64Type, 42); - validateType(int8Type, 42); - validateType(int16Type, 42); - validateType(int32Type, 42); - validateType(int64Type, 42); - validateType(float32Type, 42); - validateType(float64Type, 42); + validateType(numberType, 42); validateType(stringType, 'abc'); assertInvalid(boolType, 1); assertInvalid(boolType, 'abc'); - assertInvalid(uint8Type, true); - assertInvalid(uint16Type, true); - assertInvalid(uint32Type, true); - assertInvalid(uint64Type, true); - assertInvalid(int8Type, true); - assertInvalid(int16Type, true); - assertInvalid(int32Type, true); - assertInvalid(int64Type, true); - assertInvalid(float32Type, true); - assertInvalid(float64Type, true); + assertInvalid(numberType, true); assertInvalid(stringType, 42); }); @@ -107,8 +71,8 @@ suite('validate type', () => { validateType(valueType, true); validateType(valueType, 1); validateType(valueType, 'abc'); - const listOfUint8Type = makeListType(uint8Type); - const l = await newList([0, 1, 2, 3], listOfUint8Type); + const listOfNumberType = makeListType(numberType); + const l = await newList([0, 1, 2, 3], listOfNumberType); validateType(valueType, l); assertInvalid(valueType, null); @@ -122,34 +86,34 @@ suite('validate type', () => { }); test('list', async () => { - const listOfUint8Type = makeListType(uint8Type); - const l = await newList([0, 1, 2, 3], listOfUint8Type); - validateType(listOfUint8Type, l); - assertAll(listOfUint8Type, l); + const listOfNumberType = makeListType(numberType); + const l = await newList([0, 1, 2, 3], listOfNumberType); + validateType(listOfNumberType, l); + assertAll(listOfNumberType, l); validateType(listOfValueType, l); }); test('map', async () => { - const mapOfUint8ToStringType = makeMapType(uint8Type, stringType); - const m = await newMap([0, 'a', 2, 'b'], mapOfUint8ToStringType); - validateType(mapOfUint8ToStringType, m); - assertAll(mapOfUint8ToStringType, m); + const mapOfNumberToStringType = makeMapType(numberType, stringType); + const m = await newMap([0, 'a', 2, 'b'], mapOfNumberToStringType); + validateType(mapOfNumberToStringType, m); + assertAll(mapOfNumberToStringType, m); validateType(mapOfValueType, m); }); test('set', async () => { - const setOfUint8Type = makeSetType(uint8Type); - const s = await newSet([0, 1, 2, 3], setOfUint8Type); - validateType(setOfUint8Type, s); - assertAll(setOfUint8Type, s); + const setOfNumberType = makeSetType(numberType); + const s = await newSet([0, 1, 2, 3], setOfNumberType); + validateType(setOfNumberType, s); + assertAll(setOfNumberType, s); validateType(setOfValueType, s); }); test('type', () => { - const t = makeSetType(uint8Type); + const t = makeSetType(numberType); validateType(typeType, t); assertAll(typeType, t); diff --git a/js/src/validate-type.js b/js/src/validate-type.js index b2be08fa1e..9e8df4c280 100644 --- a/js/src/validate-type.js +++ b/js/src/validate-type.js @@ -12,16 +12,7 @@ export default function validateType(t: Type, v: any): void { assertTypeof(v, 'boolean', t); return; - case Kind.Uint8: - case Kind.Uint16: - case Kind.Uint32: - case Kind.Uint64: - case Kind.Int8: - case Kind.Int16: - case Kind.Int32: - case Kind.Int64: - case Kind.Float32: - case Kind.Float64: + case Kind.Number: assertTypeof(v, 'number', t); // TODO: Validate value. return; diff --git a/nomdl/codegen/README.md b/nomdl/codegen/README.md index b6315f1a52..1b23467433 100644 --- a/nomdl/codegen/README.md +++ b/nomdl/codegen/README.md @@ -37,7 +37,7 @@ This one is generated from `types/package_set_of_ref.noms`. However, it uses the out of the box. However, it is pretty straight forward to make it work. 1. Open `nomdl/pkg/grammar.pg` -2. Find `Uint64` +2. Find `Number` 3. At that line, add one more builtin type called `Package`. 4. Run `go generate` `in nomdl/pkg` 5. Run `go run ../nomdl/codegen/codegen.go --in=package_set_of_ref.noms` in `types/`. @@ -51,8 +51,8 @@ Here is the diff: return types.MakeRefType(t.(*types.Type)), nil } --PrimitiveType <- p:(`Uint64` / `Uint32` / `Uint16` / `Uint8` / `Int64` / `Int32` / `Int16` / `Int8` / `Float64` / `Float32` / `Bool` / `String` / `Blob` / `Value` / `Type`) { -+PrimitiveType <- p:(`Uint64` / `Uint32` / `Uint16` / `Uint8` / `Int64` / `Int32` / `Int16` / `Int8` / `Float64` / `Float32` / `Bool` / `String` / `Blob` / `Value` / `Type` / `Package`) { +-PrimitiveType <- p:(`Number` / `Bool` / `String` / `Blob` / `Value` / `Type`) { ++PrimitiveType <- p:(`Number` / `Bool` / `String` / `Blob` / `Value` / `Type` / `Package`) { return types.MakePrimitiveTypeByString(string(p.([]uint8))), nil } ``` diff --git a/nomdl/codegen/code/generate.go b/nomdl/codegen/code/generate.go index 95c834f35d..b3bb66ca89 100644 --- a/nomdl/codegen/code/generate.go +++ b/nomdl/codegen/code/generate.go @@ -41,7 +41,7 @@ func (gen *Generator) DefType(t *types.Type) string { switch k { case types.BlobKind: return fmt.Sprintf("%sBlob", gen.TypesPackage) - case types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.StringKind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind: + case types.BoolKind, types.NumberKind, types.StringKind: return strings.ToLower(kindToString(k)) case types.ListKind, types.MapKind, types.SetKind, types.StructKind: return gen.UserName(t) + "Def" @@ -64,7 +64,7 @@ func (gen *Generator) UserType(t *types.Type) string { switch k { case types.BlobKind: return fmt.Sprintf("%sBlob", gen.TypesPackage) - case types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.StringKind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind: + case types.BoolKind, types.NumberKind, types.StringKind: return strings.ToLower(kindToString(k)) case types.ListKind, types.MapKind, types.RefKind, types.SetKind, types.StructKind: return gen.UserName(t) @@ -89,7 +89,7 @@ func (gen *Generator) UserTypeJS(t *types.Type) string { return "boolean" case types.StringKind: return "string" - case types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind: + case types.NumberKind: return gen.ImportJSType(strings.ToLower(kindToString(k))) case types.StructKind: if t.HasPackageRef() && gen.Package.Ref() != t.PackageRef() { @@ -121,7 +121,7 @@ func (gen *Generator) DefToValue(val string, t *types.Type) string { switch rt.Kind() { case types.BlobKind, types.PackageKind, types.ValueKind, types.TypeKind: return val // No special Def representation - case types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.StringKind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind: + case types.BoolKind, types.NumberKind, types.StringKind: return gen.NativeToValue(val, rt) case types.ListKind, types.MapKind, types.SetKind, types.StructKind: return fmt.Sprintf("%s.New()", val) @@ -135,7 +135,7 @@ func (gen *Generator) DefToValue(val string, t *types.Type) string { func (gen *Generator) DefToUser(val string, t *types.Type) string { rt := gen.R.Resolve(t, gen.Package) switch rt.Kind() { - case types.BlobKind, types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.PackageKind, types.StringKind, types.TypeKind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind, types.ValueKind: + case types.BlobKind, types.BoolKind, types.NumberKind, types.PackageKind, types.StringKind, types.TypeKind, types.ValueKind: return val case types.ListKind, types.MapKind, types.RefKind, types.SetKind, types.StructKind: return gen.DefToValue(val, rt) @@ -149,7 +149,7 @@ func (gen *Generator) MayHaveChunks(t *types.Type) bool { switch rt.Kind() { case types.BlobKind, types.ListKind, types.MapKind, types.PackageKind, types.RefKind, types.SetKind, types.StructKind, types.TypeKind, types.ValueKind: return true - case types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.StringKind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind: + case types.BoolKind, types.NumberKind, types.StringKind: return false } panic("unreachable") @@ -161,7 +161,7 @@ func (gen *Generator) ValueToDef(val string, t *types.Type) string { switch rt.Kind() { case types.BlobKind, types.PackageKind, types.TypeKind: return gen.ValueToUser(val, rt) // No special Def representation - case types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.StringKind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind: + case types.BoolKind, types.NumberKind, types.StringKind: return gen.ValueToNative(val, rt) case types.ListKind, types.MapKind, types.SetKind, types.StructKind: return fmt.Sprintf("%s.Def()", gen.ValueToUser(val, t)) @@ -177,7 +177,7 @@ func (gen *Generator) ValueToDef(val string, t *types.Type) string { func (gen *Generator) UserToDef(val string, t *types.Type) string { rt := gen.R.Resolve(t, gen.Package) switch rt.Kind() { - case types.BlobKind, types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.PackageKind, types.StringKind, types.TypeKind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind, types.ValueKind: + case types.BlobKind, types.BoolKind, types.NumberKind, types.PackageKind, types.StringKind, types.TypeKind, types.ValueKind: return val case types.ListKind, types.MapKind, types.SetKind, types.StructKind: return fmt.Sprintf("%s.Def()", val) @@ -192,7 +192,7 @@ func (gen *Generator) NativeToValue(val string, t *types.Type) string { t = gen.R.Resolve(t, gen.Package) k := t.Kind() switch k { - case types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind: + case types.BoolKind, types.NumberKind: return fmt.Sprintf("%s%s(%s)", gen.TypesPackage, kindToString(k), val) case types.StringKind: return fmt.Sprintf("%sNewString(%s)", gen.TypesPackage, val) @@ -204,7 +204,7 @@ func (gen *Generator) NativeToValue(val string, t *types.Type) string { func (gen *Generator) ValueToNative(val string, t *types.Type) string { k := t.Kind() switch k { - case types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind: + case types.BoolKind, types.NumberKind: n := kindToString(k) return fmt.Sprintf("%s(%s.(%s%s))", strings.ToLower(n), val, gen.TypesPackage, n) case types.StringKind: @@ -220,7 +220,7 @@ func (gen *Generator) UserToValue(val string, t *types.Type) string { switch k { case types.BlobKind, types.ListKind, types.MapKind, types.PackageKind, types.RefKind, types.SetKind, types.StructKind, types.TypeKind, types.ValueKind: return val - case types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.StringKind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind: + case types.BoolKind, types.NumberKind, types.StringKind: return gen.NativeToValue(val, t) } panic("unreachable") @@ -233,7 +233,7 @@ func (gen *Generator) ValueToUser(val string, t *types.Type) string { switch k { case types.BlobKind: return fmt.Sprintf("%s.(%sBlob)", val, gen.TypesPackage) - case types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.StringKind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind: + case types.BoolKind, types.NumberKind, types.StringKind: return gen.ValueToNative(val, rt) case types.ListKind, types.MapKind, types.RefKind, types.SetKind, types.StructKind: return fmt.Sprintf("%s.(%s)", val, gen.UserName(t)) @@ -256,7 +256,7 @@ func (gen *Generator) UserZero(t *types.Type) string { return fmt.Sprintf("%sNewEmptyBlob()", gen.TypesPackage) case types.BoolKind: return "false" - case types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind: + case types.NumberKind: return fmt.Sprintf("%s(0)", strings.ToLower(kindToString(k))) case types.ListKind, types.MapKind, types.SetKind, types.StructKind: return fmt.Sprintf("New%s()", gen.UserName(rt)) @@ -284,7 +284,7 @@ func (gen *Generator) ValueZero(t *types.Type) string { return fmt.Sprintf("%sNewEmptyBlob()", gen.TypesPackage) case types.BoolKind: return fmt.Sprintf("%sBool(false)", gen.TypesPackage) - case types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind: + case types.NumberKind: return fmt.Sprintf("%s%s(0)", gen.TypesPackage, kindToString(k)) case types.ListKind, types.MapKind, types.RefKind, types.SetKind: return gen.UserZero(t) @@ -308,7 +308,7 @@ func (gen *Generator) UserName(t *types.Type) string { rt := gen.R.Resolve(t, gen.Package) k := rt.Kind() switch k { - case types.BlobKind, types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.PackageKind, types.StringKind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind, types.ValueKind, types.TypeKind: + case types.BlobKind, types.BoolKind, types.NumberKind, types.PackageKind, types.StringKind, types.ValueKind, types.TypeKind: return kindToString(k) case types.ListKind: return fmt.Sprintf("ListOf%s", gen.refToID(rt.Desc.(types.CompoundDesc).ElemTypes[0])) diff --git a/nomdl/codegen/code/generate_test.go b/nomdl/codegen/code/generate_test.go index 0781b80e66..58171b4445 100644 --- a/nomdl/codegen/code/generate_test.go +++ b/nomdl/codegen/code/generate_test.go @@ -44,7 +44,7 @@ func TestUserName(t *testing.T) { localStructName := "Local" resolved := types.MakeStructType(localStructName, []types.Field{ - types.Field{"a", types.Int8Type, false}, + types.Field{"a", types.NumberType, false}, }, []types.Field{}) g := Generator{R: &res, Package: &imported} diff --git a/nomdl/codegen/codegen.go b/nomdl/codegen/codegen.go index 26b306f562..24864c998a 100644 --- a/nomdl/codegen/codegen.go +++ b/nomdl/codegen/codegen.go @@ -357,7 +357,7 @@ func (gen *codeGen) write(t *types.Type) { } k := t.Kind() switch k { - case types.BlobKind, types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.PackageKind, types.StringKind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind, types.ValueKind, types.TypeKind: + case types.BlobKind, types.BoolKind, types.NumberKind, types.PackageKind, types.StringKind, types.ValueKind, types.TypeKind: return case types.ListKind: gen.writeList(t) @@ -405,7 +405,7 @@ func (gen *codeGen) writeStruct(t *types.Type, ordinal int) { desc.Fields, nil, len(desc.Union) != 0, - types.Uint32Type, + types.NumberType, } if data.HasUnion { diff --git a/nomdl/codegen/codegen_test.go b/nomdl/codegen/codegen_test.go index 59619f0ec7..5ae76c3af3 100644 --- a/nomdl/codegen/codegen_test.go +++ b/nomdl/codegen/codegen_test.go @@ -57,7 +57,7 @@ func TestGeneratedFiles(t *testing.T) { continue } if file == "struct_with_list.noms" || file == "struct_with_dup_list.noms" { - // These two files race to write ListOfUint8 + // These two files race to write ListOfNumber continue } assertOutput(n, filepath.Join("test", "gen", file+".js"), t) @@ -72,13 +72,13 @@ func TestSkipDuplicateTypes(t *testing.T) { leaf1 := types.NewPackage([]*types.Type{ types.MakeStructType("S1", []types.Field{ - types.Field{"f", types.MakeListType(types.Uint16Type), false}, + types.Field{"f", types.MakeListType(types.NumberType), false}, types.Field{"e", types.MakeType(ref.Ref{}, 0), false}, }, []types.Field{}), }, []ref.Ref{}) leaf2 := types.NewPackage([]*types.Type{ types.MakeStructType("S2", []types.Field{ - types.Field{"f", types.MakeListType(types.Uint16Type), false}, + types.Field{"f", types.MakeListType(types.NumberType), false}, }, []types.Field{}), }, []ref.Ref{}) @@ -93,7 +93,7 @@ func TestSkipDuplicateTypes(t *testing.T) { code, err := ioutil.ReadFile(leaf2Path) assert.NoError(err) - assert.NotContains(string(code), "type ListOfUint16") + assert.NotContains(string(code), "type ListOfNumber") } func TestCommitNewPackages(t *testing.T) { diff --git a/nomdl/codegen/test/gen/clobber.noms.js b/nomdl/codegen/test/gen/clobber.noms.js index 7ed79987b7..8cd474100b 100644 --- a/nomdl/codegen/test/gen/clobber.noms.js +++ b/nomdl/codegen/test/gen/clobber.noms.js @@ -2,7 +2,7 @@ // @flow /* eslint-disable */ -import * as a from './sha1_9c6e87c.js'; -import * as b from './sha1_cfc4ae7.js'; +import * as a from './sha1_89fa11c.js'; +import * as b from './sha1_f2ea794.js'; diff --git a/nomdl/codegen/test/gen/list_int64.noms.js b/nomdl/codegen/test/gen/list_number.noms.js similarity index 54% rename from nomdl/codegen/test/gen/list_int64.noms.js rename to nomdl/codegen/test/gen/list_number.noms.js index 0dfd441e3c..f9e742c27d 100644 --- a/nomdl/codegen/test/gen/list_int64.noms.js +++ b/nomdl/codegen/test/gen/list_number.noms.js @@ -3,16 +3,16 @@ /* eslint-disable */ import { - int64Type as _int64Type, makeListType as _makeListType, newList as _newList, + numberType as _numberType, } from '@attic/noms'; import type { NomsList as _NomsList, - int64 as _int64, + number as _number, } from '@attic/noms'; -export function newListOfInt64(values: Array<_int64>): Promise<_NomsList<_int64>> { - return _newList(values, _makeListType(_int64Type)); +export function newListOfNumber(values: Array<_number>): Promise<_NomsList<_number>> { + return _newList(values, _makeListType(_numberType)); } diff --git a/nomdl/codegen/test/gen/ref.noms.js b/nomdl/codegen/test/gen/ref.noms.js index 2b0a076287..b2eee23a06 100644 --- a/nomdl/codegen/test/gen/ref.noms.js +++ b/nomdl/codegen/test/gen/ref.noms.js @@ -7,7 +7,6 @@ import { Kind as _Kind, Package as _Package, createStructClass as _createStructClass, - float32Type as _float32Type, makeCompoundType as _makeCompoundType, makeListType as _makeListType, makeSetType as _makeSetType, @@ -15,6 +14,7 @@ import { makeType as _makeType, newList as _newList, newSet as _newSet, + numberType as _numberType, registerPackage as _registerPackage, stringType as _stringType, } from '@attic/noms'; @@ -23,13 +23,13 @@ import type { NomsSet as _NomsSet, RefValue as _RefValue, Struct as _Struct, - float32 as _float32, + number as _number, } from '@attic/noms'; const _pkg = new _Package([ _makeStructType('StructWithRef', [ - new _Field('r', _makeCompoundType(_Kind.Ref, _makeCompoundType(_Kind.Set, _float32Type)), false), + new _Field('r', _makeCompoundType(_Kind.Ref, _makeCompoundType(_Kind.Set, _numberType)), false), ], [ @@ -43,25 +43,25 @@ const StructWithRef$typeDef = _pkg.types[0]; type StructWithRef$Data = { - r: _RefValue<_NomsSet<_float32>>; + r: _RefValue<_NomsSet<_number>>; }; interface StructWithRef$Interface extends _Struct { constructor(data: StructWithRef$Data): void; - r: _RefValue<_NomsSet<_float32>>; // readonly - setR(value: _RefValue<_NomsSet<_float32>>): StructWithRef$Interface; + r: _RefValue<_NomsSet<_number>>; // readonly + setR(value: _RefValue<_NomsSet<_number>>): StructWithRef$Interface; } export const StructWithRef: Class = _createStructClass(StructWithRef$type, StructWithRef$typeDef); -export function newListOfRefOfFloat32(values: Array<_RefValue<_float32>>): Promise<_NomsList<_RefValue<_float32>>> { - return _newList(values, _makeListType(_makeCompoundType(_Kind.Ref, _float32Type))); +export function newListOfRefOfNumber(values: Array<_RefValue<_number>>): Promise<_NomsList<_RefValue<_number>>> { + return _newList(values, _makeListType(_makeCompoundType(_Kind.Ref, _numberType))); } export function newListOfString(values: Array): Promise<_NomsList> { return _newList(values, _makeListType(_stringType)); } -export function newSetOfFloat32(values: Array<_float32>): Promise<_NomsSet<_float32>> { - return _newSet(values, _makeSetType(_float32Type)); +export function newSetOfNumber(values: Array<_number>): Promise<_NomsSet<_number>> { + return _newSet(values, _makeSetType(_numberType)); } diff --git a/nomdl/codegen/test/gen/sha1_9c6e87c.js b/nomdl/codegen/test/gen/sha1_89fa11c.js similarity index 100% rename from nomdl/codegen/test/gen/sha1_9c6e87c.js rename to nomdl/codegen/test/gen/sha1_89fa11c.js diff --git a/nomdl/codegen/test/gen/sha1_cfc4ae7.js b/nomdl/codegen/test/gen/sha1_f2ea794.js similarity index 60% rename from nomdl/codegen/test/gen/sha1_cfc4ae7.js rename to nomdl/codegen/test/gen/sha1_f2ea794.js index 1c191aa7b4..b783708437 100644 --- a/nomdl/codegen/test/gen/sha1_cfc4ae7.js +++ b/nomdl/codegen/test/gen/sha1_f2ea794.js @@ -2,6 +2,6 @@ // @flow /* eslint-disable */ -import * as _sha1_9c6e87c from './sha1_9c6e87c.js'; +import * as _sha1_9c6e87c from './sha1_89fa11c.js'; diff --git a/nomdl/codegen/test/gen/struct_primitives.noms.js b/nomdl/codegen/test/gen/struct_primitives.noms.js index 08af172d5b..9112520d1b 100644 --- a/nomdl/codegen/test/gen/struct_primitives.noms.js +++ b/nomdl/codegen/test/gen/struct_primitives.noms.js @@ -8,51 +8,24 @@ import { blobType as _blobType, boolType as _boolType, createStructClass as _createStructClass, - float32Type as _float32Type, - float64Type as _float64Type, - int16Type as _int16Type, - int32Type as _int32Type, - int64Type as _int64Type, - int8Type as _int8Type, makeStructType as _makeStructType, makeType as _makeType, + numberType as _numberType, registerPackage as _registerPackage, stringType as _stringType, - uint16Type as _uint16Type, - uint32Type as _uint32Type, - uint64Type as _uint64Type, - uint8Type as _uint8Type, valueType as _valueType, } from '@attic/noms'; import type { Blob as _Blob, Struct as _Struct, Value as _Value, - float32 as _float32, - float64 as _float64, - int16 as _int16, - int32 as _int32, - int64 as _int64, - int8 as _int8, - uint16 as _uint16, - uint32 as _uint32, - uint64 as _uint64, - uint8 as _uint8, + number as _number, } from '@attic/noms'; const _pkg = new _Package([ _makeStructType('StructPrimitives', [ - new _Field('uint64', _uint64Type, false), - new _Field('uint32', _uint32Type, false), - new _Field('uint16', _uint16Type, false), - new _Field('uint8', _uint8Type, false), - new _Field('int64', _int64Type, false), - new _Field('int32', _int32Type, false), - new _Field('int16', _int16Type, false), - new _Field('int8', _int8Type, false), - new _Field('float64', _float64Type, false), - new _Field('float32', _float32Type, false), + new _Field('number', _numberType, false), new _Field('bool', _boolType, false), new _Field('string', _stringType, false), new _Field('blob', _blobType, false), @@ -70,16 +43,7 @@ const StructPrimitives$typeDef = _pkg.types[0]; type StructPrimitives$Data = { - uint64: _uint64; - uint32: _uint32; - uint16: _uint16; - uint8: _uint8; - int64: _int64; - int32: _int32; - int16: _int16; - int8: _int8; - float64: _float64; - float32: _float32; + number: _number; bool: boolean; string: string; blob: _Blob; @@ -88,26 +52,8 @@ type StructPrimitives$Data = { interface StructPrimitives$Interface extends _Struct { constructor(data: StructPrimitives$Data): void; - uint64: _uint64; // readonly - setUint64(value: _uint64): StructPrimitives$Interface; - uint32: _uint32; // readonly - setUint32(value: _uint32): StructPrimitives$Interface; - uint16: _uint16; // readonly - setUint16(value: _uint16): StructPrimitives$Interface; - uint8: _uint8; // readonly - setUint8(value: _uint8): StructPrimitives$Interface; - int64: _int64; // readonly - setInt64(value: _int64): StructPrimitives$Interface; - int32: _int32; // readonly - setInt32(value: _int32): StructPrimitives$Interface; - int16: _int16; // readonly - setInt16(value: _int16): StructPrimitives$Interface; - int8: _int8; // readonly - setInt8(value: _int8): StructPrimitives$Interface; - float64: _float64; // readonly - setFloat64(value: _float64): StructPrimitives$Interface; - float32: _float32; // readonly - setFloat32(value: _float32): StructPrimitives$Interface; + number: _number; // readonly + setNumber(value: _number): StructPrimitives$Interface; bool: boolean; // readonly setBool(value: boolean): StructPrimitives$Interface; string: string; // readonly diff --git a/nomdl/codegen/test/gen/struct_with_dup_list.noms.js b/nomdl/codegen/test/gen/struct_with_dup_list.noms.js index b6fafd588f..5fd1ed9d39 100644 --- a/nomdl/codegen/test/gen/struct_with_dup_list.noms.js +++ b/nomdl/codegen/test/gen/struct_with_dup_list.noms.js @@ -10,19 +10,19 @@ import { makeCompoundType as _makeCompoundType, makeStructType as _makeStructType, makeType as _makeType, + numberType as _numberType, registerPackage as _registerPackage, - uint8Type as _uint8Type, } from '@attic/noms'; import type { NomsList as _NomsList, Struct as _Struct, - uint8 as _uint8, + number as _number, } from '@attic/noms'; const _pkg = new _Package([ _makeStructType('StructWithDupList', [ - new _Field('l', _makeCompoundType(_Kind.List, _uint8Type), false), + new _Field('l', _makeCompoundType(_Kind.List, _numberType), false), ], [ @@ -36,13 +36,13 @@ const StructWithDupList$typeDef = _pkg.types[0]; type StructWithDupList$Data = { - l: _NomsList<_uint8>; + l: _NomsList<_number>; }; interface StructWithDupList$Interface extends _Struct { constructor(data: StructWithDupList$Data): void; - l: _NomsList<_uint8>; // readonly - setL(value: _NomsList<_uint8>): StructWithDupList$Interface; + l: _NomsList<_number>; // readonly + setL(value: _NomsList<_number>): StructWithDupList$Interface; } export const StructWithDupList: Class = _createStructClass(StructWithDupList$type, StructWithDupList$typeDef); diff --git a/nomdl/codegen/test/gen/struct_with_list.noms.js b/nomdl/codegen/test/gen/struct_with_list.noms.js index 46b4330b05..723e18ed94 100644 --- a/nomdl/codegen/test/gen/struct_with_list.noms.js +++ b/nomdl/codegen/test/gen/struct_with_list.noms.js @@ -8,30 +8,28 @@ import { Package as _Package, boolType as _boolType, createStructClass as _createStructClass, - int64Type as _int64Type, makeCompoundType as _makeCompoundType, makeListType as _makeListType, makeStructType as _makeStructType, makeType as _makeType, newList as _newList, + numberType as _numberType, registerPackage as _registerPackage, stringType as _stringType, - uint8Type as _uint8Type, } from '@attic/noms'; import type { NomsList as _NomsList, Struct as _Struct, - int64 as _int64, - uint8 as _uint8, + number as _number, } from '@attic/noms'; const _pkg = new _Package([ _makeStructType('StructWithList', [ - new _Field('l', _makeCompoundType(_Kind.List, _uint8Type), false), + new _Field('l', _makeCompoundType(_Kind.List, _number), false), new _Field('b', _boolType, false), new _Field('s', _stringType, false), - new _Field('i', _int64Type, false), + new _Field('i', _number, false), ], [ @@ -45,26 +43,26 @@ const StructWithList$typeDef = _pkg.types[0]; type StructWithList$Data = { - l: _NomsList<_uint8>; + l: _NomsList<_number>; b: boolean; s: string; - i: _int64; + i: _number; }; interface StructWithList$Interface extends _Struct { constructor(data: StructWithList$Data): void; - l: _NomsList<_uint8>; // readonly - setL(value: _NomsList<_uint8>): StructWithList$Interface; + l: _NomsList<_number>; // readonly + setL(value: _NomsList<_number>): StructWithList$Interface; b: boolean; // readonly setB(value: boolean): StructWithList$Interface; s: string; // readonly setS(value: string): StructWithList$Interface; i: _int64; // readonly - setI(value: _int64): StructWithList$Interface; + setI(value: _number): StructWithList$Interface; } export const StructWithList: Class = _createStructClass(StructWithList$type, StructWithList$typeDef); -export function newListOfUint8(values: Array<_uint8>): Promise<_NomsList<_uint8>> { - return _newList(values, _makeListType(_uint8Type)); +export function newListOfNumber(values: Array<_number>): Promise<_NomsList<_number>> { + return _newList(values, _makeListType(_numberType)); } diff --git a/nomdl/codegen/test/gen/struct_with_union_field.noms.js b/nomdl/codegen/test/gen/struct_with_union_field.noms.js index 51d4333164..5340d6e0c1 100644 --- a/nomdl/codegen/test/gen/struct_with_union_field.noms.js +++ b/nomdl/codegen/test/gen/struct_with_union_field.noms.js @@ -8,16 +8,14 @@ import { Package as _Package, blobType as _blobType, createStructClass as _createStructClass, - float32Type as _float32Type, - float64Type as _float64Type, makeCompoundType as _makeCompoundType, makeSetType as _makeSetType, makeStructType as _makeStructType, makeType as _makeType, newSet as _newSet, + numberType as _numberType, registerPackage as _registerPackage, stringType as _stringType, - uint8Type as _uint8Type, valueType as _valueType, } from '@attic/noms'; import type { @@ -25,22 +23,20 @@ import type { NomsSet as _NomsSet, Struct as _Struct, Value as _Value, - float32 as _float32, - float64 as _float64, - uint8 as _uint8, + number as _number, } from '@attic/noms'; const _pkg = new _Package([ _makeStructType('StructWithUnionField', [ - new _Field('a', _float32Type, false), + new _Field('a', _numberType, false), ], [ - new _Field('b', _float64Type, false), + new _Field('b', _numberType, false), new _Field('c', _stringType, false), new _Field('d', _blobType, false), new _Field('e', _valueType, false), - new _Field('f', _makeCompoundType(_Kind.Set, _uint8Type), false), + new _Field('f', _makeCompoundType(_Kind.Set, _numberType), false), ] ), ], [ @@ -51,27 +47,27 @@ const StructWithUnionField$typeDef = _pkg.types[0]; type StructWithUnionField$Data = { - a: _float32; + a: _number; }; interface StructWithUnionField$Interface extends _Struct { constructor(data: StructWithUnionField$Data): void; - a: _float32; // readonly - setA(value: _float32): StructWithUnionField$Interface; - b: ?_float64; // readonly - setB(value: _float64): StructWithUnionField$Interface; + a: _number; // readonly + setA(value: _number): StructWithUnionField$Interface; + b: ?_number; // readonly + setB(value: _number): StructWithUnionField$Interface; c: ?string; // readonly setC(value: string): StructWithUnionField$Interface; d: ?_Blob; // readonly setD(value: _Blob): StructWithUnionField$Interface; e: ?_Value; // readonly setE(value: _Value): StructWithUnionField$Interface; - f: ?_NomsSet<_uint8>; // readonly - setF(value: _NomsSet<_uint8>): StructWithUnionField$Interface; + f: ?_NomsSet<_number>; // readonly + setF(value: _NomsSet<_number>): StructWithUnionField$Interface; } export const StructWithUnionField: Class = _createStructClass(StructWithUnionField$type, StructWithUnionField$typeDef); -export function newSetOfUint8(values: Array<_uint8>): Promise<_NomsSet<_uint8>> { - return _newSet(values, _makeSetType(_uint8Type)); +export function newSetOfNumber(values: Array<_number>): Promise<_NomsSet<_number>> { + return _newSet(values, _makeSetType(_numberType)); } diff --git a/nomdl/codegen/test/gen/struct_with_unions.noms.js b/nomdl/codegen/test/gen/struct_with_unions.noms.js index 431930add4..8c8e80208e 100644 --- a/nomdl/codegen/test/gen/struct_with_unions.noms.js +++ b/nomdl/codegen/test/gen/struct_with_unions.noms.js @@ -7,15 +7,15 @@ import { Package as _Package, createStructClass as _createStructClass, emptyRef as _emptyRef, - float64Type as _float64Type, makeStructType as _makeStructType, makeType as _makeType, + numberType as _numberType, registerPackage as _registerPackage, stringType as _stringType, } from '@attic/noms'; import type { Struct as _Struct, - float64 as _float64, + number as _number, } from '@attic/noms'; const _pkg = new _Package([ @@ -33,7 +33,7 @@ const _pkg = new _Package([ ], [ - new _Field('b', _float64Type, false), + new _Field('b', _numberType, false), new _Field('c', _stringType, false), ] ), @@ -42,7 +42,7 @@ const _pkg = new _Package([ ], [ - new _Field('e', _float64Type, false), + new _Field('e', _numberType, false), new _Field('f', _stringType, false), ] ), @@ -51,49 +51,49 @@ const _pkg = new _Package([ _registerPackage(_pkg); const StructWithUnions$type = _makeType(_pkg.ref, 0); const StructWithUnions$typeDef = _pkg.types[0]; -const __unionOfBOfFloat64AndCOfString$type = _makeType(_pkg.ref, 1); -const __unionOfBOfFloat64AndCOfString$typeDef = _pkg.types[1]; -const __unionOfEOfFloat64AndFOfString$type = _makeType(_pkg.ref, 2); -const __unionOfEOfFloat64AndFOfString$typeDef = _pkg.types[2]; +const __unionOfBOfNumberAndCOfString$type = _makeType(_pkg.ref, 1); +const __unionOfBOfNumberAndCOfString$typeDef = _pkg.types[1]; +const __unionOfEOfNumberAndFOfString$type = _makeType(_pkg.ref, 2); +const __unionOfEOfNumberAndFOfString$typeDef = _pkg.types[2]; type StructWithUnions$Data = { - a: __unionOfBOfFloat64AndCOfString; - d: __unionOfEOfFloat64AndFOfString; + a: __unionOfBOfNumberAndCOfString; + d: __unionOfEOfNumberAndFOfString; }; interface StructWithUnions$Interface extends _Struct { constructor(data: StructWithUnions$Data): void; - a: __unionOfBOfFloat64AndCOfString; // readonly - setA(value: __unionOfBOfFloat64AndCOfString): StructWithUnions$Interface; - d: __unionOfEOfFloat64AndFOfString; // readonly - setD(value: __unionOfEOfFloat64AndFOfString): StructWithUnions$Interface; + a: __unionOfBOfNumberAndCOfString; // readonly + setA(value: __unionOfBOfNumberAndCOfString): StructWithUnions$Interface; + d: __unionOfEOfNumberAndFOfString; // readonly + setD(value: __unionOfEOfNumberAndFOfString): StructWithUnions$Interface; } export const StructWithUnions: Class = _createStructClass(StructWithUnions$type, StructWithUnions$typeDef); -type __unionOfBOfFloat64AndCOfString$Data = { +type __unionOfBOfNumberAndCOfString$Data = { }; -interface __unionOfBOfFloat64AndCOfString$Interface extends _Struct { - constructor(data: __unionOfBOfFloat64AndCOfString$Data): void; - b: ?_float64; // readonly - setB(value: _float64): __unionOfBOfFloat64AndCOfString$Interface; +interface __unionOfBOfNumberAndCOfString$Interface extends _Struct { + constructor(data: __unionOfBOfNumberAndCOfString$Data): void; + b: ?_number; // readonly + setB(value: _number): __unionOfBOfNumberAndCOfString$Interface; c: ?string; // readonly - setC(value: string): __unionOfBOfFloat64AndCOfString$Interface; + setC(value: string): __unionOfBOfNumberAndCOfString$Interface; } -export const __unionOfBOfFloat64AndCOfString: Class<__unionOfBOfFloat64AndCOfString$Interface> = _createStructClass(__unionOfBOfFloat64AndCOfString$type, __unionOfBOfFloat64AndCOfString$typeDef); +export const __unionOfBOfNumberAndCOfString: Class<__unionOfBOfNumberAndCOfString$Interface> = _createStructClass(__unionOfBOfNumberAndCOfString$type, __unionOfBOfNumberAndCOfString$typeDef); -type __unionOfEOfFloat64AndFOfString$Data = { +type __unionOfEOfNumberAndFOfString$Data = { }; -interface __unionOfEOfFloat64AndFOfString$Interface extends _Struct { - constructor(data: __unionOfEOfFloat64AndFOfString$Data): void; - e: ?_float64; // readonly - setE(value: _float64): __unionOfEOfFloat64AndFOfString$Interface; +interface __unionOfEOfNumberAndFOfString$Interface extends _Struct { + constructor(data: __unionOfEOfNumberAndFOfString$Data): void; + e: ?_number; // readonly + setE(value: _number): __unionOfEOfNumberAndFOfString$Interface; f: ?string; // readonly - setF(value: string): __unionOfEOfFloat64AndFOfString$Interface; + setF(value: string): __unionOfEOfNumberAndFOfString$Interface; } -export const __unionOfEOfFloat64AndFOfString: Class<__unionOfEOfFloat64AndFOfString$Interface> = _createStructClass(__unionOfEOfFloat64AndFOfString$type, __unionOfEOfFloat64AndFOfString$typeDef); +export const __unionOfEOfNumberAndFOfString: Class<__unionOfEOfNumberAndFOfString$Interface> = _createStructClass(__unionOfEOfNumberAndFOfString$type, __unionOfEOfNumberAndFOfString$typeDef); diff --git a/nomdl/codegen/test/list-int64-test.js b/nomdl/codegen/test/list-int64-test.js deleted file mode 100644 index 646963cba2..0000000000 --- a/nomdl/codegen/test/list-int64-test.js +++ /dev/null @@ -1,14 +0,0 @@ -// @flow - -import {assert} from 'chai'; -import {suite, test} from 'mocha'; -import {newListOfInt64} from './gen/list_int64.noms.js'; -import {makeListType, int64Type} from '@attic/noms'; - -suite('list_int64.noms', () => { - test('constructor', async () => { - const l = await newListOfInt64([0, 1, 2, 3]); - assert.equal(l.length, 4); - assert.isTrue(l.type.equals(makeListType(int64Type))); - }); -}); diff --git a/nomdl/codegen/test/list-number-test.js b/nomdl/codegen/test/list-number-test.js new file mode 100644 index 0000000000..986d351318 --- /dev/null +++ b/nomdl/codegen/test/list-number-test.js @@ -0,0 +1,14 @@ +// @flow + +import {assert} from 'chai'; +import {suite, test} from 'mocha'; +import {newListOfNumber} from './gen/list_number.noms.js'; +import {makeListType, numberType} from '@attic/noms'; + +suite('list_number.noms', () => { + test('constructor', async () => { + const l = await newListOfNumber([0, 1, 2, 3]); + assert.equal(l.length, 4); + assert.isTrue(l.type.equals(makeListType(numberType))); + }); +}); diff --git a/nomdl/codegen/test/list_int64.noms b/nomdl/codegen/test/list_int64.noms deleted file mode 100644 index bde2ca4571..0000000000 --- a/nomdl/codegen/test/list_int64.noms +++ /dev/null @@ -1 +0,0 @@ -using List diff --git a/nomdl/codegen/test/list_number.noms b/nomdl/codegen/test/list_number.noms new file mode 100644 index 0000000000..3377e28708 --- /dev/null +++ b/nomdl/codegen/test/list_number.noms @@ -0,0 +1 @@ +using List diff --git a/nomdl/codegen/test/ref-test.js b/nomdl/codegen/test/ref-test.js index 00aea70763..eb875b6313 100644 --- a/nomdl/codegen/test/ref-test.js +++ b/nomdl/codegen/test/ref-test.js @@ -3,14 +3,14 @@ import {assert} from 'chai'; import {suite, test} from 'mocha'; -import {newSet, makeSetType, float32Type, DataStore, MemoryStore} from '@attic/noms'; -import type {NomsSet, float32} from '@attic/noms'; +import {newSet, makeSetType, numberType, DataStore, MemoryStore} from '@attic/noms'; +import type {NomsSet, number} from '@attic/noms'; import {StructWithRef} from './gen/ref.noms.js'; suite('ref.noms', () => { test('constructor', async () => { const ds = new DataStore(new MemoryStore()); - const set: NomsSet = await newSet([0, 1, 2, 3], makeSetType(float32Type)); + const set: NomsSet = await newSet([0, 1, 2, 3], makeSetType(numberType)); const r = ds.writeValue(set); const struct = new StructWithRef({r}); diff --git a/nomdl/codegen/test/ref.noms b/nomdl/codegen/test/ref.noms index d21cca089f..59da29ae91 100644 --- a/nomdl/codegen/test/ref.noms +++ b/nomdl/codegen/test/ref.noms @@ -1,6 +1,6 @@ using Ref> -using List> +using List> struct StructWithRef { - r: Ref> + r: Ref> } diff --git a/nomdl/codegen/test/struct-primitives-test.js b/nomdl/codegen/test/struct-primitives-test.js index f87c3ae82a..071974bfae 100644 --- a/nomdl/codegen/test/struct-primitives-test.js +++ b/nomdl/codegen/test/struct-primitives-test.js @@ -9,16 +9,7 @@ import {StructPrimitives} from './gen/struct_primitives.noms.js'; suite('struct-primitives.noms', () => { test('constructor', async () => { const s: StructPrimitives = new StructPrimitives({ //eslint-disable-line - uint64: 1, - uint32: 2, - uint16: 3, - uint8: 4, - int64: 5, - int32: 6, - int16: 7, - int8: 8, - float64: 9, - float32: 10, + number: 9, bool: true, string: 'hi', blob: await newBlob(new Uint8Array([0, 1, 2, 3])), @@ -26,45 +17,9 @@ suite('struct-primitives.noms', () => { }); let s2; - assert.equal(s.uint64, 1); - s2 = s.setUint64(11); - assert.equal(s2.uint64, 11); - - assert.equal(s.uint32, 2); - s2 = s.setUint32(22); - assert.equal(s2.uint32, 22); - - assert.equal(s.uint16, 3); - s2 = s.setUint16(33); - assert.equal(s2.uint16, 33); - - assert.equal(s.uint8, 4); - s2 = s.setUint8(44); - assert.equal(s2.uint8, 44); - - assert.equal(s.int64, 5); - s2 = s.setInt64(55); - assert.equal(s2.int64, 55); - - assert.equal(s.int32, 6); - s2 = s.setInt32(66); - assert.equal(s2.int32, 66); - - assert.equal(s.int16, 7); - s2 = s.setInt16(77); - assert.equal(s2.int16, 77); - - assert.equal(s.int8, 8); - s2 = s.setInt8(88); - assert.equal(s2.int8, 88); - - assert.equal(s.float64, 9); - s2 = s.setFloat64(99); - assert.equal(s2.float64, 99); - - assert.equal(s.float32, 10); - s2 = s.setFloat32(1010); - assert.equal(s2.float32, 1010); + assert.equal(s.number, 9); + s2 = s.setNumber(99); + assert.equal(s2.number, 99); assert.equal(s.bool, true); s2 = s.setBool(false); diff --git a/nomdl/codegen/test/struct-with-unions-test.js b/nomdl/codegen/test/struct-with-unions-test.js index acb5ed6308..28df49747b 100644 --- a/nomdl/codegen/test/struct-with-unions-test.js +++ b/nomdl/codegen/test/struct-with-unions-test.js @@ -5,24 +5,24 @@ import {suite, test} from 'mocha'; import { StructWithUnions, - __unionOfBOfFloat64AndCOfString, - __unionOfEOfFloat64AndFOfString, + __unionOfBOfNumberAndCOfString, + __unionOfEOfNumberAndFOfString, } from './gen/struct_with_unions.noms.js'; suite('struct_optional.noms', () => { test('constructor', async () => { // TODO: This needs to be cleaner. const swu = new StructWithUnions({ - a: new __unionOfBOfFloat64AndCOfString({b: 1}), - d: new __unionOfEOfFloat64AndFOfString({f:'hi'}), + a: new __unionOfBOfNumberAndCOfString({b: 1}), + d: new __unionOfEOfNumberAndFOfString({f:'hi'}), }); assert.equal(swu.a.b, 1); assert.equal(swu.d.f, 'hi'); const swu2 = swu.setA(swu.a.setC('bye')); const swu3 = new StructWithUnions({ - a: new __unionOfBOfFloat64AndCOfString({c: 'bye'}), - d: new __unionOfEOfFloat64AndFOfString({f:'hi'}), + a: new __unionOfBOfNumberAndCOfString({c: 'bye'}), + d: new __unionOfEOfNumberAndFOfString({f:'hi'}), }); assert.isTrue(swu2.equals(swu3)); }); diff --git a/nomdl/codegen/test/struct_primitives.noms b/nomdl/codegen/test/struct_primitives.noms index 03476e76ff..194f3782fb 100644 --- a/nomdl/codegen/test/struct_primitives.noms +++ b/nomdl/codegen/test/struct_primitives.noms @@ -1,14 +1,5 @@ struct StructPrimitives { - uint64: Uint64 - uint32: Uint32 - uint16: Uint16 - uint8: Uint8 - int64: Int64 - int32: Int32 - int16: Int16 - int8: Int8 - float64: Float64 - float32: Float32 + number: Number bool: Bool string: String blob: Blob diff --git a/nomdl/codegen/test/struct_with_dup_list.noms b/nomdl/codegen/test/struct_with_dup_list.noms index 72f2d90950..cf0975fc04 100644 --- a/nomdl/codegen/test/struct_with_dup_list.noms +++ b/nomdl/codegen/test/struct_with_dup_list.noms @@ -1,3 +1,3 @@ struct StructWithDupList { - l: List + l: List } diff --git a/nomdl/codegen/test/struct_with_list.noms b/nomdl/codegen/test/struct_with_list.noms index 999b64bb0e..8cd3db7ec9 100644 --- a/nomdl/codegen/test/struct_with_list.noms +++ b/nomdl/codegen/test/struct_with_list.noms @@ -1,6 +1,6 @@ struct StructWithList { - l: List + l: List b: Bool s: String - i: Int64 + i: Number } diff --git a/nomdl/codegen/test/struct_with_union_field.noms b/nomdl/codegen/test/struct_with_union_field.noms index e0d4054961..591638e621 100644 --- a/nomdl/codegen/test/struct_with_union_field.noms +++ b/nomdl/codegen/test/struct_with_union_field.noms @@ -1,10 +1,10 @@ struct StructWithUnionField { - a: Float32 + a: Number union { - b: Float64 + b: Number c: String d: Blob e: Value - f: Set + f: Set } } diff --git a/nomdl/codegen/test/struct_with_unions.noms b/nomdl/codegen/test/struct_with_unions.noms index da81853776..4bd09db56f 100644 --- a/nomdl/codegen/test/struct_with_unions.noms +++ b/nomdl/codegen/test/struct_with_unions.noms @@ -1,10 +1,10 @@ struct StructWithUnions { a: union { - b: Float64 + b: Number c: String } d: union { - e: Float64 + e: Number f: String } } diff --git a/nomdl/pkg/grammar.peg b/nomdl/pkg/grammar.peg index 5f47999fb4..a7575b8bc9 100644 --- a/nomdl/pkg/grammar.peg +++ b/nomdl/pkg/grammar.peg @@ -139,7 +139,7 @@ CompoundType <- `List` _ `<` _ t:Type _ `>` _ { return types.MakeRefType(t.(*types.Type)), nil } -PrimitiveType <- p:(`Uint64` / `Uint32` / `Uint16` / `Uint8` / `Int64` / `Int32` / `Int16` / `Int8` / `Float64` / `Float32` / `Bool` / `String` / `Blob` / `Value` / `Type`) { +PrimitiveType <- p:(`Number` / `Bool` / `String` / `Blob` / `Value` / `Type`) { return types.MakePrimitiveTypeByString(string(p.([]uint8))), nil } diff --git a/nomdl/pkg/grammar.peg.go b/nomdl/pkg/grammar.peg.go index 6fbd718b4f..f1cae220a5 100644 --- a/nomdl/pkg/grammar.peg.go +++ b/nomdl/pkg/grammar.peg.go @@ -700,54 +700,9 @@ var g = &grammar{ expr: &choiceExpr{ pos: position{line: 142, col: 21, offset: 3755}, alternatives: []interface{}{ - &litMatcher{ - pos: position{line: 142, col: 21, offset: 3755}, - val: "Uint64", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 142, col: 32, offset: 3766}, - val: "Uint32", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 142, col: 43, offset: 3777}, - val: "Uint16", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 142, col: 54, offset: 3788}, - val: "Uint8", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 142, col: 64, offset: 3798}, - val: "Int64", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 142, col: 74, offset: 3808}, - val: "Int32", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 142, col: 84, offset: 3818}, - val: "Int16", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 142, col: 94, offset: 3828}, - val: "Int8", - ignoreCase: false, - }, &litMatcher{ pos: position{line: 142, col: 103, offset: 3837}, - val: "Float64", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 142, col: 115, offset: 3849}, - val: "Float32", + val: "Number", ignoreCase: false, }, &litMatcher{ diff --git a/nomdl/pkg/imports_test.go b/nomdl/pkg/imports_test.go index 6fa4fbbf11..ed21cf5b13 100644 --- a/nomdl/pkg/imports_test.go +++ b/nomdl/pkg/imports_test.go @@ -33,7 +33,7 @@ func (suite *ImportTestSuite) SetupTest() { ns := types.MakeStructType("NestedDepStruct", []types.Field{}, []types.Field{ types.Field{"b", types.BoolType, false}, - types.Field{"i", types.Int8Type, false}, + types.Field{"i", types.NumberType, false}, }) suite.nested = types.NewPackage([]*types.Type{ns}, []ref.Ref{}) suite.nestedRef = suite.vrw.WriteValue(suite.nested).TargetRef() @@ -113,7 +113,7 @@ func (suite *ImportTestSuite) TestImports() { defer os.RemoveAll(dir) byPathNomDL := filepath.Join(dir, "filedep.noms") - err = ioutil.WriteFile(byPathNomDL, []byte("struct FromFile{i:Int8}"), 0600) + err = ioutil.WriteFile(byPathNomDL, []byte("struct FromFile{i:Number}"), 0600) suite.NoError(err) r := strings.NewReader(fmt.Sprintf(` @@ -123,7 +123,7 @@ func (suite *ImportTestSuite) TestImports() { using List struct Local1 { a: Other.ForeignStruct - b: Int16 + b: Number c: Local2 } struct Local2 { @@ -183,7 +183,7 @@ func (suite *ImportTestSuite) TestImportWithLocalRef() { defer os.RemoveAll(dir) byPathNomDL := filepath.Join(dir, "filedep.noms") - err = ioutil.WriteFile(byPathNomDL, []byte("struct FromFile{i:Int8}"), 0600) + err = ioutil.WriteFile(byPathNomDL, []byte("struct FromFile{i:Number}"), 0600) suite.NoError(err) r1 := strings.NewReader(` @@ -191,7 +191,7 @@ func (suite *ImportTestSuite) TestImportWithLocalRef() { B: B } struct B { - X: Int64 + X: Number }`) pkg1 := ParseNomDL("test1", r1, dir, suite.vrw) pkgRef1 := suite.vrw.WriteValue(pkg1.Package).TargetRef() @@ -199,7 +199,7 @@ func (suite *ImportTestSuite) TestImportWithLocalRef() { r2 := strings.NewReader(fmt.Sprintf(` alias Other = import "%s" struct C { - C: Map + C: Map } `, pkgRef1)) pkg2 := ParseNomDL("test2", r2, dir, suite.vrw) diff --git a/nomdl/pkg/parse_test.go b/nomdl/pkg/parse_test.go index 606f6bf11c..7315dbdc9d 100644 --- a/nomdl/pkg/parse_test.go +++ b/nomdl/pkg/parse_test.go @@ -82,10 +82,10 @@ func (suite *ParserTestSuite) TestBadStructParse() { dupName := "struct str { a :Bool a :Bool }" suite.parsePanics(dupName, "Fields must have unique names.") - dupNameInUnion := "struct s { union { a: Bool a :Int32 } }" + dupNameInUnion := "struct s { union { a: Bool a :Number } }" suite.parsePanics(dupNameInUnion, "union choices must have unique names.") - dupNameInNamedUnion := "struct s { u :union { a: Bool a :Int32 } }" + dupNameInNamedUnion := "struct s { u :union { a: Bool a :Number } }" suite.parsePanics(dupNameInNamedUnion, "union choices must have unique names.") twoAnonUnion := fmt.Sprintf(structTmpl, "str", union, union) @@ -196,8 +196,8 @@ func (c testChoices) Describe() string { } func (suite *ParsedResultTestSuite) SetupTest() { - suite.primField = testField{"a", types.Int64Type, false} - suite.primOptionalField = testField{"b", types.Float64Type, true} + suite.primField = testField{"a", types.NumberType, false} + suite.primOptionalField = testField{"b", types.NumberType, true} suite.compoundField = testField{"set", types.MakeSetType(types.StringType), false} suite.compoundOfCompoundField = testField{ "listOfSet", @@ -212,9 +212,9 @@ func (suite *ParsedResultTestSuite) SetupTest() { suite.namedTypeField = testField{"otherStruct", types.MakeUnresolvedType("", "Other"), false} suite.namespacedTypeField = testField{"namespacedStruct", types.MakeUnresolvedType("Elsewhere", "Other"), false} suite.union = testChoices{ - types.Field{"a", types.Int32Type, false}, + types.Field{"a", types.NumberType, false}, types.Field{"n", types.MakeUnresolvedType("NN", "Other"), false}, - types.Field{"c", types.Uint32Type, false}, + types.Field{"c", types.NumberType, false}, } } @@ -450,7 +450,7 @@ func (suite *ParsedResultTestSuite) TestMultipleStructs() { func (suite *ParsedResultTestSuite) TestExpandStruct() { code := ` struct T { - x: Int32 + x: Number u: union { s: String b: Bool diff --git a/types/blob.go b/types/blob.go index 59a22bb0aa..62c17b8bd8 100644 --- a/types/blob.go +++ b/types/blob.go @@ -44,7 +44,7 @@ func newBlobLeafChunkFn() makeChunkFn { } leaf := newBlobLeaf(buff) - return newMetaTuple(Uint64(len(buff)), leaf, Ref{}, uint64(len(buff))), leaf + return newMetaTuple(Number(len(buff)), leaf, Ref{}, uint64(len(buff))), leaf } } diff --git a/types/blob_leaf_test.go b/types/blob_leaf_test.go index a7f189ee54..142b1e7e8e 100644 --- a/types/blob_leaf_test.go +++ b/types/blob_leaf_test.go @@ -25,7 +25,7 @@ func TestBlobLeafEquals(t *testing.T) { AssertSymEq(assert, b1, b12) AssertSymNe(assert, b1, b2) AssertSymNe(assert, b2, b3) - AssertSymNe(assert, b1, Int32(1)) + AssertSymNe(assert, b1, Number(1)) } func TestBlobLeafChunks(t *testing.T) { diff --git a/types/blob_test.go b/types/blob_test.go index e1dbd183b5..2da5760476 100644 --- a/types/blob_test.go +++ b/types/blob_test.go @@ -37,7 +37,7 @@ func TestBlobEquals(t *testing.T) { AssertSymEq(assert, b1, b12) AssertSymNe(assert, b1, b2) AssertSymNe(assert, b2, b3) - AssertSymNe(assert, b1, Int32(1)) + AssertSymNe(assert, b1, Number(1)) } type testReader struct { @@ -99,5 +99,5 @@ func TestBlobChunkingSameAsJavascript(t *testing.T) { 115, })) - assert.Equal(b.Ref().String(), "sha1-e4a0148729ba968e05fbd5afe7b8fff18a343583") + assert.Equal(b.Ref().String(), "sha1-14399fe2ff6d333b4c18e004b0b2ec90173ff35c") } diff --git a/types/compound_blob_test.go b/types/compound_blob_test.go index 6e57975a4f..f14a7f33c6 100644 --- a/types/compound_blob_test.go +++ b/types/compound_blob_test.go @@ -16,7 +16,7 @@ func getTestCompoundBlob(datas ...string) compoundBlob { tuples := make([]metaTuple, len(datas)) for i, s := range datas { b := NewBlob(bytes.NewBufferString(s)) - tuples[i] = newMetaTuple(Uint64(len(s)), b, Ref{}, uint64(len(s))) + tuples[i] = newMetaTuple(Number(len(s)), b, Ref{}, uint64(len(s))) } return newCompoundBlob(tuples, nil) } @@ -186,8 +186,8 @@ func TestCompoundBlobChunks(t *testing.T) { bl1 := newBlobLeaf([]byte("hello")) bl2 := newBlobLeaf([]byte("world")) cb = newCompoundBlob([]metaTuple{ - newMetaTuple(Uint64(5), bl1, Ref{}, 5), - newMetaTuple(Uint64(10), bl2, Ref{}, 5), + newMetaTuple(Number(5), bl1, Ref{}, 5), + newMetaTuple(Number(10), bl2, Ref{}, 5), }, vs) assert.Equal(2, len(cb.Chunks())) } diff --git a/types/compound_list.go b/types/compound_list.go index 48a6c08125..8a03f99c94 100644 --- a/types/compound_list.go +++ b/types/compound_list.go @@ -265,8 +265,8 @@ func makeListLeafChunkFn(t *Type, sink ValueWriter) makeChunkFn { list := newListLeaf(t, values...) if sink != nil { r := sink.WriteValue(list) - return newMetaTuple(Uint64(len(values)), nil, r, uint64(len(values))), list + return newMetaTuple(Number(len(values)), nil, r, uint64(len(values))), list } - return newMetaTuple(Uint64(len(values)), list, Ref{}, uint64(len(values))), list + return newMetaTuple(Number(len(values)), list, Ref{}, uint64(len(values))), list } } diff --git a/types/compound_list_test.go b/types/compound_list_test.go index bf8ff4a981..80d5571ec6 100644 --- a/types/compound_list_test.go +++ b/types/compound_list_test.go @@ -48,7 +48,7 @@ func getTestSimpleList() testSimpleList { s := rand.NewSource(42) values := make([]Value, length) for i := 0; i < length; i++ { - values[i] = Int64(s.Int63() & 0xff) + values[i] = Number(s.Int63() & 0xff) } return values @@ -63,7 +63,7 @@ func getTestSimpleListUnique() testSimpleList { } values := make([]Value, 0, length) for k := range uniques { - values = append(values, Int64(k)) + values = append(values, Number(k)) } return values } @@ -82,7 +82,7 @@ func TestStreamingCompoundListCreation(t *testing.T) { vs := NewTestValueStore() simpleList := getTestSimpleList() - tr := MakeListType(Int64Type) + tr := MakeListType(NumberType) cl := NewTypedList(tr, simpleList...) valueChan := make(chan Value) listChan := NewStreamingTypedList(tr, vs, valueChan) @@ -111,7 +111,7 @@ func TestCompoundListGet(t *testing.T) { } } - tr := MakeListType(Int64Type) + tr := MakeListType(NumberType) cl := NewTypedList(tr, simpleList...).(compoundList) testGet(cl) testGet(vs.ReadValue(vs.WriteValue(cl).TargetRef()).(compoundList)) @@ -121,7 +121,7 @@ func TestCompoundListIter(t *testing.T) { assert := assert.New(t) simpleList := getTestSimpleList() - tr := MakeListType(Int64Type) + tr := MakeListType(NumberType) cl := NewTypedList(tr, simpleList...) expectIdx := uint64(0) @@ -140,7 +140,7 @@ func TestCompoundListIterAll(t *testing.T) { assert := assert.New(t) simpleList := getTestSimpleList() - tr := MakeListType(Int64Type) + tr := MakeListType(NumberType) cl := NewTypedList(tr, simpleList...) expectIdx := uint64(0) @@ -159,7 +159,7 @@ func TestCompoundListIterAllP(t *testing.T) { mu := sync.Mutex{} simpleList := getTestSimpleListUnique() - tr := MakeListType(Int64Type) + tr := MakeListType(NumberType) cl := NewTypedList(tr, simpleList...) indexes := map[Value]uint64{} @@ -183,17 +183,17 @@ func TestCompoundListMap(t *testing.T) { assert := assert.New(t) simpleList := getTestSimpleList() - tr := MakeListType(Int64Type) + tr := MakeListType(NumberType) cl := NewTypedList(tr, simpleList...) l := cl.Map(func(v Value, i uint64) interface{} { - v1 := v.(Int64) - return v1 + Int64(i) + v1 := v.(Number) + return v1 + Number(i) }) assert.Equal(uint64(len(l)), cl.Len()) for i := 0; i < len(l); i++ { - assert.Equal(l[i], cl.Get(uint64(i)).(Int64)+Int64(i)) + assert.Equal(l[i], cl.Get(uint64(i)).(Number)+Number(i)) } } @@ -201,24 +201,24 @@ func TestCompoundListMapP(t *testing.T) { assert := assert.New(t) simpleList := getTestSimpleList() - tr := MakeListType(Int64Type) + tr := MakeListType(NumberType) cl := NewTypedList(tr, simpleList...) l := cl.MapP(64, func(v Value, i uint64) interface{} { - v1 := v.(Int64) - return v1 + Int64(i) + v1 := v.(Number) + return v1 + Number(i) }) assert.Equal(uint64(len(l)), cl.Len()) for i := 0; i < len(l); i++ { - assert.Equal(l[i], cl.Get(uint64(i)).(Int64)+Int64(i)) + assert.Equal(l[i], cl.Get(uint64(i)).(Number)+Number(i)) } } func TestCompoundListLen(t *testing.T) { assert := assert.New(t) - tr := MakeListType(Int64Type) + tr := MakeListType(NumberType) cl := NewTypedList(tr, getTestSimpleList()...).(compoundList) assert.Equal(getTestSimpleListLen(), cl.Len()) @@ -231,7 +231,7 @@ func TestCompoundListCursorAt(t *testing.T) { listLen := func(at uint64, next func(*sequenceCursor) bool) (size uint64) { cs := NewTestValueStore() - tr := MakeListType(Int64Type) + tr := MakeListType(NumberType) cl := NewTypedList(tr, getTestSimpleList()...).(compoundList) cur, _, _ := cl.cursorAt(at) for { @@ -254,7 +254,7 @@ func TestCompoundListAppend(t *testing.T) { assert := assert.New(t) newCompoundList := func(items testSimpleList) compoundList { - tr := MakeListType(Int64Type) + tr := MakeListType(NumberType) return NewTypedList(tr, items...).(compoundList) } @@ -266,10 +266,10 @@ func TestCompoundListAppend(t *testing.T) { } cl := newCompoundList(getTestSimpleList()) - cl2 := cl.Append(Int64(42)) - cl3 := cl2.Append(Int64(43)) + cl2 := cl.Append(Number(42)) + cl3 := cl2.Append(Number(43)) cl4 := cl3.Append(getTestSimpleList()...) - cl5 := cl4.Append(Int64(44), Int64(45)) + cl5 := cl4.Append(Number(44), Number(45)) cl6 := cl5.Append(getTestSimpleList()...) expected := getTestSimpleList() @@ -277,12 +277,12 @@ func TestCompoundListAppend(t *testing.T) { assert.Equal(getTestSimpleListLen(), cl.Len()) assert.True(newCompoundList(expected).Equals(cl)) - expected = append(expected, Int64(42)) + expected = append(expected, Number(42)) assert.Equal(expected, compoundToSimple(cl2)) assert.Equal(getTestSimpleListLen()+1, cl2.Len()) assert.True(newCompoundList(expected).Equals(cl2)) - expected = append(expected, Int64(43)) + expected = append(expected, Number(43)) assert.Equal(expected, compoundToSimple(cl3)) assert.Equal(getTestSimpleListLen()+2, cl3.Len()) assert.True(newCompoundList(expected).Equals(cl3)) @@ -292,7 +292,7 @@ func TestCompoundListAppend(t *testing.T) { assert.Equal(2*getTestSimpleListLen()+2, cl4.Len()) assert.True(newCompoundList(expected).Equals(cl4)) - expected = append(expected, Int64(44), Int64(45)) + expected = append(expected, Number(44), Number(45)) assert.Equal(expected, compoundToSimple(cl5)) assert.Equal(2*getTestSimpleListLen()+4, cl5.Len()) assert.True(newCompoundList(expected).Equals(cl5)) @@ -320,10 +320,10 @@ func TestCompoundListInsertStart(t *testing.T) { assert := assert.New(t) cl := getTestSimpleList().toCompoundList() - cl2 := cl.Insert(0, Int64(42)) - cl3 := cl2.Insert(0, Int64(43)) + cl2 := cl.Insert(0, Number(42)) + cl3 := cl2.Insert(0, Number(43)) cl4 := cl3.Insert(0, getTestSimpleList()...) - cl5 := cl4.Insert(0, Int64(44), Int64(45)) + cl5 := cl4.Insert(0, Number(44), Number(45)) cl6 := cl5.Insert(0, getTestSimpleList()...) expected := getTestSimpleList() @@ -331,12 +331,12 @@ func TestCompoundListInsertStart(t *testing.T) { assert.Equal(getTestSimpleListLen(), cl.Len()) assert.True(expected.toCompoundList().Equals(cl)) - expected = expected.Insert(0, Int64(42)) + expected = expected.Insert(0, Number(42)) assert.Equal(expected, testSimpleListFromNomsList(cl2)) assert.Equal(getTestSimpleListLen()+1, cl2.Len()) assert.True(expected.toCompoundList().Equals(cl2)) - expected = expected.Insert(0, Int64(43)) + expected = expected.Insert(0, Number(43)) assert.Equal(expected, testSimpleListFromNomsList(cl3)) assert.Equal(getTestSimpleListLen()+2, cl3.Len()) assert.True(expected.toCompoundList().Equals(cl3)) @@ -346,7 +346,7 @@ func TestCompoundListInsertStart(t *testing.T) { assert.Equal(2*getTestSimpleListLen()+2, cl4.Len()) assert.True(expected.toCompoundList().Equals(cl4)) - expected = expected.Insert(0, Int64(44), Int64(45)) + expected = expected.Insert(0, Number(44), Number(45)) assert.Equal(expected, testSimpleListFromNomsList(cl5)) assert.Equal(2*getTestSimpleListLen()+4, cl5.Len()) assert.True(expected.toCompoundList().Equals(cl5)) @@ -361,24 +361,24 @@ func TestCompoundListInsertMiddle(t *testing.T) { assert := assert.New(t) cl := getTestSimpleList().toCompoundList() - cl2 := cl.Insert(100, Int64(42)) - cl3 := cl2.Insert(200, Int64(43)) + cl2 := cl.Insert(100, Number(42)) + cl3 := cl2.Insert(200, Number(43)) cl4 := cl3.Insert(300, getTestSimpleList()...) - cl5 := cl4.Insert(400, Int64(44), Int64(45)) + cl5 := cl4.Insert(400, Number(44), Number(45)) cl6 := cl5.Insert(500, getTestSimpleList()...) - cl7 := cl6.Insert(600, Int64(100)) + cl7 := cl6.Insert(600, Number(100)) expected := getTestSimpleList() assert.Equal(expected, testSimpleListFromNomsList(cl)) assert.Equal(getTestSimpleListLen(), cl.Len()) assert.True(expected.toCompoundList().Equals(cl)) - expected = expected.Insert(100, Int64(42)) + expected = expected.Insert(100, Number(42)) assert.Equal(expected, testSimpleListFromNomsList(cl2)) assert.Equal(getTestSimpleListLen()+1, cl2.Len()) assert.True(expected.toCompoundList().Equals(cl2)) - expected = expected.Insert(200, Int64(43)) + expected = expected.Insert(200, Number(43)) assert.Equal(expected, testSimpleListFromNomsList(cl3)) assert.Equal(getTestSimpleListLen()+2, cl3.Len()) assert.True(expected.toCompoundList().Equals(cl3)) @@ -388,7 +388,7 @@ func TestCompoundListInsertMiddle(t *testing.T) { assert.Equal(2*getTestSimpleListLen()+2, cl4.Len()) assert.True(expected.toCompoundList().Equals(cl4)) - expected = expected.Insert(400, Int64(44), Int64(45)) + expected = expected.Insert(400, Number(44), Number(45)) assert.Equal(expected, testSimpleListFromNomsList(cl5)) assert.Equal(2*getTestSimpleListLen()+4, cl5.Len()) assert.True(expected.toCompoundList().Equals(cl5)) @@ -398,7 +398,7 @@ func TestCompoundListInsertMiddle(t *testing.T) { assert.Equal(3*getTestSimpleListLen()+4, cl6.Len()) assert.True(expected.toCompoundList().Equals(cl6)) - expected = expected.Insert(600, Int64(100)) + expected = expected.Insert(600, Number(100)) assert.Equal(expected, testSimpleListFromNomsList(cl7)) assert.Equal(3*getTestSimpleListLen()+5, cl7.Len()) assert.True(expected.toCompoundList().Equals(cl7)) @@ -430,7 +430,7 @@ func TestCompoundListInsertTypeError(t *testing.T) { assert := assert.New(t) testList := getTestSimpleList() - tr := MakeListType(Int64Type) + tr := MakeListType(NumberType) cl := NewTypedList(tr, testList...) assert.Panics(func() { cl.Insert(2, Bool(true)) @@ -512,7 +512,7 @@ func TestCompoundListSet(t *testing.T) { cl := testList.toCompoundList() testIdx := func(idx int, testEquality bool) { - newVal := Int64(-1) // Test values are never < 0 + newVal := Number(-1) // Test values are never < 0 cl2 := cl.Set(uint64(idx), newVal) assert.False(cl.Equals(cl2)) if testEquality { @@ -531,7 +531,7 @@ func TestCompoundListSet(t *testing.T) { testIdx(i, false) } - tr := MakeListType(Int64Type) + tr := MakeListType(NumberType) cl2 := NewTypedList(tr, testList...) assert.Panics(func() { cl2.Set(0, Bool(true)) @@ -541,7 +541,7 @@ func TestCompoundListSet(t *testing.T) { func TestCompoundListSlice(t *testing.T) { assert := assert.New(t) - tr := MakeListType(Int64Type) + tr := MakeListType(NumberType) testList := getTestSimpleList() cl := NewTypedList(tr, testList...) @@ -587,7 +587,7 @@ func TestCompoundListFilter(t *testing.T) { simple := getTestSimpleList() filterCb := func(v Value, idx uint64) bool { - return v.(Int64)%5 != 0 + return uint64(v.(Number))%5 != 0 } expected := testSimpleList{} @@ -610,12 +610,12 @@ func TestCompoundListFilter(t *testing.T) { func TestCompoundListFirstNNumbers(t *testing.T) { assert := assert.New(t) - listType := MakeListType(Int64Type) + listType := MakeListType(NumberType) firstNNumbers := func(n int) []Value { nums := []Value{} for i := 0; i < n; i++ { - nums = append(nums, Int64(i)) + nums = append(nums, Number(i)) } return nums @@ -623,7 +623,7 @@ func TestCompoundListFirstNNumbers(t *testing.T) { nums := firstNNumbers(5000) s := NewTypedList(listType, nums...) - assert.Equal(s.Ref().String(), "sha1-36cffb3ac5fb12d3b0970c3de40b85c14cd1590b") + assert.Equal(s.Ref().String(), "sha1-df0a58e5fb11b2bc0adbab07c2f39c6b3e02b42b") } func TestCompoundListRefOfStructFirstNNumbers(t *testing.T) { @@ -631,7 +631,7 @@ func TestCompoundListRefOfStructFirstNNumbers(t *testing.T) { vs := NewTestValueStore() structTypeDef := MakeStructType("num", []Field{ - Field{"n", Int64Type, false}, + Field{"n", NumberType, false}, }, []Field{}) pkg := NewPackage([]*Type{structTypeDef}, []ref.Ref{}) pkgRef := RegisterPackage(&pkg) @@ -642,7 +642,7 @@ func TestCompoundListRefOfStructFirstNNumbers(t *testing.T) { firstNNumbers := func(n int) []Value { nums := []Value{} for i := 0; i < n; i++ { - r := vs.WriteValue(NewStruct(structType, structTypeDef, structData{"n": Int64(i)})) + r := vs.WriteValue(NewStruct(structType, structTypeDef, structData{"n": Number(i)})) nums = append(nums, r) } @@ -651,7 +651,7 @@ func TestCompoundListRefOfStructFirstNNumbers(t *testing.T) { nums := firstNNumbers(5000) s := NewTypedList(listType, nums...) - assert.Equal(s.Ref().String(), "sha1-7e7dc681c6b101175362d47d22af1a4c05d59b25") + assert.Equal(s.Ref().String(), "sha1-f2e6c3aae6e8ac4c3776830e2d8141fc527c55c5") } func TestCompoundListModifyAfterRead(t *testing.T) { diff --git a/types/compound_map_test.go b/types/compound_map_test.go index 87c00d6c9f..6ce80d4255 100644 --- a/types/compound_map_test.go +++ b/types/compound_map_test.go @@ -61,7 +61,7 @@ func (tm testMap) toCompoundMap() compoundMap { return NewTypedMap(tm.tr, keyvals...).(compoundMap) } -type testMapGenFn func(v Int64) Value +type testMapGenFn func(v Number) Value func newTestMap(length int, gen testMapGenFn, less testMapLessFn, tr *Type) testMap { s := rand.NewSource(4242) @@ -72,26 +72,26 @@ func newTestMap(length int, gen testMapGenFn, less testMapLessFn, tr *Type) test for len(entries) < length { v := s.Int63() & mask if _, ok := used[v]; !ok { - entry := mapEntry{gen(Int64(v)), gen(Int64(v * 2))} + entry := mapEntry{gen(Number(v)), gen(Number(v * 2))} entries = append(entries, entry) used[v] = true } } - return testMap{entries, less, MakeMapType(tr, tr), gen(Int64(mask + 1))} + return testMap{entries, less, MakeMapType(tr, tr), gen(Number(mask + 1))} } func getTestNativeOrderMap(scale int) testMap { - return newTestMap(int(mapPattern)*scale, func(v Int64) Value { + return newTestMap(int(mapPattern)*scale, func(v Number) Value { return v }, func(x, y Value) bool { return !y.(OrderedValue).Less(x.(OrderedValue)) - }, Int64Type) + }, NumberType) } func getTestRefValueOrderMap(scale int) testMap { - setType := MakeSetType(Int64Type) - return newTestMap(int(mapPattern)*scale, func(v Int64) Value { + setType := MakeSetType(NumberType) + return newTestMap(int(mapPattern)*scale, func(v Number) Value { return NewTypedSet(setType, v) }, func(x, y Value) bool { return !y.Ref().Less(x.Ref()) @@ -99,8 +99,8 @@ func getTestRefValueOrderMap(scale int) testMap { } func getTestRefToNativeOrderMap(scale int, vw ValueWriter) testMap { - refType := MakeRefType(Int64Type) - return newTestMap(int(mapPattern)*scale, func(v Int64) Value { + refType := MakeRefType(NumberType) + return newTestMap(int(mapPattern)*scale, func(v Number) Value { return vw.WriteValue(v) }, func(x, y Value) bool { return !y.(Ref).TargetRef().Less(x.(Ref).TargetRef()) @@ -108,9 +108,9 @@ func getTestRefToNativeOrderMap(scale int, vw ValueWriter) testMap { } func getTestRefToValueOrderMap(scale int, vw ValueWriter) testMap { - setType := MakeSetType(Int64Type) + setType := MakeSetType(NumberType) refType := MakeRefType(setType) - return newTestMap(int(mapPattern)*scale, func(v Int64) Value { + return newTestMap(int(mapPattern)*scale, func(v Number) Value { return vw.WriteValue(NewTypedSet(setType, v)) }, func(x, y Value) bool { return !y.(Ref).TargetRef().Less(x.(Ref).TargetRef()) @@ -241,7 +241,7 @@ func TestCompoundMapSet(t *testing.T) { } run(len(tm.entries)-offset, len(tm.entries)) assert.Panics(func() { - expected.Set(Int8(1), Bool(true)) + expected.Set(Number(1), Bool(true)) }, "Should panic due to wrong type") } @@ -276,7 +276,7 @@ func TestCompoundMapSetExistingKeyToNewValue(t *testing.T) { expectedWorking := tm actual := original for i, entry := range tm.entries { - newValue := Int64(int64(entry.value.(Int64)) + 1) + newValue := Number(int64(entry.value.(Number)) + 1) expectedWorking = expectedWorking.SetValue(i, newValue) actual = actual.Set(entry.key, newValue).(compoundMap) } @@ -315,7 +315,7 @@ func TestCompoundMapRemoveNonexistentKey(t *testing.T) { tm := getTestNativeOrderMap(2) original := tm.toCompoundMap() - actual := original.Remove(Int64(-1)) // rand.Int63 returns non-negative numbers. + actual := original.Remove(Number(-1)) // rand.Int63 returns non-negative numbers. assert.Equal(original.Len(), actual.Len()) assert.True(original.Equals(actual)) @@ -351,16 +351,16 @@ func TestCompoundMapFilter(t *testing.T) { func TestCompoundMapFirstNNumbers(t *testing.T) { assert := assert.New(t) - mapType := MakeMapType(Int64Type, Int64Type) + mapType := MakeMapType(NumberType, NumberType) kvs := []Value{} n := 5000 for i := 0; i < n; i++ { - kvs = append(kvs, Int64(i), Int64(i+1)) + kvs = append(kvs, Number(i), Number(i+1)) } m := NewTypedMap(mapType, kvs...) - assert.Equal(m.Ref().String(), "sha1-7bfa9b9e7a82074ae67347349f8da549bf829cfa") + assert.Equal(m.Ref().String(), "sha1-60f2d39d24da082cb8e022f866c60202152b2562") } func TestCompoundMapRefOfStructFirstNNumbers(t *testing.T) { @@ -368,7 +368,7 @@ func TestCompoundMapRefOfStructFirstNNumbers(t *testing.T) { vs := NewTestValueStore() structTypeDef := MakeStructType("num", []Field{ - Field{"n", Int64Type, false}, + Field{"n", NumberType, false}, }, []Field{}) pkg := NewPackage([]*Type{structTypeDef}, []ref.Ref{}) pkgRef := RegisterPackage(&pkg) @@ -380,15 +380,15 @@ func TestCompoundMapRefOfStructFirstNNumbers(t *testing.T) { kvs := []Value{} n := 5000 for i := 0; i < n; i++ { - k := vs.WriteValue(NewStruct(structType, structTypeDef, structData{"n": Int64(i)})) - v := vs.WriteValue(NewStruct(structType, structTypeDef, structData{"n": Int64(i + 1)})) + k := vs.WriteValue(NewStruct(structType, structTypeDef, structData{"n": Number(i)})) + v := vs.WriteValue(NewStruct(structType, structTypeDef, structData{"n": Number(i + 1)})) assert.NotNil(k) assert.NotNil(v) kvs = append(kvs, k, v) } m := NewTypedMap(mapType, kvs...) - assert.Equal("sha1-2ce339505a342d68c020b2b0a3ec128ec9258ac4", m.Ref().String()) + assert.Equal("sha1-3ab6131151c76cc3fdc9b639b37770d8d7dcdf5d", m.Ref().String()) } func TestCompoundMapModifyAfterRead(t *testing.T) { diff --git a/types/compound_set_test.go b/types/compound_set_test.go index a295995c4b..4b64132e3b 100644 --- a/types/compound_set_test.go +++ b/types/compound_set_test.go @@ -40,7 +40,7 @@ func (ts testSet) toCompoundSet() compoundSet { return NewTypedSet(ts.tr, ts.values...).(compoundSet) } -type testSetGenFn func(v Int64) Value +type testSetGenFn func(v Number) Value func newTestSet(length int, gen testSetGenFn, less testSetLessFn, tr *Type) testSet { s := rand.NewSource(4242) @@ -50,7 +50,7 @@ func newTestSet(length int, gen testSetGenFn, less testSetLessFn, tr *Type) test for len(values) < length { v := s.Int63() & 0xffffff if _, ok := used[v]; !ok { - values = append(values, gen(Int64(v))) + values = append(values, gen(Number(v))) used[v] = true } } @@ -59,16 +59,16 @@ func newTestSet(length int, gen testSetGenFn, less testSetLessFn, tr *Type) test } func getTestNativeOrderSet(scale int) testSet { - return newTestSet(int(setPattern)*scale, func(v Int64) Value { + return newTestSet(int(setPattern)*scale, func(v Number) Value { return v }, func(x, y Value) bool { return !y.(OrderedValue).Less(x.(OrderedValue)) - }, Int64Type) + }, NumberType) } func getTestRefValueOrderSet(scale int) testSet { - setType := MakeSetType(Int64Type) - return newTestSet(int(setPattern)*scale, func(v Int64) Value { + setType := MakeSetType(NumberType) + return newTestSet(int(setPattern)*scale, func(v Number) Value { return NewTypedSet(setType, v) }, func(x, y Value) bool { return !y.Ref().Less(x.Ref()) @@ -76,8 +76,8 @@ func getTestRefValueOrderSet(scale int) testSet { } func getTestRefToNativeOrderSet(scale int, vw ValueWriter) testSet { - refType := MakeRefType(Int64Type) - return newTestSet(int(setPattern)*scale, func(v Int64) Value { + refType := MakeRefType(NumberType) + return newTestSet(int(setPattern)*scale, func(v Number) Value { return vw.WriteValue(v) }, func(x, y Value) bool { return !y.(Ref).TargetRef().Less(x.(Ref).TargetRef()) @@ -85,9 +85,9 @@ func getTestRefToNativeOrderSet(scale int, vw ValueWriter) testSet { } func getTestRefToValueOrderSet(scale int, vw ValueWriter) testSet { - setType := MakeSetType(Int64Type) + setType := MakeSetType(NumberType) refType := MakeRefType(setType) - return newTestSet(int(setPattern)*scale, func(v Int64) Value { + return newTestSet(int(setPattern)*scale, func(v Number) Value { return vw.WriteValue(NewTypedSet(setType, v)) }, func(x, y Value) bool { return !y.(Ref).TargetRef().Less(x.(Ref).TargetRef()) @@ -209,7 +209,7 @@ func TestCompoundSetInsert(t *testing.T) { } run(len(ts.values)-offset, len(ts.values)) assert.Panics(func() { - expected.Insert(Int8(1)) + expected.Insert(Bool(true)) }, "Should panic due to wrong type") } @@ -260,7 +260,7 @@ func TestCompoundSetRemoveNonexistentValue(t *testing.T) { ts := getTestNativeOrderSet(2) original := ts.toCompoundSet() - actual := original.Remove(Int64(-1)) // rand.Int63 returns non-negative values. + actual := original.Remove(Number(-1)) // rand.Int63 returns non-negative values. assert.Equal(original.Len(), actual.Len()) assert.True(original.Equals(actual)) @@ -344,12 +344,12 @@ func TestCompoundSetUnion(t *testing.T) { func TestCompoundSetFirstNNumbers(t *testing.T) { assert := assert.New(t) - setType := MakeSetType(Int64Type) + setType := MakeSetType(NumberType) firstNNumbers := func(n int) []Value { nums := []Value{} for i := 0; i < n; i++ { - nums = append(nums, Int64(i)) + nums = append(nums, Number(i)) } return nums @@ -357,7 +357,7 @@ func TestCompoundSetFirstNNumbers(t *testing.T) { nums := firstNNumbers(5000) s := newTypedSet(setType, nums...) - assert.Equal(s.Ref().String(), "sha1-b8ce0af4afd144c64f58e393283407cc0321b0c3") + assert.Equal(s.Ref().String(), "sha1-5b4cd51d88b3d99e6dafdb1cafb8cec90d5aecdf") } func TestCompoundSetRefOfStructFirstNNumbers(t *testing.T) { @@ -365,7 +365,7 @@ func TestCompoundSetRefOfStructFirstNNumbers(t *testing.T) { vs := NewTestValueStore() structTypeDef := MakeStructType("num", []Field{ - Field{"n", Int64Type, false}, + Field{"n", NumberType, false}, }, []Field{}) pkg := NewPackage([]*Type{structTypeDef}, []ref.Ref{}) pkgRef := RegisterPackage(&pkg) @@ -377,7 +377,7 @@ func TestCompoundSetRefOfStructFirstNNumbers(t *testing.T) { firstNNumbers := func(n int) []Value { nums := []Value{} for i := 0; i < n; i++ { - r := vs.WriteValue(NewStruct(structType, structTypeDef, structData{"n": Int64(i)})) + r := vs.WriteValue(NewStruct(structType, structTypeDef, structData{"n": Number(i)})) nums = append(nums, r) } @@ -386,7 +386,7 @@ func TestCompoundSetRefOfStructFirstNNumbers(t *testing.T) { nums := firstNNumbers(5000) s := NewTypedSet(setType, nums...) - assert.Equal("sha1-f1126a3e01f462c6dd97e49dcaa79b9a448ee162", s.Ref().String()) + assert.Equal("sha1-4c2b0e159ae443ec99299b6ea266d9a408f7987d", s.Ref().String()) } func TestCompoundSetModifyAfterRead(t *testing.T) { diff --git a/types/decode_noms_value.go b/types/decode_noms_value.go index 49cf2cb8d0..041517a6ca 100644 --- a/types/decode_noms_value.go +++ b/types/decode_noms_value.go @@ -159,7 +159,7 @@ func indexTypeForMetaSequence(t *Type) *Type { default: panic(fmt.Sprintf("Unknown type used for metaSequence: %s", t.Describe())) case BlobKind, ListKind: - return Uint64Type + return NumberType case MapKind, SetKind: elemType := t.Desc.(CompoundDesc).ElemTypes[0] if elemType.IsOrdered() { @@ -223,26 +223,8 @@ func (r *jsonArrayReader) readValueWithoutTag(t *Type, pkg *Package) Value { return r.readBlob(t) case BoolKind: return Bool(r.read().(bool)) - case Uint8Kind: - return Uint8(r.readUint()) - case Uint16Kind: - return Uint16(r.readUint()) - case Uint32Kind: - return Uint32(r.readUint()) - case Uint64Kind: - return Uint64(r.readUint()) - case Int8Kind: - return Int8(r.readInt()) - case Int16Kind: - return Int16(r.readInt()) - case Int32Kind: - return Int32(r.readInt()) - case Int64Kind: - return Int64(r.readInt()) - case Float32Kind: - return Float32(r.readFloat()) - case Float64Kind: - return Float64(r.readFloat()) + case NumberKind: + return Number(r.readFloat()) case StringKind: return NewString(r.readString()) case ValueKind: @@ -375,8 +357,8 @@ func (r *jsonArrayReader) readStruct(typeDef, typ *Type, pkg *Package) Value { } } if len(desc.Union) > 0 { - unionIndex := uint32(r.readUint()) - values = append(values, Uint32(unionIndex), r.readValueWithoutTag(desc.Union[unionIndex].T, pkg)) + unionIndex := uint64(r.readUint()) + values = append(values, Number(unionIndex), r.readValueWithoutTag(desc.Union[unionIndex].T, pkg)) } return structBuilder(values, typ, typeDef) diff --git a/types/decode_noms_value_test.go b/types/decode_noms_value_test.go index a0fc3b5064..3f174cffa6 100644 --- a/types/decode_noms_value_test.go +++ b/types/decode_noms_value_test.go @@ -15,10 +15,10 @@ func TestRead(t *testing.T) { assert := assert.New(t) cs := NewTestValueStore() - a := []interface{}{float64(1), "hi", true} + a := []interface{}{Number(1), "hi", true} r := newJSONArrayReader(a, cs) - assert.Equal(float64(1), r.read().(float64)) + assert.Equal(Number(1), r.read().(Number)) assert.False(r.atEnd()) assert.Equal("hi", r.readString()) @@ -68,35 +68,24 @@ func TestReadPrimitives(t *testing.T) { test(Bool(true), "[%d, true]", BoolKind) test(Bool(false), "[%d, false]", BoolKind) - - test(Uint8(0), `[%d, "0"]`, Uint8Kind) - test(Uint16(0), `[%d, "0"]`, Uint16Kind) - test(Uint32(0), `[%d, "0"]`, Uint32Kind) - test(Uint64(0), `[%d, "0"]`, Uint64Kind) - test(Int8(0), `[%d, "0"]`, Int8Kind) - test(Int16(0), `[%d, "0"]`, Int16Kind) - test(Int32(0), `[%d, "0"]`, Int32Kind) - test(Int64(0), `[%d, "0"]`, Int64Kind) - test(Float32(0), `[%d, "0"]`, Float32Kind) - test(Float64(0), `[%d, "0"]`, Float64Kind) - + test(Number(0), `[%d, "0"]`, NumberKind) test(NewString("hi"), `[%d, "hi"]`, StringKind) blob := NewBlob(bytes.NewBuffer([]byte{0x00, 0x01})) test(blob, `[%d, false, "AAE="]`, BlobKind) } -func TestReadListOfInt32(t *testing.T) { +func TestReadListOfNumber(t *testing.T) { assert := assert.New(t) cs := NewTestValueStore() - a := parseJSON(`[%d, %d, false, ["0", "1", "2", "3"]]`, ListKind, Int32Kind) + a := parseJSON(`[%d, %d, false, ["0", "1", "2", "3"]]`, ListKind, NumberKind) r := newJSONArrayReader(a, cs) - tr := MakeListType(Int32Type) + tr := MakeListType(NumberType) l := r.readTopLevelValue() - l2 := NewTypedList(tr, Int32(0), Int32(1), Int32(2), Int32(3)) + l2 := NewTypedList(tr, Number(0), Number(1), Number(2), Number(3)) assert.True(l2.Equals(l)) } @@ -104,23 +93,23 @@ func TestReadListOfValue(t *testing.T) { assert := assert.New(t) cs := NewTestValueStore() - a := parseJSON(`[%d, %d, false, [%d, "1", %d, "hi", %d, true]]`, ListKind, ValueKind, Int32Kind, StringKind, BoolKind) + a := parseJSON(`[%d, %d, false, [%d, "1", %d, "hi", %d, true]]`, ListKind, ValueKind, NumberKind, StringKind, BoolKind) r := newJSONArrayReader(a, cs) l := r.readTopLevelValue() - assert.True(NewList(Int32(1), NewString("hi"), Bool(true)).Equals(l)) + assert.True(NewList(Number(1), NewString("hi"), Bool(true)).Equals(l)) } -func TestReadValueListOfInt8(t *testing.T) { +func TestReadValueListOfNumber(t *testing.T) { assert := assert.New(t) cs := NewTestValueStore() - a := parseJSON(`[%d, %d, %d, false, ["0", "1", "2"]]`, ValueKind, ListKind, Int8Kind) + a := parseJSON(`[%d, %d, %d, false, ["0", "1", "2"]]`, ValueKind, ListKind, NumberKind) r := newJSONArrayReader(a, cs) - tr := MakeListType(Int8Type) + tr := MakeListType(NumberType) l := r.readTopLevelValue() - l2 := NewTypedList(tr, Int8(0), Int8(1), Int8(2)) + l2 := NewTypedList(tr, Number(0), Number(1), Number(2)) assert.True(l2.Equals(l)) } @@ -128,15 +117,15 @@ func TestReadCompoundList(t *testing.T) { assert := assert.New(t) cs := NewTestValueStore() - tr := MakeListType(Int32Type) - leaf1 := newListLeaf(tr, Int32(0)) - leaf2 := newListLeaf(tr, Int32(1), Int32(2), Int32(3)) + tr := MakeListType(NumberType) + leaf1 := newListLeaf(tr, Number(0)) + leaf2 := newListLeaf(tr, Number(1), Number(2), Number(3)) l2 := buildCompoundList([]metaTuple{ - newMetaTuple(Uint64(1), leaf1, Ref{}, 1), - newMetaTuple(Uint64(4), leaf2, Ref{}, 4), + newMetaTuple(Number(1), leaf1, Ref{}, 1), + newMetaTuple(Number(4), leaf2, Ref{}, 4), }, tr, cs) - a := parseJSON(`[%d, %d, true, ["%s", "1", "1", "%s", "4", "4"]]`, ListKind, Int32Kind, leaf1.Ref(), leaf2.Ref()) + a := parseJSON(`[%d, %d, true, ["%s", "1", "1", "%s", "4", "4"]]`, ListKind, NumberKind, leaf1.Ref(), leaf2.Ref()) r := newJSONArrayReader(a, cs) l := r.readTopLevelValue() @@ -147,74 +136,74 @@ func TestReadCompoundSet(t *testing.T) { assert := assert.New(t) cs := NewTestValueStore() - tr := MakeSetType(Int32Type) - leaf1 := newSetLeaf(tr, Int32(0), Int32(1)) - leaf2 := newSetLeaf(tr, Int32(2), Int32(3), Int32(4)) + tr := MakeSetType(NumberType) + leaf1 := newSetLeaf(tr, Number(0), Number(1)) + leaf2 := newSetLeaf(tr, Number(2), Number(3), Number(4)) l2 := buildCompoundSet([]metaTuple{ - newMetaTuple(Int32(1), leaf1, Ref{}, 2), - newMetaTuple(Int32(4), leaf2, Ref{}, 3), + newMetaTuple(Number(1), leaf1, Ref{}, 2), + newMetaTuple(Number(4), leaf2, Ref{}, 3), }, tr, cs) - a := parseJSON(`[%d, %d, true, ["%s", "1", "2", "%s", "4", "3"]]`, SetKind, Int32Kind, leaf1.Ref(), leaf2.Ref()) + a := parseJSON(`[%d, %d, true, ["%s", "1", "2", "%s", "4", "3"]]`, SetKind, NumberKind, leaf1.Ref(), leaf2.Ref()) r := newJSONArrayReader(a, cs) l := r.readTopLevelValue() assert.True(l2.Equals(l)) } -func TestReadMapOfInt64ToFloat64(t *testing.T) { +func TestReadMapOfNumberToNumber(t *testing.T) { assert := assert.New(t) cs := NewTestValueStore() - a := parseJSON(`[%d, %d, %d, false, ["0", "1", "2", "3"]]`, MapKind, Int64Kind, Float64Kind) + a := parseJSON(`[%d, %d, %d, false, ["0", "1", "2", "3"]]`, MapKind, NumberKind, NumberKind) r := newJSONArrayReader(a, cs) - tr := MakeMapType(Int64Type, Float64Type) + tr := MakeMapType(NumberType, NumberType) m := r.readTopLevelValue() - m2 := NewTypedMap(tr, Int64(0), Float64(1), Int64(2), Float64(3)) + m2 := NewTypedMap(tr, Number(0), Number(1), Number(2), Number(3)) assert.True(m2.Equals(m)) } -func TestReadValueMapOfUint64ToUint32(t *testing.T) { +func TestReadValueMapOfNumberToNumber(t *testing.T) { assert := assert.New(t) cs := NewTestValueStore() - a := parseJSON(`[%d, %d, %d, %d, false, ["0", "1", "2", "3"]]`, ValueKind, MapKind, Uint64Kind, Uint32Kind) + a := parseJSON(`[%d, %d, %d, %d, false, ["0", "1", "2", "3"]]`, ValueKind, MapKind, NumberKind, NumberKind) r := newJSONArrayReader(a, cs) - mapTr := MakeMapType(Uint64Type, Uint32Type) + tr := MakeMapType(NumberType, NumberType) m := r.readTopLevelValue() - m2 := NewTypedMap(mapTr, Uint64(0), Uint32(1), Uint64(2), Uint32(3)) + m2 := NewTypedMap(tr, Number(0), Number(1), Number(2), Number(3)) assert.True(m2.Equals(m)) } -func TestReadSetOfUint8(t *testing.T) { +func TestReadSetOfNumber(t *testing.T) { assert := assert.New(t) cs := NewTestValueStore() - a := parseJSON(`[%d, %d, false, ["0", "1", "2", "3"]]`, SetKind, Uint8Kind) + a := parseJSON(`[%d, %d, false, ["0", "1", "2", "3"]]`, SetKind, NumberKind) r := newJSONArrayReader(a, cs) - tr := MakeSetType(Uint8Type) + tr := MakeSetType(NumberType) s := r.readTopLevelValue() - s2 := NewTypedSet(tr, Uint8(0), Uint8(1), Uint8(2), Uint8(3)) + s2 := NewTypedSet(tr, Number(0), Number(1), Number(2), Number(3)) assert.True(s2.Equals(s)) } -func TestReadValueSetOfUint16(t *testing.T) { +func TestReadValueSetOfNumber(t *testing.T) { assert := assert.New(t) cs := NewTestValueStore() - a := parseJSON(`[%d, %d, %d, false, ["0", "1", "2", "3"]]`, ValueKind, SetKind, Uint16Kind) + a := parseJSON(`[%d, %d, %d, false, ["0", "1", "2", "3"]]`, ValueKind, SetKind, NumberKind) r := newJSONArrayReader(a, cs) - setTr := MakeSetType(Uint16Type) + setTr := MakeSetType(NumberType) s := r.readTopLevelValue() - s2 := NewTypedSet(setTr, Uint16(0), Uint16(1), Uint16(2), Uint16(3)) + s2 := NewTypedSet(setTr, Number(0), Number(1), Number(2), Number(3)) assert.True(s2.Equals(s)) } @@ -232,9 +221,9 @@ func TestReadCompoundBlob(t *testing.T) { _, ok := m.(compoundBlob) assert.True(ok) m2 := newCompoundBlob([]metaTuple{ - newMetaTuple(Uint64(20), nil, NewTypedRef(MakeRefType(typeForBlob), r1), 20), - newMetaTuple(Uint64(40), nil, NewTypedRef(MakeRefType(typeForBlob), r2), 40), - newMetaTuple(Uint64(60), nil, NewTypedRef(MakeRefType(typeForBlob), r3), 60), + newMetaTuple(Number(20), nil, NewTypedRef(MakeRefType(typeForBlob), r1), 20), + newMetaTuple(Number(40), nil, NewTypedRef(MakeRefType(typeForBlob), r2), 40), + newMetaTuple(Number(60), nil, NewTypedRef(MakeRefType(typeForBlob), r3), 60), }, cs) assert.True(m.Type().Equals(m2.Type())) @@ -246,7 +235,7 @@ func TestReadStruct(t *testing.T) { cs := NewTestValueStore() typ := MakeStructType("A1", []Field{ - Field{"x", Int16Type, false}, + Field{"x", NumberType, false}, Field{"s", StringType, false}, Field{"b", BoolType, false}, }, []Field{}) @@ -257,7 +246,7 @@ func TestReadStruct(t *testing.T) { r := newJSONArrayReader(a, cs) v := r.readTopLevelValue().(Struct) - assert.True(v.Get("x").Equals(Int16(42))) + assert.True(v.Get("x").Equals(Number(42))) assert.True(v.Get("s").Equals(NewString("hi"))) assert.True(v.Get("b").Equals(Bool(true))) } @@ -267,7 +256,7 @@ func TestReadStructUnion(t *testing.T) { cs := NewTestValueStore() typ := MakeStructType("A2", []Field{ - Field{"x", Float32Type, false}, + Field{"x", NumberType, false}, }, []Field{ Field{"b", BoolType, false}, Field{"s", StringType, false}, @@ -279,13 +268,13 @@ func TestReadStructUnion(t *testing.T) { r := newJSONArrayReader(a, cs) v := r.readTopLevelValue().(Struct) - assert.True(v.Get("x").Equals(Float32(42))) - assert.Equal(uint32(1), v.UnionIndex()) + assert.True(v.Get("x").Equals(Number(42))) + assert.Equal(uint64(Number(1)), uint64(v.UnionIndex())) assert.True(v.UnionValue().Equals(NewString("hi"))) x, ok := v.MaybeGet("x") assert.True(ok) - assert.True(x.Equals(Float32(42))) + assert.True(x.Equals(Number(42))) s, ok := v.MaybeGet("s") assert.True(ok) @@ -298,7 +287,7 @@ func TestReadStructOptional(t *testing.T) { cs := NewTestValueStore() typ := MakeStructType("A3", []Field{ - Field{"x", Float32Type, false}, + Field{"x", NumberType, false}, Field{"s", StringType, true}, Field{"b", BoolType, true}, }, []Field{}) @@ -309,7 +298,7 @@ func TestReadStructOptional(t *testing.T) { r := newJSONArrayReader(a, cs) v := r.readTopLevelValue().(Struct) - assert.True(v.Get("x").Equals(Float32(42))) + assert.True(v.Get("x").Equals(Number(42))) _, ok := v.MaybeGet("s") assert.False(ok) assert.Panics(func() { v.Get("s") }) @@ -324,13 +313,13 @@ func TestReadStructWithList(t *testing.T) { // struct A4 { // b: Bool - // l: List(Int32) + // l: List(Number) // s: String // } typ := MakeStructType("A4", []Field{ Field{"b", BoolType, false}, - Field{"l", MakeListType(Int32Type), false}, + Field{"l", MakeListType(NumberType), false}, Field{"s", StringType, false}, }, []Field{}) pkg := NewPackage([]*Type{typ}, []ref.Ref{}) @@ -338,11 +327,11 @@ func TestReadStructWithList(t *testing.T) { a := parseJSON(`[%d, "%s", "0", true, false, ["0", "1", "2"], "hi"]`, UnresolvedKind, pkgRef.String()) r := newJSONArrayReader(a, cs) - l32Tr := MakeListType(Int32Type) + l32Tr := MakeListType(NumberType) v := r.readTopLevelValue().(Struct) assert.True(v.Get("b").Equals(Bool(true))) - l := NewTypedList(l32Tr, Int32(0), Int32(1), Int32(2)) + l := NewTypedList(l32Tr, Number(0), Number(1), Number(2)) assert.True(v.Get("l").Equals(l)) assert.True(v.Get("s").Equals(NewString("hi"))) } @@ -365,12 +354,12 @@ func TestReadStructWithValue(t *testing.T) { pkg := NewPackage([]*Type{typ}, []ref.Ref{}) pkgRef := RegisterPackage(&pkg) - a := parseJSON(`[%d, "%s", "0", true, %d, "42", "hi"]`, UnresolvedKind, pkgRef.String(), Uint8Kind) + a := parseJSON(`[%d, "%s", "0", true, %d, "42", "hi"]`, UnresolvedKind, pkgRef.String(), NumberKind) r := newJSONArrayReader(a, cs) v := r.readTopLevelValue().(Struct) assert.True(v.Get("b").Equals(Bool(true))) - assert.True(v.Get("v").Equals(Uint8(42))) + assert.True(v.Get("v").Equals(Number(42))) assert.True(v.Get("s").Equals(NewString("hi"))) } @@ -379,13 +368,13 @@ func TestReadValueStruct(t *testing.T) { cs := NewTestValueStore() // struct A1 { - // x: Float32 + // x: Number // b: Bool // s: String // } typ := MakeStructType("A1", []Field{ - Field{"x", Int16Type, false}, + Field{"x", NumberType, false}, Field{"s", StringType, false}, Field{"b", BoolType, false}, }, []Field{}) @@ -396,7 +385,7 @@ func TestReadValueStruct(t *testing.T) { r := newJSONArrayReader(a, cs) v := r.readTopLevelValue().(Struct) - assert.True(v.Get("x").Equals(Int16(42))) + assert.True(v.Get("x").Equals(Number(42))) assert.True(v.Get("s").Equals(NewString("hi"))) assert.True(v.Get("b").Equals(Bool(true))) } @@ -406,10 +395,10 @@ func TestReadRef(t *testing.T) { cs := NewTestValueStore() r := ref.Parse("sha1-a9993e364706816aba3e25717850c26c9cd0d89d") - a := parseJSON(`[%d, %d, "%s"]`, RefKind, Uint32Kind, r.String()) + a := parseJSON(`[%d, %d, "%s"]`, RefKind, NumberKind, r.String()) reader := newJSONArrayReader(a, cs) v := reader.readTopLevelValue() - tr := MakeRefType(Uint32Type) + tr := MakeRefType(NumberType) assert.True(NewTypedRef(tr, r).Equals(v)) } @@ -418,10 +407,10 @@ func TestReadValueRef(t *testing.T) { cs := NewTestValueStore() r := ref.Parse("sha1-a9993e364706816aba3e25717850c26c9cd0d89d") - a := parseJSON(`[%d, %d, %d, "%s"]`, ValueKind, RefKind, Uint32Kind, r.String()) + a := parseJSON(`[%d, %d, %d, "%s"]`, ValueKind, RefKind, NumberKind, r.String()) reader := newJSONArrayReader(a, cs) v := reader.readTopLevelValue() - tr := MakeRefType(Uint32Type) + tr := MakeRefType(NumberType) assert.True(NewTypedRef(tr, r).Equals(v)) } @@ -458,33 +447,33 @@ func TestReadTypeValue(t *testing.T) { assert.True(expected.Equals(tr)) } - test(Int32Type, - `[%d, %d]`, TypeKind, Int32Kind) + test(NumberType, + `[%d, %d]`, TypeKind, NumberKind) test(MakeListType(BoolType), `[%d, %d, [%d]]`, TypeKind, ListKind, BoolKind) test(MakeMapType(BoolType, StringType), `[%d, %d, [%d, %d]]`, TypeKind, MapKind, BoolKind, StringKind) test(MakeStructType("S", []Field{ - Field{"x", Int16Type, false}, + Field{"x", NumberType, false}, Field{"v", ValueType, true}, }, []Field{}), - `[%d, %d, "S", ["x", %d, false, "v", %d, true], []]`, TypeKind, StructKind, Int16Kind, ValueKind) + `[%d, %d, "S", ["x", %d, false, "v", %d, true], []]`, TypeKind, StructKind, NumberKind, ValueKind) test(MakeStructType("S", []Field{}, []Field{ - Field{"x", Int16Type, false}, + Field{"x", NumberType, false}, Field{"v", ValueType, false}, }), - `[%d, %d, "S", [], ["x", %d, false, "v", %d, false]]`, TypeKind, StructKind, Int16Kind, ValueKind) + `[%d, %d, "S", [], ["x", %d, false, "v", %d, false]]`, TypeKind, StructKind, NumberKind, ValueKind) pkgRef := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567") test(MakeType(pkgRef, 123), `[%d, %d, "%s", "123"]`, TypeKind, UnresolvedKind, pkgRef.String()) test(MakeStructType("S", []Field{ Field{"e", MakeType(pkgRef, 123), false}, - Field{"x", Int64Type, false}, + Field{"x", NumberType, false}, }, []Field{}), - `[%d, %d, "S", ["e", %d, "%s", "123", false, "x", %d, false], []]`, TypeKind, StructKind, UnresolvedKind, pkgRef.String(), Int64Kind) + `[%d, %d, "S", ["e", %d, "%s", "123", false, "x", %d, false], []]`, TypeKind, StructKind, UnresolvedKind, pkgRef.String(), NumberKind) test(MakeUnresolvedType("ns", "n"), `[%d, %d, "%s", "-1", "ns", "n"]`, TypeKind, UnresolvedKind, ref.Ref{}.String()) } @@ -493,10 +482,10 @@ func TestReadPackage2(t *testing.T) { cs := NewTestValueStore() rr := ref.Parse("sha1-a9993e364706816aba3e25717850c26c9cd0d89d") - setTref := MakeSetType(Uint32Type) + setTref := MakeSetType(NumberType) pkg := NewPackage([]*Type{setTref}, []ref.Ref{rr}) - a := []interface{}{float64(PackageKind), []interface{}{float64(SetKind), []interface{}{float64(Uint32Kind)}}, []interface{}{rr.String()}} + a := []interface{}{float64(PackageKind), []interface{}{float64(SetKind), []interface{}{float64(NumberKind)}}, []interface{}{rr.String()}} r := newJSONArrayReader(a, cs) v := r.readTopLevelValue().(Package) assert.True(t, pkg.Equals(v)) @@ -508,7 +497,7 @@ func TestReadPackageThroughChunkSource(t *testing.T) { pkg := NewPackage([]*Type{ MakeStructType("S", []Field{ - Field{"X", Int32Type, false}, + Field{"X", NumberType, false}, }, []Field{}), }, []ref.Ref{}) // Don't register @@ -518,5 +507,5 @@ func TestReadPackageThroughChunkSource(t *testing.T) { r := newJSONArrayReader(a, cs) v := r.readTopLevelValue().(Struct) - assert.True(v.Get("X").Equals(Int32(42))) + assert.True(v.Get("X").Equals(Number(42))) } diff --git a/types/encode_human_readable.go b/types/encode_human_readable.go index 1422a1bbfb..cbb0e32a55 100644 --- a/types/encode_human_readable.go +++ b/types/encode_human_readable.go @@ -51,26 +51,8 @@ func (w *hrsWriter) Write(v Value) { switch v.Type().Kind() { case BoolKind: w.write(strconv.FormatBool(bool(v.(Bool)))) - case Uint8Kind: - w.write(strconv.FormatUint(uint64(v.(Uint8)), 10)) - case Uint16Kind: - w.write(strconv.FormatUint(uint64(v.(Uint16)), 10)) - case Uint32Kind: - w.write(strconv.FormatUint(uint64(v.(Uint32)), 10)) - case Uint64Kind: - w.write(strconv.FormatUint(uint64(v.(Uint64)), 10)) - case Int8Kind: - w.write(strconv.FormatInt(int64(v.(Int8)), 10)) - case Int16Kind: - w.write(strconv.FormatInt(int64(v.(Int16)), 10)) - case Int32Kind: - w.write(strconv.FormatInt(int64(v.(Int32)), 10)) - case Int64Kind: - w.write(strconv.FormatInt(int64(v.(Int64)), 10)) - case Float32Kind: - w.write(strconv.FormatFloat(float64(v.(Float32)), 'g', -1, 32)) - case Float64Kind: - w.write(strconv.FormatFloat(float64(v.(Float64)), 'g', -1, 64)) + case NumberKind: + w.write(strconv.FormatFloat(float64(v.(Number)), 'g', -1, 64)) case StringKind: w.write(strconv.Quote(v.(String).String())) @@ -198,7 +180,7 @@ func (w *hrsWriter) WriteTagged(v Value) { switch t.Kind() { case BoolKind, StringKind: w.Write(v) - case Uint8Kind, Uint16Kind, Uint32Kind, Uint64Kind, Int8Kind, Int16Kind, Int32Kind, Int64Kind, Float32Kind, Float64Kind, BlobKind, ListKind, MapKind, RefKind, SetKind, TypeKind: + case NumberKind, BlobKind, ListKind, MapKind, RefKind, SetKind, TypeKind: w.writeTypeAsValue(t) w.write("(") w.Write(v) @@ -220,7 +202,7 @@ func (w *hrsWriter) WriteTagged(v Value) { func (w *hrsWriter) writeTypeAsValue(t *Type) { switch t.Kind() { - case BlobKind, BoolKind, Float32Kind, Float64Kind, Int16Kind, Int32Kind, Int64Kind, Int8Kind, StringKind, TypeKind, Uint16Kind, Uint32Kind, Uint64Kind, Uint8Kind, ValueKind, PackageKind: + case BlobKind, BoolKind, NumberKind, StringKind, TypeKind, ValueKind, PackageKind: w.write(KindToString[t.Kind()]) case ListKind, RefKind, SetKind: w.write(KindToString[t.Kind()]) diff --git a/types/encode_human_readable_test.go b/types/encode_human_readable_test.go index 0c8fb63509..236db0258d 100644 --- a/types/encode_human_readable_test.go +++ b/types/encode_human_readable_test.go @@ -28,43 +28,14 @@ func TestWriteHumanReadablePrimitiveValues(t *testing.T) { assertWriteHRSEqual(t, "true", Bool(true)) assertWriteHRSEqual(t, "false", Bool(false)) - assertWriteHRSEqual(t, "0", Uint8(0)) - assertWriteHRSEqual(t, "0", Uint16(0)) - assertWriteHRSEqual(t, "0", Uint32(0)) - assertWriteHRSEqual(t, "0", Uint64(0)) - assertWriteHRSEqual(t, "0", Int8(0)) - assertWriteHRSEqual(t, "0", Int16(0)) - assertWriteHRSEqual(t, "0", Int32(0)) - assertWriteHRSEqual(t, "0", Int64(0)) - assertWriteHRSEqual(t, "0", Float32(0)) - assertWriteHRSEqual(t, "0", Float64(0)) + assertWriteHRSEqual(t, "0", Number(0)) + assertWriteHRSEqual(t, "42", Number(42)) - assertWriteHRSEqual(t, "42", Uint8(42)) - assertWriteHRSEqual(t, "42", Uint16(42)) - assertWriteHRSEqual(t, "42", Uint32(42)) - assertWriteHRSEqual(t, "42", Uint64(42)) - assertWriteHRSEqual(t, "42", Int8(42)) - assertWriteHRSEqual(t, "42", Int16(42)) - assertWriteHRSEqual(t, "42", Int32(42)) - assertWriteHRSEqual(t, "42", Int64(42)) - assertWriteHRSEqual(t, "42", Float32(42)) - assertWriteHRSEqual(t, "42", Float64(42)) + assertWriteHRSEqual(t, "-42", Number(-42)) - assertWriteHRSEqual(t, "-42", Int8(-42)) - assertWriteHRSEqual(t, "-42", Int16(-42)) - assertWriteHRSEqual(t, "-42", Int32(-42)) - assertWriteHRSEqual(t, "-42", Int64(-42)) - assertWriteHRSEqual(t, "-42", Float32(-42)) - assertWriteHRSEqual(t, "-42", Float64(-42)) - - assertWriteHRSEqual(t, "3.1415927", Float32(3.1415926535)) - assertWriteHRSEqual(t, "3.1415926535", Float64(3.1415926535)) - - assertWriteHRSEqual(t, "314159.25", Float32(3.1415926535e5)) - assertWriteHRSEqual(t, "314159.26535", Float64(3.1415926535e5)) - - assertWriteHRSEqual(t, "3.1415925e+20", Float32(3.1415926535e20)) - assertWriteHRSEqual(t, "3.1415926535e+20", Float64(3.1415926535e20)) + assertWriteHRSEqual(t, "3.1415926535", Number(3.1415926535)) + assertWriteHRSEqual(t, "314159.26535", Number(3.1415926535e5)) + assertWriteHRSEqual(t, "3.1415926535e+20", Number(3.1415926535e20)) assertWriteHRSEqual(t, `"abc"`, NewString("abc")) assertWriteHRSEqual(t, `" "`, NewString(" ")) @@ -85,33 +56,33 @@ func TestWriteHumanReadablePrimitiveValues(t *testing.T) { func TestWriteHumanReadableRef(t *testing.T) { vs := NewTestValueStore() - x := Int32(42) + x := Number(42) rv := vs.WriteValue(x) - assertWriteHRSEqual(t, "sha1-c56efb6071a71743b826f2e10df26761549df9c2", rv) - assertWriteTaggedHRSEqual(t, "Ref(sha1-c56efb6071a71743b826f2e10df26761549df9c2)", rv) + assertWriteHRSEqual(t, "sha1-bd0b7d4cb11321762f4206f0d6c6fdf820f8556e", rv) + assertWriteTaggedHRSEqual(t, "Ref(sha1-bd0b7d4cb11321762f4206f0d6c6fdf820f8556e)", rv) } func TestWriteHumanReadableCollections(t *testing.T) { - lt := MakeListType(Float64Type) - l := NewTypedList(lt, Float64(0), Float64(1), Float64(2), Float64(3)) + lt := MakeListType(NumberType) + l := NewTypedList(lt, Number(0), Number(1), Number(2), Number(3)) assertWriteHRSEqual(t, "[\n 0,\n 1,\n 2,\n 3,\n]", l) - assertWriteTaggedHRSEqual(t, "List([\n 0,\n 1,\n 2,\n 3,\n])", l) + assertWriteTaggedHRSEqual(t, "List([\n 0,\n 1,\n 2,\n 3,\n])", l) - st := MakeSetType(Int8Type) - s := NewTypedSet(st, Int8(0), Int8(1), Int8(2), Int8(3)) + st := MakeSetType(NumberType) + s := NewTypedSet(st, Number(0), Number(1), Number(2), Number(3)) assertWriteHRSEqual(t, "{\n 0,\n 1,\n 2,\n 3,\n}", s) - assertWriteTaggedHRSEqual(t, "Set({\n 0,\n 1,\n 2,\n 3,\n})", s) + assertWriteTaggedHRSEqual(t, "Set({\n 0,\n 1,\n 2,\n 3,\n})", s) - mt := MakeMapType(Int32Type, BoolType) - m := NewTypedMap(mt, Int32(0), Bool(false), Int32(1), Bool(true)) + mt := MakeMapType(NumberType, BoolType) + m := NewTypedMap(mt, Number(0), Bool(false), Number(1), Bool(true)) assertWriteHRSEqual(t, "{\n 0: false,\n 1: true,\n}", m) - assertWriteTaggedHRSEqual(t, "Map({\n 0: false,\n 1: true,\n})", m) + assertWriteTaggedHRSEqual(t, "Map({\n 0: false,\n 1: true,\n})", m) } func TestWriteHumanReadableNested(t *testing.T) { - lt := MakeListType(Float64Type) - l := NewTypedList(lt, Float64(0), Float64(1)) - l2 := NewTypedList(lt, Float64(2), Float64(3)) + lt := MakeListType(NumberType) + l := NewTypedList(lt, Number(0), Number(1)) + l2 := NewTypedList(lt, Number(2), Number(3)) st := MakeSetType(StringType) s := NewTypedSet(st, NewString("a"), NewString("b")) @@ -135,7 +106,7 @@ func TestWriteHumanReadableNested(t *testing.T) { 1, ], }`, m) - assertWriteTaggedHRSEqual(t, `Map, List>({ + assertWriteTaggedHRSEqual(t, `Map, List>({ { "c", "d", @@ -156,8 +127,8 @@ func TestWriteHumanReadableNested(t *testing.T) { func TestWriteHumanReadableStruct(t *testing.T) { pkg := NewPackage([]*Type{ MakeStructType("S1", []Field{ - Field{Name: "x", T: Int32Type, Optional: false}, - Field{Name: "y", T: Int32Type, Optional: true}, + Field{Name: "x", T: NumberType, Optional: false}, + Field{Name: "y", T: NumberType, Optional: true}, }, []Field{}), }, []ref.Ref{}) typeDef := pkg.Types()[0] @@ -165,24 +136,24 @@ func TestWriteHumanReadableStruct(t *testing.T) { typ := MakeType(pkg.Ref(), 0) str := NewStruct(typ, typeDef, map[string]Value{ - "x": Int32(1), + "x": Number(1), }) assertWriteHRSEqual(t, "S1 {\n x: 1,\n}", str) - assertWriteTaggedHRSEqual(t, "Struct({\n x: 1,\n})", str) + assertWriteTaggedHRSEqual(t, "Struct({\n x: 1,\n})", str) str2 := NewStruct(typ, typeDef, map[string]Value{ - "x": Int32(2), - "y": Int32(3), + "x": Number(2), + "y": Number(3), }) assertWriteHRSEqual(t, "S1 {\n x: 2,\n y: 3,\n}", str2) - assertWriteTaggedHRSEqual(t, "Struct({\n x: 2,\n y: 3,\n})", str2) + assertWriteTaggedHRSEqual(t, "Struct({\n x: 2,\n y: 3,\n})", str2) } func TestWriteHumanReadableStructWithUnion(t *testing.T) { pkg := NewPackage([]*Type{ MakeStructType("S2", []Field{}, []Field{ - Field{Name: "x", T: Int32Type, Optional: false}, - Field{Name: "y", T: Int32Type, Optional: false}, + Field{Name: "x", T: NumberType, Optional: false}, + Field{Name: "y", T: NumberType, Optional: false}, }), }, []ref.Ref{}) typeDef := pkg.Types()[0] @@ -190,22 +161,22 @@ func TestWriteHumanReadableStructWithUnion(t *testing.T) { typ := MakeType(pkg.Ref(), 0) str := NewStruct(typ, typeDef, map[string]Value{ - "x": Int32(1), + "x": Number(1), }) assertWriteHRSEqual(t, "S2 {\n x: 1,\n}", str) - assertWriteTaggedHRSEqual(t, "Struct({\n x: 1,\n})", str) + assertWriteTaggedHRSEqual(t, "Struct({\n x: 1,\n})", str) str2 := NewStruct(typ, typeDef, map[string]Value{ - "y": Int32(2), + "y": Number(2), }) assertWriteHRSEqual(t, "S2 {\n y: 2,\n}", str2) - assertWriteTaggedHRSEqual(t, "Struct({\n y: 2,\n})", str2) + assertWriteTaggedHRSEqual(t, "Struct({\n y: 2,\n})", str2) } func TestWriteHumanReadableListOfStruct(t *testing.T) { pkg := NewPackage([]*Type{ MakeStructType("S3", []Field{}, []Field{ - Field{Name: "x", T: Int32Type, Optional: false}, + Field{Name: "x", T: NumberType, Optional: false}, }), }, []ref.Ref{}) typeDef := pkg.Types()[0] @@ -213,13 +184,13 @@ func TestWriteHumanReadableListOfStruct(t *testing.T) { typ := MakeType(pkg.Ref(), 0) str1 := NewStruct(typ, typeDef, map[string]Value{ - "x": Int32(1), + "x": Number(1), }) str2 := NewStruct(typ, typeDef, map[string]Value{ - "x": Int32(2), + "x": Number(2), }) str3 := NewStruct(typ, typeDef, map[string]Value{ - "x": Int32(3), + "x": Number(3), }) lt := MakeListType(typ) l := NewTypedList(lt, str1, str2, str3) @@ -234,7 +205,7 @@ func TestWriteHumanReadableListOfStruct(t *testing.T) { x: 3, }, ]`, l) - assertWriteTaggedHRSEqual(t, `List>([ + assertWriteTaggedHRSEqual(t, `List>([ S3 { x: 1, }, @@ -286,21 +257,12 @@ func TestWriteHumanReadableType(t *testing.T) { assertWriteHRSEqual(t, "Blob", BlobType) assertWriteHRSEqual(t, "String", StringType) - assertWriteHRSEqual(t, "Int8", Int8Type) - assertWriteHRSEqual(t, "Int16", Int16Type) - assertWriteHRSEqual(t, "Int32", Int32Type) - assertWriteHRSEqual(t, "Int64", Int64Type) - assertWriteHRSEqual(t, "Uint8", Uint8Type) - assertWriteHRSEqual(t, "Uint16", Uint16Type) - assertWriteHRSEqual(t, "Uint32", Uint32Type) - assertWriteHRSEqual(t, "Uint64", Uint64Type) - assertWriteHRSEqual(t, "Float32", Float32Type) - assertWriteHRSEqual(t, "Float64", Float64Type) + assertWriteHRSEqual(t, "Number", NumberType) - assertWriteHRSEqual(t, "List", MakeListType(Int8Type)) - assertWriteHRSEqual(t, "Set", MakeSetType(Int16Type)) - assertWriteHRSEqual(t, "Ref", MakeRefType(Int32Type)) - assertWriteHRSEqual(t, "Map", MakeMapType(Int64Type, StringType)) + assertWriteHRSEqual(t, "List", MakeListType(NumberType)) + assertWriteHRSEqual(t, "Set", MakeSetType(NumberType)) + assertWriteHRSEqual(t, "Ref", MakeRefType(NumberType)) + assertWriteHRSEqual(t, "Map", MakeMapType(NumberType, StringType)) pkg := NewPackage([]*Type{ MakeStructType("Str", []Field{ @@ -314,23 +276,23 @@ func TestWriteHumanReadableType(t *testing.T) { RegisterPackage(&pkg) st := MakeType(pkg.Ref(), 0) - assertWriteHRSEqual(t, "Struct", st) - assertWriteTaggedHRSEqual(t, "Type(Struct)", st) + assertWriteHRSEqual(t, "Struct", st) + assertWriteTaggedHRSEqual(t, "Type(Struct)", st) sTypeDef := pkg.Types()[0] assertWriteHRSEqual(t, `struct Str { - c: Struct + c: Struct o: optional String union { - x: Struct + x: Struct y: Bool } }`, sTypeDef) assertWriteTaggedHRSEqual(t, `Type(struct Str { - c: Struct + c: Struct o: optional String union { - x: Struct + x: Struct y: Bool } })`, sTypeDef) @@ -340,43 +302,15 @@ func TestWriteHumanReadableTaggedPrimitiveValues(t *testing.T) { assertWriteHRSEqual(t, "true", Bool(true)) assertWriteHRSEqual(t, "false", Bool(false)) - assertWriteTaggedHRSEqual(t, "Uint8(0)", Uint8(0)) - assertWriteTaggedHRSEqual(t, "Uint16(0)", Uint16(0)) - assertWriteTaggedHRSEqual(t, "Uint32(0)", Uint32(0)) - assertWriteTaggedHRSEqual(t, "Uint64(0)", Uint64(0)) - assertWriteTaggedHRSEqual(t, "Int8(0)", Int8(0)) - assertWriteTaggedHRSEqual(t, "Int16(0)", Int16(0)) - assertWriteTaggedHRSEqual(t, "Int32(0)", Int32(0)) - assertWriteTaggedHRSEqual(t, "Int64(0)", Int64(0)) - assertWriteTaggedHRSEqual(t, "Float32(0)", Float32(0)) - assertWriteTaggedHRSEqual(t, "Float64(0)", Float64(0)) + assertWriteTaggedHRSEqual(t, "Number(0)", Number(0)) + assertWriteTaggedHRSEqual(t, "Number(42)", Number(42)) + assertWriteTaggedHRSEqual(t, "Number(-42)", Number(-42)) - assertWriteTaggedHRSEqual(t, "Uint8(42)", Uint8(42)) - assertWriteTaggedHRSEqual(t, "Uint16(42)", Uint16(42)) - assertWriteTaggedHRSEqual(t, "Uint32(42)", Uint32(42)) - assertWriteTaggedHRSEqual(t, "Uint64(42)", Uint64(42)) - assertWriteTaggedHRSEqual(t, "Int8(42)", Int8(42)) - assertWriteTaggedHRSEqual(t, "Int16(42)", Int16(42)) - assertWriteTaggedHRSEqual(t, "Int32(42)", Int32(42)) - assertWriteTaggedHRSEqual(t, "Int64(42)", Int64(42)) - assertWriteTaggedHRSEqual(t, "Float32(42)", Float32(42)) - assertWriteTaggedHRSEqual(t, "Float64(42)", Float64(42)) + assertWriteTaggedHRSEqual(t, "Number(3.1415926535)", Number(3.1415926535)) - assertWriteTaggedHRSEqual(t, "Int8(-42)", Int8(-42)) - assertWriteTaggedHRSEqual(t, "Int16(-42)", Int16(-42)) - assertWriteTaggedHRSEqual(t, "Int32(-42)", Int32(-42)) - assertWriteTaggedHRSEqual(t, "Int64(-42)", Int64(-42)) - assertWriteTaggedHRSEqual(t, "Float32(-42)", Float32(-42)) - assertWriteTaggedHRSEqual(t, "Float64(-42)", Float64(-42)) + assertWriteTaggedHRSEqual(t, "Number(314159.26535)", Number(3.1415926535e5)) - assertWriteTaggedHRSEqual(t, "Float32(3.1415927)", Float32(3.1415926535)) - assertWriteTaggedHRSEqual(t, "Float64(3.1415926535)", Float64(3.1415926535)) - - assertWriteTaggedHRSEqual(t, "Float32(314159.25)", Float32(3.1415926535e5)) - assertWriteTaggedHRSEqual(t, "Float64(314159.26535)", Float64(3.1415926535e5)) - - assertWriteTaggedHRSEqual(t, "Float32(3.1415925e+20)", Float32(3.1415926535e20)) - assertWriteTaggedHRSEqual(t, "Float64(3.1415926535e+20)", Float64(3.1415926535e20)) + assertWriteTaggedHRSEqual(t, "Number(3.1415926535e+20)", Number(3.1415926535e20)) assertWriteTaggedHRSEqual(t, `"abc"`, NewString("abc")) assertWriteTaggedHRSEqual(t, `" "`, NewString(" ")) @@ -398,21 +332,10 @@ func TestWriteHumanReadableTaggedType(t *testing.T) { assertWriteTaggedHRSEqual(t, "Type(Bool)", BoolType) assertWriteTaggedHRSEqual(t, "Type(Blob)", BlobType) assertWriteTaggedHRSEqual(t, "Type(String)", StringType) - - assertWriteTaggedHRSEqual(t, "Type(Int8)", Int8Type) - assertWriteTaggedHRSEqual(t, "Type(Int16)", Int16Type) - assertWriteTaggedHRSEqual(t, "Type(Int32)", Int32Type) - assertWriteTaggedHRSEqual(t, "Type(Int64)", Int64Type) - assertWriteTaggedHRSEqual(t, "Type(Uint8)", Uint8Type) - assertWriteTaggedHRSEqual(t, "Type(Uint16)", Uint16Type) - assertWriteTaggedHRSEqual(t, "Type(Uint32)", Uint32Type) - assertWriteTaggedHRSEqual(t, "Type(Uint64)", Uint64Type) - assertWriteTaggedHRSEqual(t, "Type(Float32)", Float32Type) - assertWriteTaggedHRSEqual(t, "Type(Float64)", Float64Type) - - assertWriteTaggedHRSEqual(t, "Type(List)", MakeListType(Int8Type)) - assertWriteTaggedHRSEqual(t, "Type(Set)", MakeSetType(Int16Type)) - assertWriteTaggedHRSEqual(t, "Type(Ref)", MakeRefType(Int32Type)) - assertWriteTaggedHRSEqual(t, "Type(Map)", MakeMapType(Int64Type, StringType)) + assertWriteTaggedHRSEqual(t, "Type(Number)", NumberType) + assertWriteTaggedHRSEqual(t, "Type(List)", MakeListType(NumberType)) + assertWriteTaggedHRSEqual(t, "Type(Set)", MakeSetType(NumberType)) + assertWriteTaggedHRSEqual(t, "Type(Ref)", MakeRefType(NumberType)) + assertWriteTaggedHRSEqual(t, "Type(Map)", MakeMapType(NumberType, StringType)) } diff --git a/types/encode_noms_value.go b/types/encode_noms_value.go index 4f756db6fc..128cd3c022 100644 --- a/types/encode_noms_value.go +++ b/types/encode_noms_value.go @@ -123,26 +123,8 @@ func (w *jsonArrayWriter) writeValue(v Value, tr *Type, pkg *Package) { w.writeBlob(v.(Blob)) case BoolKind: w.writeBool(bool(v.(Bool))) - case Float32Kind: - w.writeFloat(float64(v.(Float32))) - case Float64Kind: - w.writeFloat(float64(v.(Float64))) - case Int16Kind: - w.writeInt(int64(v.(Int16))) - case Int32Kind: - w.writeInt(int64(v.(Int32))) - case Int64Kind: - w.writeInt(int64(v.(Int64))) - case Int8Kind: - w.writeInt(int64(v.(Int8))) - case Uint16Kind: - w.writeUint(uint64(v.(Uint16))) - case Uint32Kind: - w.writeUint(uint64(v.(Uint32))) - case Uint64Kind: - w.writeUint(uint64(v.(Uint64))) - case Uint8Kind: - w.writeUint(uint64(v.(Uint8))) + case NumberKind: + w.writeFloat(float64(v.(Number))) case ListKind: if w.maybeWriteMetaSequence(v, tr, pkg) { return @@ -312,7 +294,7 @@ func (w *jsonArrayWriter) writeStruct(v Value, typ, typeDef *Type, pkg *Package) } } if len(desc.Union) > 0 { - unionIndex := uint64(values[i].(Uint32)) + unionIndex := uint64(values[i].(Number)) i++ w.writeUint(unionIndex) w.writeValue(values[i], desc.Union[unionIndex].T, pkg) diff --git a/types/encode_noms_value_test.go b/types/encode_noms_value_test.go index c910a5f88f..1d1d3fc6cc 100644 --- a/types/encode_noms_value_test.go +++ b/types/encode_noms_value_test.go @@ -21,21 +21,11 @@ func TestWritePrimitives(t *testing.T) { f(BoolKind, Bool(true), true) f(BoolKind, Bool(false), false) - f(Uint8Kind, Uint8(0), "0") - f(Uint16Kind, Uint16(0), "0") - f(Uint32Kind, Uint32(0), "0") - f(Uint64Kind, Uint64(0), "0") - f(Int8Kind, Int8(0), "0") - f(Int16Kind, Int16(0), "0") - f(Int32Kind, Int32(0), "0") - f(Int64Kind, Int64(0), "0") - f(Float32Kind, Float32(0), "0") - f(Float64Kind, Float64(0), "0") - - f(Int64Kind, Int64(1e18), "1000000000000000000") - f(Uint64Kind, Uint64(1e19), "10000000000000000000") - f(Float64Kind, Float64(float64(1e19)), "10000000000000000000") - f(Float64Kind, Float64(float64(1e20)), "1e+20") + f(NumberKind, Number(0), "0") + f(NumberKind, Number(1e18), "1000000000000000000") + f(NumberKind, Number(1e19), "10000000000000000000") + f(NumberKind, Number(float64(1e19)), "10000000000000000000") + f(NumberKind, Number(float64(1e20)), "1e+20") f(StringKind, NewString("hi"), "hi") } @@ -50,51 +40,51 @@ func TestWriteSimpleBlob(t *testing.T) { func TestWriteList(t *testing.T) { assert := assert.New(t) - typ := MakeListType(Int32Type) - v := NewTypedList(typ, Int32(0), Int32(1), Int32(2), Int32(3)) + typ := MakeListType(NumberType) + v := NewTypedList(typ, Number(0), Number(1), Number(2), Number(3)) w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(v) - assert.EqualValues([]interface{}{ListKind, Int32Kind, false, []interface{}{"0", "1", "2", "3"}}, w.toArray()) + assert.EqualValues([]interface{}{ListKind, NumberKind, false, []interface{}{"0", "1", "2", "3"}}, w.toArray()) } func TestWriteListOfList(t *testing.T) { assert := assert.New(t) - it := MakeListType(Int16Type) + it := MakeListType(NumberType) typ := MakeListType(it) - l1 := NewTypedList(it, Int16(0)) - l2 := NewTypedList(it, Int16(1), Int16(2), Int16(3)) + l1 := NewTypedList(it, Number(0)) + l2 := NewTypedList(it, Number(1), Number(2), Number(3)) v := NewTypedList(typ, l1, l2) w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(v) - assert.EqualValues([]interface{}{ListKind, ListKind, Int16Kind, false, []interface{}{false, []interface{}{"0"}, false, []interface{}{"1", "2", "3"}}}, w.toArray()) + assert.EqualValues([]interface{}{ListKind, ListKind, NumberKind, false, []interface{}{false, []interface{}{"0"}, false, []interface{}{"1", "2", "3"}}}, w.toArray()) } func TestWriteSet(t *testing.T) { assert := assert.New(t) - typ := MakeSetType(Uint32Type) - v := NewTypedSet(typ, Uint32(3), Uint32(1), Uint32(2), Uint32(0)) + typ := MakeSetType(NumberType) + v := NewTypedSet(typ, Number(3), Number(1), Number(2), Number(0)) w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(v) // The order of the elements is based on the order defined by OrderedValue. - assert.EqualValues([]interface{}{SetKind, Uint32Kind, false, []interface{}{"0", "1", "2", "3"}}, w.toArray()) + assert.EqualValues([]interface{}{SetKind, NumberKind, false, []interface{}{"0", "1", "2", "3"}}, w.toArray()) } func TestWriteSetOfSet(t *testing.T) { assert := assert.New(t) - st := MakeSetType(Int32Type) + st := MakeSetType(NumberType) typ := MakeSetType(st) - v := NewTypedSet(typ, NewTypedSet(st, Int32(0)), NewTypedSet(st, Int32(1), Int32(2), Int32(3))) + v := NewTypedSet(typ, NewTypedSet(st, Number(0)), NewTypedSet(st, Number(1), Number(2), Number(3))) w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(v) // The order of the elements is based on the order defined by OrderedValue. - assert.EqualValues([]interface{}{SetKind, SetKind, Int32Kind, false, []interface{}{false, []interface{}{"1", "2", "3"}, false, []interface{}{"0"}}}, w.toArray()) + assert.EqualValues([]interface{}{SetKind, SetKind, NumberKind, false, []interface{}{false, []interface{}{"1", "2", "3"}, false, []interface{}{"0"}}}, w.toArray()) } func TestWriteMap(t *testing.T) { @@ -112,15 +102,15 @@ func TestWriteMap(t *testing.T) { func TestWriteMapOfMap(t *testing.T) { assert := assert.New(t) - kt := MakeMapType(StringType, Int64Type) + kt := MakeMapType(StringType, NumberType) vt := MakeSetType(BoolType) typ := MakeMapType(kt, vt) - v := NewTypedMap(typ, NewTypedMap(kt, NewString("a"), Int64(0)), NewTypedSet(vt, Bool(true))) + v := NewTypedMap(typ, NewTypedMap(kt, NewString("a"), Number(0)), NewTypedSet(vt, Bool(true))) w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(v) // the order of the elements is based on the ref of the value. - assert.EqualValues([]interface{}{MapKind, MapKind, StringKind, Int64Kind, SetKind, BoolKind, false, []interface{}{false, []interface{}{"a", "0"}, false, []interface{}{true}}}, w.toArray()) + assert.EqualValues([]interface{}{MapKind, MapKind, StringKind, NumberKind, SetKind, BoolKind, false, []interface{}{false, []interface{}{"a", "0"}, false, []interface{}{true}}}, w.toArray()) } func TestWriteCompoundBlob(t *testing.T) { @@ -131,9 +121,9 @@ func TestWriteCompoundBlob(t *testing.T) { r3 := ref.Parse("sha1-0000000000000000000000000000000000000003") v := newCompoundBlob([]metaTuple{ - newMetaTuple(Uint64(20), nil, NewTypedRef(MakeRefType(typeForBlob), r1), 20), - newMetaTuple(Uint64(40), nil, NewTypedRef(MakeRefType(typeForBlob), r2), 40), - newMetaTuple(Uint64(60), nil, NewTypedRef(MakeRefType(typeForBlob), r3), 60), + newMetaTuple(Number(20), nil, NewTypedRef(MakeRefType(typeForBlob), r1), 20), + newMetaTuple(Number(40), nil, NewTypedRef(MakeRefType(typeForBlob), r2), 40), + newMetaTuple(Number(60), nil, NewTypedRef(MakeRefType(typeForBlob), r3), 60), }, NewTestValueStore()) w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(v) @@ -160,13 +150,13 @@ func TestWriteStruct(t *testing.T) { assert := assert.New(t) typeDef := MakeStructType("S", []Field{ - Field{"x", Int8Type, false}, + Field{"x", NumberType, false}, Field{"b", BoolType, false}, }, []Field{}) pkg := NewPackage([]*Type{typeDef}, []ref.Ref{}) pkgRef := RegisterPackage(&pkg) typ := MakeType(pkgRef, 0) - v := NewStruct(typ, typeDef, structData{"x": Int8(42), "b": Bool(true)}) + v := NewStruct(typ, typeDef, structData{"x": Number(42), "b": Bool(true)}) w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(v) @@ -177,13 +167,13 @@ func TestWriteStructOptionalField(t *testing.T) { assert := assert.New(t) typeDef := MakeStructType("S", []Field{ - Field{"x", Int8Type, true}, + Field{"x", NumberType, true}, Field{"b", BoolType, false}, }, []Field{}) pkg := NewPackage([]*Type{typeDef}, []ref.Ref{}) pkgRef := RegisterPackage(&pkg) typ := MakeType(pkgRef, 0) - v := NewStruct(typ, typeDef, structData{"x": Int8(42), "b": Bool(true)}) + v := NewStruct(typ, typeDef, structData{"x": Number(42), "b": Bool(true)}) w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(v) @@ -200,7 +190,7 @@ func TestWriteStructWithUnion(t *testing.T) { assert := assert.New(t) typeDef := MakeStructType("S", []Field{ - Field{"x", Int8Type, false}, + Field{"x", NumberType, false}, }, []Field{ Field{"b", BoolType, false}, Field{"s", StringType, false}, @@ -208,13 +198,13 @@ func TestWriteStructWithUnion(t *testing.T) { pkg := NewPackage([]*Type{typeDef}, []ref.Ref{}) pkgRef := RegisterPackage(&pkg) typ := MakeType(pkgRef, 0) - v := NewStruct(typ, typeDef, structData{"x": Int8(42), "s": NewString("hi")}) + v := NewStruct(typ, typeDef, structData{"x": Number(42), "s": NewString("hi")}) w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(v) assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), "0", "42", "1", "hi"}, w.toArray()) - v = NewStruct(typ, typeDef, structData{"x": Int8(42), "b": Bool(true)}) + v = NewStruct(typ, typeDef, structData{"x": Number(42), "b": Bool(true)}) w = newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(v) @@ -246,7 +236,7 @@ func TestWriteStructWithStruct(t *testing.T) { assert := assert.New(t) s2TypeDef := MakeStructType("S2", []Field{ - Field{"x", Int32Type, false}, + Field{"x", NumberType, false}, }, []Field{}) sTypeDef := MakeStructType("S", []Field{ Field{"s", MakeType(ref.Ref{}, 0), false}, @@ -256,7 +246,7 @@ func TestWriteStructWithStruct(t *testing.T) { s2Type := MakeType(pkgRef, 0) sType := MakeType(pkgRef, 1) - v := NewStruct(sType, sTypeDef, structData{"s": NewStruct(s2Type, s2TypeDef, structData{"x": Int32(42)})}) + v := NewStruct(sType, sTypeDef, structData{"s": NewStruct(s2Type, s2TypeDef, structData{"x": Number(42)})}) w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(v) assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), "1", "42"}, w.toArray()) @@ -282,33 +272,33 @@ func TestWriteStructWithBlob(t *testing.T) { func TestWriteCompoundList(t *testing.T) { assert := assert.New(t) - ltr := MakeListType(Int32Type) - leaf1 := newListLeaf(ltr, Int32(0)) - leaf2 := newListLeaf(ltr, Int32(1), Int32(2), Int32(3)) + ltr := MakeListType(NumberType) + leaf1 := newListLeaf(ltr, Number(0)) + leaf2 := newListLeaf(ltr, Number(1), Number(2), Number(3)) cl := buildCompoundList([]metaTuple{ - newMetaTuple(Uint64(1), leaf1, Ref{}, 1), - newMetaTuple(Uint64(4), leaf2, Ref{}, 4), + newMetaTuple(Number(1), leaf1, Ref{}, 1), + newMetaTuple(Number(4), leaf2, Ref{}, 4), }, ltr, NewTestValueStore()) w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(cl) - assert.EqualValues([]interface{}{ListKind, Int32Kind, true, []interface{}{leaf1.Ref().String(), "1", "1", leaf2.Ref().String(), "4", "4"}}, w.toArray()) + assert.EqualValues([]interface{}{ListKind, NumberKind, true, []interface{}{leaf1.Ref().String(), "1", "1", leaf2.Ref().String(), "4", "4"}}, w.toArray()) } func TestWriteCompoundSet(t *testing.T) { assert := assert.New(t) - ltr := MakeSetType(Int32Type) - leaf1 := newSetLeaf(ltr, Int32(0), Int32(1)) - leaf2 := newSetLeaf(ltr, Int32(2), Int32(3), Int32(4)) + ltr := MakeSetType(NumberType) + leaf1 := newSetLeaf(ltr, Number(0), Number(1)) + leaf2 := newSetLeaf(ltr, Number(2), Number(3), Number(4)) cl := buildCompoundSet([]metaTuple{ - newMetaTuple(Int32(1), leaf1, Ref{}, 2), - newMetaTuple(Int32(4), leaf2, Ref{}, 3), + newMetaTuple(Number(1), leaf1, Ref{}, 2), + newMetaTuple(Number(4), leaf2, Ref{}, 3), }, ltr, NewTestValueStore()) w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(cl) - assert.EqualValues([]interface{}{SetKind, Int32Kind, true, []interface{}{leaf1.Ref().String(), "1", "2", leaf2.Ref().String(), "4", "3"}}, w.toArray()) + assert.EqualValues([]interface{}{SetKind, NumberKind, true, []interface{}{leaf1.Ref().String(), "1", "2", leaf2.Ref().String(), "4", "3"}}, w.toArray()) } func TestWriteListOfValue(t *testing.T) { @@ -318,16 +308,7 @@ func TestWriteListOfValue(t *testing.T) { blob := NewBlob(bytes.NewBuffer([]byte{0x01})) v := NewTypedList(typ, Bool(true), - Uint8(1), - Uint16(1), - Uint32(1), - Uint64(1), - Int8(1), - Int16(1), - Int32(1), - Int64(1), - Float32(1), - Float64(1), + Number(1), NewString("hi"), blob, ) @@ -337,16 +318,7 @@ func TestWriteListOfValue(t *testing.T) { assert.EqualValues([]interface{}{ListKind, ValueKind, false, []interface{}{ BoolKind, true, - Uint8Kind, "1", - Uint16Kind, "1", - Uint32Kind, "1", - Uint64Kind, "1", - Int8Kind, "1", - Int16Kind, "1", - Int32Kind, "1", - Int64Kind, "1", - Float32Kind, "1", - Float64Kind, "1", + NumberKind, "1", StringKind, "hi", BlobKind, false, "AQ==", }}, w.toArray()) @@ -356,13 +328,13 @@ func TestWriteListOfValueWithStruct(t *testing.T) { assert := assert.New(t) typeDef := MakeStructType("S", []Field{ - Field{"x", Int32Type, false}, + Field{"x", NumberType, false}, }, []Field{}) pkg := NewPackage([]*Type{typeDef}, []ref.Ref{}) pkgRef := RegisterPackage(&pkg) listType := MakeListType(ValueType) structType := MakeType(pkgRef, 0) - v := NewTypedList(listType, NewStruct(structType, typeDef, structData{"x": Int32(42)})) + v := NewTypedList(listType, NewStruct(structType, typeDef, structData{"x": Number(42)})) w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(v) @@ -374,14 +346,14 @@ func TestWriteListOfValueWithType(t *testing.T) { pkg := NewPackage([]*Type{ MakeStructType("S", []Field{ - Field{"x", Int32Type, false}, + Field{"x", NumberType, false}, }, []Field{})}, []ref.Ref{}) pkgRef := RegisterPackage(&pkg) typ := MakeListType(ValueType) v := NewTypedList(typ, Bool(true), - Int32Type, + NumberType, TypeType, MakeType(pkgRef, 0), ) @@ -390,7 +362,7 @@ func TestWriteListOfValueWithType(t *testing.T) { w.writeTopLevelValue(v) assert.EqualValues([]interface{}{ListKind, ValueKind, false, []interface{}{ BoolKind, true, - TypeKind, Int32Kind, + TypeKind, NumberKind, TypeKind, TypeKind, TypeKind, UnresolvedKind, pkgRef.String(), "0", }}, w.toArray()) @@ -399,13 +371,13 @@ func TestWriteListOfValueWithType(t *testing.T) { func TestWriteRef(t *testing.T) { assert := assert.New(t) - typ := MakeRefType(Uint32Type) + typ := MakeRefType(NumberType) r := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567") v := NewTypedRef(typ, r) w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(v) - assert.EqualValues([]interface{}{RefKind, Uint32Kind, r.String()}, w.toArray()) + assert.EqualValues([]interface{}{RefKind, NumberKind, r.String()}, w.toArray()) } func TestWriteTypeValue(t *testing.T) { @@ -417,21 +389,21 @@ func TestWriteTypeValue(t *testing.T) { assert.EqualValues(expected, w.toArray()) } - test([]interface{}{TypeKind, Int32Kind}, Int32Type) + test([]interface{}{TypeKind, NumberKind}, NumberType) test([]interface{}{TypeKind, ListKind, []interface{}{BoolKind}}, MakeListType(BoolType)) test([]interface{}{TypeKind, MapKind, []interface{}{BoolKind, StringKind}}, MakeMapType(BoolType, StringType)) - test([]interface{}{TypeKind, StructKind, "S", []interface{}{"x", Int16Kind, false, "v", ValueKind, true}, []interface{}{}}, + test([]interface{}{TypeKind, StructKind, "S", []interface{}{"x", NumberKind, false, "v", ValueKind, true}, []interface{}{}}, MakeStructType("S", []Field{ - Field{"x", Int16Type, false}, + Field{"x", NumberType, false}, Field{"v", ValueType, true}, }, []Field{})) - test([]interface{}{TypeKind, StructKind, "S", []interface{}{}, []interface{}{"x", Int16Kind, false, "v", ValueKind, false}}, + test([]interface{}{TypeKind, StructKind, "S", []interface{}{}, []interface{}{"x", NumberKind, false, "v", ValueKind, false}}, MakeStructType("S", []Field{}, []Field{ - Field{"x", Int16Type, false}, + Field{"x", NumberType, false}, Field{"v", ValueType, false}, })) @@ -439,10 +411,10 @@ func TestWriteTypeValue(t *testing.T) { test([]interface{}{TypeKind, UnresolvedKind, pkgRef.String(), "123"}, MakeType(pkgRef, 123)) - test([]interface{}{TypeKind, StructKind, "S", []interface{}{"e", UnresolvedKind, pkgRef.String(), "123", false, "x", Int64Kind, false}, []interface{}{}}, + test([]interface{}{TypeKind, StructKind, "S", []interface{}{"e", UnresolvedKind, pkgRef.String(), "123", false, "x", NumberKind, false}, []interface{}{}}, MakeStructType("S", []Field{ Field{"e", MakeType(pkgRef, 123), false}, - Field{"x", Int64Type, false}, + Field{"x", NumberType, false}, }, []Field{})) test([]interface{}{TypeKind, UnresolvedKind, ref.Ref{}.String(), "-1", "ns", "n"}, @@ -463,11 +435,11 @@ func TestWriteListOfTypes(t *testing.T) { func TestWritePackage(t *testing.T) { assert := assert.New(t) - setTref := MakeSetType(Uint32Type) + setTref := MakeSetType(NumberType) r := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567") v := Package{[]*Type{setTref}, []ref.Ref{r}, &ref.Ref{}} w := newJSONArrayWriter(NewTestValueStore()) w.writeTopLevelValue(v) - assert.EqualValues([]interface{}{PackageKind, []interface{}{SetKind, []interface{}{Uint32Kind}}, []interface{}{r.String()}}, w.toArray()) + assert.EqualValues([]interface{}{PackageKind, []interface{}{SetKind, []interface{}{NumberKind}}, []interface{}{r.String()}}, w.toArray()) } diff --git a/types/equals_test.go b/types/equals_test.go index e64f47f56b..8ef4343090 100644 --- a/types/equals_test.go +++ b/types/equals_test.go @@ -10,39 +10,16 @@ import ( func TestValueEquals(t *testing.T) { assert := assert.New(t) - r1 := Uint16(1).Ref() - r2 := Uint16(2).Ref() + r1 := Number(1).Ref() + r2 := Number(2).Ref() values := []func() Value{ func() Value { return nil }, func() Value { return Bool(false) }, func() Value { return Bool(true) }, - func() Value { return Int8(0) }, - func() Value { return Int8(1) }, - func() Value { return Int8(-1) }, - func() Value { return Int16(0) }, - func() Value { return Int16(1) }, - func() Value { return Int16(-1) }, - func() Value { return Int32(0) }, - func() Value { return Int32(1) }, - func() Value { return Int32(-1) }, - func() Value { return Int64(0) }, - func() Value { return Int64(1) }, - func() Value { return Int64(-1) }, - func() Value { return Uint8(0) }, - func() Value { return Uint8(1) }, - func() Value { return Uint16(0) }, - func() Value { return Uint16(1) }, - func() Value { return Uint32(0) }, - func() Value { return Uint32(1) }, - func() Value { return Uint64(0) }, - func() Value { return Uint64(1) }, - func() Value { return Float32(0) }, - func() Value { return Float32(-1) }, - func() Value { return Float32(1) }, - func() Value { return Float64(0) }, - func() Value { return Float64(-1) }, - func() Value { return Float64(1) }, + func() Value { return Number(0) }, + func() Value { return Number(-1) }, + func() Value { return Number(1) }, func() Value { return NewString("") }, func() Value { return NewString("hi") }, func() Value { return NewString("bye") }, @@ -59,8 +36,8 @@ func TestValueEquals(t *testing.T) { b1 := NewBlob(bytes.NewBufferString("hi")) b2 := NewBlob(bytes.NewBufferString("bye")) return newCompoundBlob([]metaTuple{ - newMetaTuple(Uint64(uint64(2)), b1, Ref{}, 2), - newMetaTuple(Uint64(uint64(5)), b2, Ref{}, 5), + newMetaTuple(Number(uint64(2)), b1, Ref{}, 2), + newMetaTuple(Number(uint64(5)), b2, Ref{}, 5), }, nil) }, func() Value { return NewList() }, @@ -75,17 +52,17 @@ func TestValueEquals(t *testing.T) { func() Value { return StringType }, func() Value { return MakeStructType("a", []Field{}, []Field{}) }, func() Value { return MakeStructType("b", []Field{}, []Field{}) }, - func() Value { return MakeListType(Uint64Type) }, - func() Value { return MakeListType(Int64Type) }, - func() Value { return MakeSetType(Uint32Type) }, - func() Value { return MakeSetType(Int32Type) }, - func() Value { return MakeRefType(Uint16Type) }, - func() Value { return MakeRefType(Int16Type) }, + func() Value { return MakeListType(BoolType) }, + func() Value { return MakeListType(NumberType) }, + func() Value { return MakeSetType(BoolType) }, + func() Value { return MakeSetType(NumberType) }, + func() Value { return MakeRefType(BoolType) }, + func() Value { return MakeRefType(NumberType) }, func() Value { - return MakeMapType(Uint8Type, ValueType) + return MakeMapType(BoolType, ValueType) }, func() Value { - return MakeMapType(Int8Type, ValueType) + return MakeMapType(NumberType, ValueType) }, func() Value { return MakeType(r1, 0) }, func() Value { return MakeType(r1, 1) }, diff --git a/types/gen/header.tmpl b/types/gen/header.tmpl deleted file mode 100644 index 8733c99843..0000000000 --- a/types/gen/header.tmpl +++ /dev/null @@ -1,9 +0,0 @@ -// DO NOT EDIT: This file was generated. -// To regenerate, run `go generate` in this package. - -package types - -import ( - "github.com/attic-labs/noms/ref" -) - diff --git a/types/gen/main.go b/types/gen/main.go deleted file mode 100644 index 36c783ab90..0000000000 --- a/types/gen/main.go +++ /dev/null @@ -1,59 +0,0 @@ -package main - -import ( - "io/ioutil" - "log" - "os" - "path" - "runtime" - "strings" - "text/template" - - "sort" - - "github.com/attic-labs/noms/d" -) - -var ( - headerTempl = readTemplate("header.tmpl") - primitiveTempl = readTemplate("primitive.tmpl") -) - -func main() { - types := map[string]bool{"Bool": false, "Int8": true, "Int16": true, "Int32": true, "Int64": true, "Uint8": true, "Uint16": true, "Uint32": true, "Uint64": true, "Float32": true, "Float64": true} - typeNames := []string{} - for k := range types { - typeNames = append(typeNames, k) - } - sort.Strings(typeNames) - - f, err := os.OpenFile("primitives.go", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) - if err != nil { - log.Fatal(err) - return - } - - headerTempl.Execute(f, nil) - - for _, t := range typeNames { - ordered := types[t] - goType := strings.ToLower(t) - primitiveTempl.Execute(f, struct { - NomsType string - GoType string - IsOrdered bool - }{t, goType, ordered}) - } -} - -func readTemplate(name string) *template.Template { - _, thisfile, _, _ := runtime.Caller(1) - f, err := os.Open(path.Join(path.Dir(thisfile), name)) - d.Chk.NoError(err) - defer f.Close() - b, err := ioutil.ReadAll(f) - d.Chk.NoError(err) - t, err := template.New(name).Parse(string(b)) - d.Chk.NoError(err) - return t -} diff --git a/types/gen/primitive.tmpl b/types/gen/primitive.tmpl deleted file mode 100644 index 3090735ba9..0000000000 --- a/types/gen/primitive.tmpl +++ /dev/null @@ -1,32 +0,0 @@ -type {{.NomsType}} {{.GoType}} - -func (p {{.NomsType}}) Equals(other Value) bool { - return p == other -} - -func (v {{.NomsType}}) Ref() ref.Ref { - return getRef(v) -} - -func (v {{.NomsType}}) Chunks() []RefBase { - return nil -} - -func (v {{.NomsType}}) ChildValues() []Value { - return nil -} - -func (v {{.NomsType}}) ToPrimitive() interface{} { - return {{.GoType}}(v) -} - -var typeFor{{.NomsType}} = MakePrimitiveType({{.NomsType}}Kind) - -func (v {{.NomsType}}) Type() *Type { - return typeFor{{.NomsType}} -} -{{if .IsOrdered}} -func (v {{.NomsType}}) Less(other OrderedValue) bool { - return v < other.({{.NomsType}}) -} -{{end}} diff --git a/types/get_ref_test.go b/types/get_ref_test.go index 41b8803bdc..8d39797adb 100644 --- a/types/get_ref_test.go +++ b/types/get_ref_test.go @@ -43,10 +43,10 @@ func TestEnsureRef(t *testing.T) { }() bl := newBlobLeaf([]byte("hi")) - cb := newCompoundBlob([]metaTuple{{bl, Ref{}, Uint64(2), 2}}, vs) + cb := newCompoundBlob([]metaTuple{{bl, Ref{}, Number(2), 2}}, vs) ll := newListLeaf(listType, NewString("foo")) - cl := buildCompoundList([]metaTuple{{ll, Ref{}, Uint64(1), 1}}, listType, vs) + cl := buildCompoundList([]metaTuple{{ll, Ref{}, Number(1), 1}}, listType, vs) ml := newMapLeaf(mapType, mapEntry{NewString("foo"), NewString("bar")}) cm := buildCompoundMap([]metaTuple{{ml, Ref{}, NewString("foo"), 1}}, mapType, vs) @@ -75,16 +75,7 @@ func TestEnsureRef(t *testing.T) { count = byte(1) values = []Value{ Bool(false), - Int8(0), - Int16(0), - Int32(0), - Int64(0), - Uint8(0), - Uint16(0), - Uint32(0), - Uint64(0), - Float32(0), - Float64(0), + Number(0), } for i := 0; i < 2; i++ { for j, v := range values { diff --git a/types/incremental_test.go b/types/incremental_test.go index 0180ae7b71..29dbec4e3a 100644 --- a/types/incremental_test.go +++ b/types/incremental_test.go @@ -10,16 +10,7 @@ import ( var ( testVals = []Value{ Bool(true), - Int8(1), - Int16(1), - Int32(1), - Int64(1), - Uint8(1), - Uint16(1), - Uint32(1), - Uint64(1), - Float32(1), - Float64(1), + Number(1), NewString("hi"), newBlobLeaf([]byte("hi")), // compoundBlob @@ -111,7 +102,7 @@ func SkipTestIncrementalAddRef(t *testing.T) { cs := chunks.NewTestStore() vs := newLocalValueStore(cs) - expectedItem := Uint32(42) + expectedItem := Number(42) ref := vs.WriteValue(expectedItem).TargetRef() expected := NewList(NewRef(ref)) diff --git a/types/indexed_sequences.go b/types/indexed_sequences.go index 50bf498198..7a623d8722 100644 --- a/types/indexed_sequences.go +++ b/types/indexed_sequences.go @@ -25,8 +25,8 @@ func newIndexedMetaSequenceChunkFn(t *Type, source ValueReader, sink ValueWriter meta := newMetaSequenceFromData(tuples, t, source) if sink != nil { r := sink.WriteValue(meta) - return newMetaTuple(Uint64(tuples.uint64ValuesSum()), nil, r, numLeaves), meta + return newMetaTuple(Number(tuples.uint64ValuesSum()), nil, r, numLeaves), meta } - return newMetaTuple(Uint64(tuples.uint64ValuesSum()), meta, Ref{}, numLeaves), meta + return newMetaTuple(Number(tuples.uint64ValuesSum()), meta, Ref{}, numLeaves), meta } } diff --git a/types/list_test.go b/types/list_test.go index facf6bf7a5..3467af388b 100644 --- a/types/list_test.go +++ b/types/list_test.go @@ -34,10 +34,10 @@ func TestListGet(t *testing.T) { assert := assert.New(t) l := NewList() - l = l.Append(Int32(0), Int32(1), Int32(2)) - assert.Equal(Int32(0), l.Get(0)) - assert.Equal(Int32(1), l.Get(1)) - assert.Equal(Int32(2), l.Get(2)) + l = l.Append(Number(0), Number(1), Number(2)) + assert.Equal(Number(0), l.Get(0)) + assert.Equal(Number(1), l.Get(1)) + assert.Equal(Number(2), l.Get(2)) assert.Panics(func() { l.Get(3) @@ -48,12 +48,12 @@ func TestListSlice(t *testing.T) { assert := assert.New(t) l1 := NewList() - l1 = l1.Append(Int32(0), Int32(1), Int32(2), Int32(3)) + l1 = l1.Append(Number(0), Number(1), Number(2), Number(3)) l2 := l1.Slice(1, 3) assert.Equal(uint64(4), l1.Len()) assert.Equal(uint64(2), l2.Len()) - assert.Equal(Int32(1), l2.Get(0)) - assert.Equal(Int32(2), l2.Get(1)) + assert.Equal(Number(1), l2.Get(0)) + assert.Equal(Number(2), l2.Get(1)) l3 := l1.Slice(0, 0) assert.Equal(uint64(0), l3.Len()) @@ -61,7 +61,7 @@ func TestListSlice(t *testing.T) { assert.Equal(uint64(0), l3.Len()) l3 = l1.Slice(1, 2) assert.Equal(uint64(1), l3.Len()) - assert.Equal(Int32(1), l3.Get(0)) + assert.Equal(Number(1), l3.Get(0)) l3 = l1.Slice(0, l1.Len()) assert.True(l1.Equals(l3)) @@ -77,12 +77,12 @@ func TestListSet(t *testing.T) { assert := assert.New(t) l0 := NewList() - l0 = l0.Append(Float32(0.0)) - l1 := l0.Set(uint64(0), Float32(1.0)) - assert.Equal(Float32(1.0), l1.Get(0)) - assert.Equal(Float32(0.0), l0.Get(0)) + l0 = l0.Append(Number(0.0)) + l1 := l0.Set(uint64(0), Number(1.0)) + assert.Equal(Number(1.0), l1.Get(0)) + assert.Equal(Number(0.0), l0.Get(0)) assert.Panics(func() { - l1.Set(uint64(2), Float32(2.0)) + l1.Set(uint64(2), Number(2.0)) }) } @@ -108,24 +108,24 @@ func TestListInsert(t *testing.T) { // Insert(0, v1) l0 := NewList() - l1 := l0.Insert(uint64(0), Int32(-1)) + l1 := l0.Insert(uint64(0), Number(-1)) assert.Equal(uint64(0), l0.Len()) assert.Equal(uint64(1), l1.Len()) - assert.Equal(Int32(-1), l1.Get(0)) + assert.Equal(Number(-1), l1.Get(0)) // Insert(0, v1, v2) - l2 := l1.Insert(0, Int32(-3), Int32(-2)) + l2 := l1.Insert(0, Number(-3), Number(-2)) assert.Equal(uint64(3), l2.Len()) - assert.Equal(Int32(-1), l2.Get(2)) - assert.True(NewList(Int32(-3), Int32(-2)).Equals(l2.Slice(0, 2))) + assert.Equal(Number(-1), l2.Get(2)) + assert.True(NewList(Number(-3), Number(-2)).Equals(l2.Slice(0, 2))) assert.Equal(uint64(1), l1.Len()) // Insert(2, v3) - l3 := l2.Insert(2, Int32(1)) - assert.Equal(Int32(1), l3.Get(2)) + l3 := l2.Insert(2, Number(1)) + assert.Equal(Number(1), l3.Get(2)) assert.Panics(func() { - l2.Insert(5, Int32(0)) + l2.Insert(5, Number(0)) }) } @@ -174,7 +174,7 @@ func TestListMap(t *testing.T) { testMap := func(concurrency, listLen int) { values := make([]Value, listLen) for i := 0; i < listLen; i++ { - values[i] = Int64(i) + values[i] = Number(i) } l := newListLeaf(listType, values...) @@ -201,7 +201,7 @@ func TestListMap(t *testing.T) { for getCur() < expectConcurreny { } - i := v.(Int64) + i := v.(Number) assert.Equal(uint64(i), index, "%d == %d", i, index) return int64(i * i) } @@ -229,16 +229,16 @@ func TestListMap(t *testing.T) { func TestListIter(t *testing.T) { assert := assert.New(t) - l := NewList(Int32(0), Int32(1), Int32(2), Int32(3), Int32(4)) - acc := []int32{} + l := NewList(Number(0), Number(1), Number(2), Number(3), Number(4)) + acc := []Number{} i := uint64(0) l.Iter(func(v Value, index uint64) bool { assert.Equal(i, index) i++ - acc = append(acc, int32(v.(Int32))) + acc = append(acc, Number(v.(Number))) return i > 2 }) - assert.Equal([]int32{0, 1, 2}, acc) + assert.Equal([]Number{0, 1, 2}, acc) cl := NewList(NewString("a"), NewString("b"), NewString("c"), NewString("d"), NewString("e"), NewString("f")) acc2 := []string{} @@ -263,15 +263,15 @@ func TestListIter(t *testing.T) { func TestListIterAll(t *testing.T) { assert := assert.New(t) - l := NewList(Int32(0), Int32(1), Int32(2), Int32(3), Int32(4)) - acc := []int32{} + l := NewList(Number(0), Number(1), Number(2), Number(3), Number(4)) + acc := []Number{} i := uint64(0) l.IterAll(func(v Value, index uint64) { assert.Equal(i, index) i++ - acc = append(acc, int32(v.(Int32))) + acc = append(acc, Number(v.(Number))) }) - assert.Equal([]int32{0, 1, 2, 3, 4}, acc) + assert.Equal([]Number{0, 1, 2, 3, 4}, acc) cl := NewList(NewString("a"), NewString("b"), NewString("c"), NewString("d"), NewString("e"), NewString("f")) acc2 := []string{} @@ -287,7 +287,7 @@ func TestListIterAllP(t *testing.T) { testIter := func(concurrency, listLen int) { values := make([]Value, listLen) for i := 0; i < listLen; i++ { - values[i] = Int64(i) + values[i] = Number(i) } l := newListLeaf(listType, values...) @@ -313,7 +313,7 @@ func TestListIterAllP(t *testing.T) { for getCur() < expectConcurreny { } - i := v.(Int64) + i := v.(Number) visited[index] = true assert.Equal(uint64(i), index, "%d == %d", i, index) } @@ -340,11 +340,11 @@ func TestListIterAllP(t *testing.T) { func TestListType(t *testing.T) { assert := assert.New(t) - l := NewList(Int32(0)) + l := NewList(Number(0)) assert.True(l.Type().Equals(MakeListType(ValueType))) - tr := MakeListType(Uint8Type) - l2 := newListLeaf(tr, []Value{Uint8(0), Uint8(1)}...) + tr := MakeListType(NumberType) + l2 := newListLeaf(tr, []Value{Number(0), Number(1)}...) assert.Equal(tr, l2.Type()) l3 := l2.Slice(0, 1) @@ -354,11 +354,11 @@ func TestListType(t *testing.T) { l3 = l2.RemoveAt(0) assert.True(tr.Equals(l3.Type())) - l3 = l2.Set(0, Uint8(11)) + l3 = l2.Set(0, Number(11)) assert.True(tr.Equals(l3.Type())) - l3 = l2.Append(Uint8(2)) + l3 = l2.Append(Number(2)) assert.True(tr.Equals(l3.Type())) - l3 = l2.Insert(0, Uint8(3)) + l3 = l2.Insert(0, Number(3)) assert.True(tr.Equals(l3.Type())) assert.Panics(func() { l2.Set(0, NewString("")) }) @@ -369,11 +369,11 @@ func TestListType(t *testing.T) { func TestListChunks(t *testing.T) { assert := assert.New(t) - l1 := NewList(Int32(0)) + l1 := NewList(Number(0)) c1 := l1.Chunks() assert.Len(c1, 0) - ool := NewRef(Int32(0).Ref()) + ool := NewRef(Number(0).Ref()) l2 := NewList(ool) c2 := l2.Chunks() assert.Len(c2, 1) diff --git a/types/map_test.go b/types/map_test.go index d0a2040a82..5571d6d7fb 100644 --- a/types/map_test.go +++ b/types/map_test.go @@ -58,17 +58,17 @@ func TestMapSetGet(t *testing.T) { assert := assert.New(t) m1 := newMapLeaf(mapType) assert.Nil(m1.Get(NewString("foo"))) - m2 := m1.Set(NewString("foo"), Int32(42)) + m2 := m1.Set(NewString("foo"), Number(42)) assert.Nil(m1.Get(NewString("foo"))) - assert.True(Int32(42).Equals(m2.Get(NewString("foo")))) - m3 := m2.Set(NewString("foo"), Int32(43)) + assert.True(Number(42).Equals(m2.Get(NewString("foo")))) + m3 := m2.Set(NewString("foo"), Number(43)) assert.Nil(m1.Get(NewString("foo"))) - assert.True(Int32(42).Equals(m2.Get(NewString("foo")))) - assert.True(Int32(43).Equals(m3.Get(NewString("foo")))) + assert.True(Number(42).Equals(m2.Get(NewString("foo")))) + assert.True(Number(43).Equals(m3.Get(NewString("foo")))) m4 := m3.Remove(NewString("foo")) assert.Nil(m1.Get(NewString("foo"))) - assert.True(Int32(42).Equals(m2.Get(NewString("foo")))) - assert.True(Int32(43).Equals(m3.Get(NewString("foo")))) + assert.True(Number(42).Equals(m2.Get(NewString("foo")))) + assert.True(Number(43).Equals(m3.Get(NewString("foo")))) assert.Nil(m4.Get(NewString("foo"))) } @@ -90,7 +90,7 @@ func TestMapSetM(t *testing.T) { // BUG 98 func TestMapDuplicateSet(t *testing.T) { assert := assert.New(t) - m1 := NewMap(Bool(true), Bool(true), Int32(42), Int32(42), Int32(42), Int32(42)) + m1 := NewMap(Bool(true), Bool(true), Number(42), Number(42), Number(42), Number(42)) assert.Equal(uint64(2), m1.Len()) } @@ -123,18 +123,18 @@ func TestMapIter(t *testing.T) { m.Iter(cb) assert.Equal(0, len(results)) - m = m.SetM(NewString("a"), Int32(0), NewString("b"), Int32(1)) + m = m.SetM(NewString("a"), Number(0), NewString("b"), Number(1)) m.Iter(cb) assert.Equal(2, len(results)) - assert.True(got(NewString("a"), Int32(0))) - assert.True(got(NewString("b"), Int32(1))) + assert.True(got(NewString("a"), Number(0))) + assert.True(got(NewString("b"), Number(1))) results = resultList{} stop = true m.Iter(cb) assert.Equal(1, len(results)) // Iteration order not guaranteed, but it has to be one of these. - assert.True(got(NewString("a"), Int32(0)) || got(NewString("b"), Int32(1))) + assert.True(got(NewString("a"), Number(0)) || got(NewString("b"), Number(1))) } func TestMapIterAllP(t *testing.T) { @@ -143,8 +143,8 @@ func TestMapIterAllP(t *testing.T) { testIter := func(concurrency, mapLen int) { values := make([]Value, 2*mapLen) for i := 0; i < mapLen; i++ { - values[2*i] = Uint64(i) - values[2*i+1] = Uint64(i) + values[2*i] = Number(i) + values[2*i+1] = Number(i) } m := newMapLeaf(mapType, buildMapData(mapData{}, values, mapType)...) @@ -170,7 +170,7 @@ func TestMapIterAllP(t *testing.T) { for getCur() < expectConcurreny { } - visited[v.(Uint64)] = true + visited[uint64(v.(Number))] = true } if concurrency == 1 { @@ -195,11 +195,11 @@ func TestMapIterAllP(t *testing.T) { func TestMapFilter(t *testing.T) { assert := assert.New(t) - m := NewMap(Int8(0), NewString("a"), Int8(1), NewString("b"), Int8(2), NewString("c")) + m := NewMap(Number(0), NewString("a"), Number(1), NewString("b"), Number(2), NewString("c")) m2 := m.Filter(func(k, v Value) bool { - return k.Equals(Int8(0)) || v.Equals(NewString("c")) + return k.Equals(Number(0)) || v.Equals(NewString("c")) }) - assert.True(NewMap(Int8(0), NewString("a"), Int8(2), NewString("c")).Equals(m2)) + assert.True(NewMap(Number(0), NewString("a"), Number(2), NewString("c")).Equals(m2)) } func TestMapEquals(t *testing.T) { @@ -214,8 +214,8 @@ func TestMapEquals(t *testing.T) { assert.True(m3.Equals(m2)) assert.True(m2.Equals(m3)) - m1 = NewMap(NewString("foo"), Float32(0.0), NewString("bar"), NewList()) - m2 = m2.SetM(NewString("foo"), Float32(0.0), NewString("bar"), NewList()) + m1 = NewMap(NewString("foo"), Number(0.0), NewString("bar"), NewList()) + m2 = m2.SetM(NewString("foo"), Number(0.0), NewString("bar"), NewList()) assert.True(m1.Equals(m2)) assert.True(m2.Equals(m1)) assert.False(m2.Equals(m3)) @@ -230,10 +230,8 @@ func TestMapNotStringKeys(t *testing.T) { l := []Value{ Bool(true), NewString("true"), Bool(false), NewString("false"), - Int32(1), NewString("int32: 1"), - Int32(0), NewString("int32: 0"), - Float64(1), NewString("float64: 1"), - Float64(0), NewString("float64: 0"), + Number(1), NewString("Number: 1"), + Number(0), NewString("Number: 0"), b1, NewString("blob1"), b2, NewString("blob2"), NewList(), NewString("empty list"), @@ -244,11 +242,11 @@ func TestMapNotStringKeys(t *testing.T) { NewSet(NewSet()), NewString("map of set/set"), } m1 := NewMap(l...) - assert.Equal(uint64(14), m1.Len()) + assert.Equal(uint64(12), m1.Len()) for i := 0; i < len(l); i += 2 { assert.True(m1.Get(l[i]).Equals(l[i+1])) } - assert.Nil(m1.Get(Int32(42))) + assert.Nil(m1.Get(Number(42))) } func testMapOrder(assert *assert.Assertions, keyType, valueType *Type, tuples []Value, expectOrdering []Value) { @@ -285,62 +283,62 @@ func TestMapOrdering(t *testing.T) { ) testMapOrder(assert, - Uint64Type, StringType, + NumberType, StringType, []Value{ - Uint64(0), NewString("unused"), - Uint64(1000), NewString("unused"), - Uint64(1), NewString("unused"), - Uint64(100), NewString("unused"), - Uint64(2), NewString("unused"), - Uint64(10), NewString("unused"), + Number(0), NewString("unused"), + Number(1000), NewString("unused"), + Number(1), NewString("unused"), + Number(100), NewString("unused"), + Number(2), NewString("unused"), + Number(10), NewString("unused"), }, []Value{ - Uint64(0), - Uint64(1), - Uint64(2), - Uint64(10), - Uint64(100), - Uint64(1000), + Number(0), + Number(1), + Number(2), + Number(10), + Number(100), + Number(1000), }, ) testMapOrder(assert, - Int16Type, StringType, + NumberType, StringType, []Value{ - Int16(0), NewString("unused"), - Int16(-30), NewString("unused"), - Int16(25), NewString("unused"), - Int16(1002), NewString("unused"), - Int16(-5050), NewString("unused"), - Int16(23), NewString("unused"), + Number(0), NewString("unused"), + Number(-30), NewString("unused"), + Number(25), NewString("unused"), + Number(1002), NewString("unused"), + Number(-5050), NewString("unused"), + Number(23), NewString("unused"), }, []Value{ - Int16(-5050), - Int16(-30), - Int16(0), - Int16(23), - Int16(25), - Int16(1002), + Number(-5050), + Number(-30), + Number(0), + Number(23), + Number(25), + Number(1002), }, ) testMapOrder(assert, - Float32Type, StringType, + NumberType, StringType, []Value{ - Float32(0.0001), NewString("unused"), - Float32(0.000001), NewString("unused"), - Float32(1), NewString("unused"), - Float32(25.01e3), NewString("unused"), - Float32(-32.231123e5), NewString("unused"), - Float32(23), NewString("unused"), + Number(0.0001), NewString("unused"), + Number(0.000001), NewString("unused"), + Number(1), NewString("unused"), + Number(25.01e3), NewString("unused"), + Number(-32.231123e5), NewString("unused"), + Number(23), NewString("unused"), }, []Value{ - Float32(-32.231123e5), - Float32(0.000001), - Float32(0.0001), - Float32(1), - Float32(23), - Float32(25.01e3), + Number(-32.231123e5), + Number(0.000001), + Number(0.0001), + Number(1), + Number(23), + Number(25.01e3), }, ) @@ -396,7 +394,7 @@ func TestMapType(t *testing.T) { m := newMapLeaf(mapType) assert.True(m.Type().Equals(MakeMapType(ValueType, ValueType))) - tr := MakeMapType(StringType, Uint64Type) + tr := MakeMapType(StringType, NumberType) m = newMapLeaf(tr) assert.Equal(tr, m.Type()) @@ -408,30 +406,30 @@ func TestMapType(t *testing.T) { }) assert.True(tr.Equals(m2.Type())) - m2 = m.Set(NewString("A"), Uint64(1)) + m2 = m.Set(NewString("A"), Number(1)) assert.True(tr.Equals(m2.Type())) - m2 = m.SetM(NewString("B"), Uint64(2), NewString("C"), Uint64(2)) + m2 = m.SetM(NewString("B"), Number(2), NewString("C"), Number(2)) assert.True(tr.Equals(m2.Type())) - assert.Panics(func() { m.Set(NewString("A"), Uint8(1)) }) - assert.Panics(func() { m.Set(Bool(true), Uint64(1)) }) - assert.Panics(func() { m.SetM(NewString("B"), Uint64(2), NewString("A"), Uint8(1)) }) - assert.Panics(func() { m.SetM(NewString("B"), Uint64(2), Bool(true), Uint64(1)) }) + assert.Panics(func() { m.Set(NewString("A"), Bool(true)) }) + assert.Panics(func() { m.Set(Bool(true), Number(1)) }) + assert.Panics(func() { m.SetM(NewString("B"), Bool(false), NewString("A"), Bool(true)) }) + assert.Panics(func() { m.SetM(NewString("B"), Number(2), Bool(true), Number(1)) }) } func TestMapChunks(t *testing.T) { assert := assert.New(t) - l1 := NewMap(Int32(0), Int32(1)) + l1 := NewMap(Number(0), Number(1)) c1 := l1.Chunks() assert.Len(c1, 0) - l2 := NewMap(NewRef(Int32(0).Ref()), Int32(1)) + l2 := NewMap(NewRef(Number(0).Ref()), Number(1)) c2 := l2.Chunks() assert.Len(c2, 1) - l3 := NewMap(Int32(0), NewRef(Int32(1).Ref())) + l3 := NewMap(Number(0), NewRef(Number(1).Ref())) c3 := l3.Chunks() assert.Len(c3, 1) } diff --git a/types/meta_sequence.go b/types/meta_sequence.go index d340a9d7a9..754a33c9b3 100644 --- a/types/meta_sequence.go +++ b/types/meta_sequence.go @@ -39,7 +39,7 @@ func (mt metaTuple) ChildRef() Ref { } func (mt metaTuple) uint64Value() uint64 { - return uint64(mt.value.(Uint64)) + return uint64(mt.value.(Number)) } type metaSequenceData []metaTuple diff --git a/types/meta_sequence_cursor_test.go b/types/meta_sequence_cursor_test.go index 2026633f3b..65e9289952 100644 --- a/types/meta_sequence_cursor_test.go +++ b/types/meta_sequence_cursor_test.go @@ -12,7 +12,7 @@ func TestMeta(t *testing.T) { vs := NewTestValueStore() - flatList := []Value{Uint32(0), Uint32(1), Uint32(2), Uint32(3), Uint32(4), Uint32(5), Uint32(6), Uint32(7)} + flatList := []Value{Number(0), Number(1), Number(2), Number(3), Number(4), Number(5), Number(6), Number(7)} l0 := NewList(flatList[0]) lr0 := vs.WriteValue(l0) l1 := NewList(flatList[1]) @@ -32,21 +32,21 @@ func TestMeta(t *testing.T) { mtr := l0.Type() - m0 := compoundList{metaSequenceObject{metaSequenceData{{l0, lr0, Uint64(1), 1}, {l1, lr1, Uint64(2), 2}}, mtr}, 0, &ref.Ref{}, vs} + m0 := compoundList{metaSequenceObject{metaSequenceData{{l0, lr0, Number(1), 1}, {l1, lr1, Number(2), 2}}, mtr}, 0, &ref.Ref{}, vs} lm0 := vs.WriteValue(m0) - m1 := compoundList{metaSequenceObject{metaSequenceData{{l2, lr2, Uint64(1), 1}, {l3, lr3, Uint64(2), 2}}, mtr}, 0, &ref.Ref{}, vs} + m1 := compoundList{metaSequenceObject{metaSequenceData{{l2, lr2, Number(1), 1}, {l3, lr3, Number(2), 2}}, mtr}, 0, &ref.Ref{}, vs} lm1 := vs.WriteValue(m1) - m2 := compoundList{metaSequenceObject{metaSequenceData{{l4, lr4, Uint64(1), 1}, {l5, lr5, Uint64(2), 2}}, mtr}, 0, &ref.Ref{}, vs} + m2 := compoundList{metaSequenceObject{metaSequenceData{{l4, lr4, Number(1), 1}, {l5, lr5, Number(2), 2}}, mtr}, 0, &ref.Ref{}, vs} lm2 := vs.WriteValue(m2) - m3 := compoundList{metaSequenceObject{metaSequenceData{{l6, lr6, Uint64(1), 1}, {l7, lr7, Uint64(2), 2}}, mtr}, 0, &ref.Ref{}, vs} + m3 := compoundList{metaSequenceObject{metaSequenceData{{l6, lr6, Number(1), 1}, {l7, lr7, Number(2), 2}}, mtr}, 0, &ref.Ref{}, vs} lm3 := vs.WriteValue(m3) - m00 := compoundList{metaSequenceObject{metaSequenceData{{m0, lm0, Uint64(2), 2}, {m1, lm1, Uint64(4), 4}}, mtr}, 0, &ref.Ref{}, vs} + m00 := compoundList{metaSequenceObject{metaSequenceData{{m0, lm0, Number(2), 2}, {m1, lm1, Number(4), 4}}, mtr}, 0, &ref.Ref{}, vs} lm00 := vs.WriteValue(m00) - m01 := compoundList{metaSequenceObject{metaSequenceData{{m2, lm2, Uint64(2), 2}, {m3, lm3, Uint64(4), 4}}, mtr}, 0, &ref.Ref{}, vs} + m01 := compoundList{metaSequenceObject{metaSequenceData{{m2, lm2, Number(2), 2}, {m3, lm3, Number(4), 4}}, mtr}, 0, &ref.Ref{}, vs} lm01 := vs.WriteValue(m01) - rootList := compoundList{metaSequenceObject{metaSequenceData{{m00, lm00, Uint64(4), 4}, {m01, lm01, Uint64(8), 8}}, mtr}, 0, &ref.Ref{}, vs} + rootList := compoundList{metaSequenceObject{metaSequenceData{{m00, lm00, Number(4), 4}, {m01, lm01, Number(8), 8}}, mtr}, 0, &ref.Ref{}, vs} rootRef := vs.WriteValue(rootList).TargetRef() rootList = vs.ReadValue(rootRef).(compoundList) diff --git a/types/noms_kind.go b/types/noms_kind.go index 3a79bf6172..3b3541f489 100644 --- a/types/noms_kind.go +++ b/types/noms_kind.go @@ -6,16 +6,7 @@ type NomsKind uint8 // All supported kinds of Noms types are enumerated here. const ( BoolKind NomsKind = iota - Uint8Kind - Uint16Kind - Uint32Kind - Uint64Kind - Int8Kind - Int16Kind - Int32Kind - Int64Kind - Float32Kind - Float64Kind + NumberKind StringKind BlobKind ValueKind @@ -32,7 +23,7 @@ const ( // IsPrimitiveKind returns true if k represents a Noms primitive type, which excludes collections (List, Map, Set), Refs, Structs, Symbolic and Unresolved types. func IsPrimitiveKind(k NomsKind) bool { switch k { - case BoolKind, Int8Kind, Int16Kind, Int32Kind, Int64Kind, Float32Kind, Float64Kind, Uint8Kind, Uint16Kind, Uint32Kind, Uint64Kind, StringKind, BlobKind, ValueKind, TypeKind, PackageKind: + case BoolKind, NumberKind, StringKind, BlobKind, ValueKind, TypeKind, PackageKind: return true default: return false diff --git a/types/primitives.go b/types/primitives.go index dfa882631a..464b879563 100644 --- a/types/primitives.go +++ b/types/primitives.go @@ -1,6 +1,3 @@ -// DO NOT EDIT: This file was generated. -// To regenerate, run `go generate` in this package. - package types import ( @@ -35,323 +32,34 @@ func (v Bool) Type() *Type { return typeForBool } -type Float32 float32 +type Number float64 -func (p Float32) Equals(other Value) bool { +func (p Number) Equals(other Value) bool { return p == other } -func (v Float32) Ref() ref.Ref { +func (v Number) Ref() ref.Ref { return getRef(v) } -func (v Float32) Chunks() []Ref { +func (v Number) Chunks() []Ref { return nil } -func (v Float32) ChildValues() []Value { +func (v Number) ChildValues() []Value { return nil } -func (v Float32) ToPrimitive() interface{} { - return float32(v) -} - -var typeForFloat32 = Float32Type - -func (v Float32) Type() *Type { - return typeForFloat32 -} - -func (v Float32) Less(other OrderedValue) bool { - return v < other.(Float32) -} - -type Float64 float64 - -func (p Float64) Equals(other Value) bool { - return p == other -} - -func (v Float64) Ref() ref.Ref { - return getRef(v) -} - -func (v Float64) Chunks() []Ref { - return nil -} - -func (v Float64) ChildValues() []Value { - return nil -} - -func (v Float64) ToPrimitive() interface{} { +func (v Number) ToPrimitive() interface{} { return float64(v) } -var typeForFloat64 = Float64Type +var typeForNumber = NumberType -func (v Float64) Type() *Type { - return typeForFloat64 +func (v Number) Type() *Type { + return typeForNumber } -func (v Float64) Less(other OrderedValue) bool { - return v < other.(Float64) +func (v Number) Less(other OrderedValue) bool { + return v < other.(Number) } - -type Int16 int16 - -func (p Int16) Equals(other Value) bool { - return p == other -} - -func (v Int16) Ref() ref.Ref { - return getRef(v) -} - -func (v Int16) Chunks() []Ref { - return nil -} - -func (v Int16) ChildValues() []Value { - return nil -} - -func (v Int16) ToPrimitive() interface{} { - return int16(v) -} - -var typeForInt16 = Int16Type - -func (v Int16) Type() *Type { - return typeForInt16 -} - -func (v Int16) Less(other OrderedValue) bool { - return v < other.(Int16) -} - -type Int32 int32 - -func (p Int32) Equals(other Value) bool { - return p == other -} - -func (v Int32) Ref() ref.Ref { - return getRef(v) -} - -func (v Int32) Chunks() []Ref { - return nil -} - -func (v Int32) ChildValues() []Value { - return nil -} - -func (v Int32) ToPrimitive() interface{} { - return int32(v) -} - -var typeForInt32 = Int32Type - -func (v Int32) Type() *Type { - return typeForInt32 -} - -func (v Int32) Less(other OrderedValue) bool { - return v < other.(Int32) -} - -type Int64 int64 - -func (p Int64) Equals(other Value) bool { - return p == other -} - -func (v Int64) Ref() ref.Ref { - return getRef(v) -} - -func (v Int64) Chunks() []Ref { - return nil -} - -func (v Int64) ChildValues() []Value { - return nil -} - -func (v Int64) ToPrimitive() interface{} { - return int64(v) -} - -var typeForInt64 = Int64Type - -func (v Int64) Type() *Type { - return typeForInt64 -} - -func (v Int64) Less(other OrderedValue) bool { - return v < other.(Int64) -} - -type Int8 int8 - -func (p Int8) Equals(other Value) bool { - return p == other -} - -func (v Int8) Ref() ref.Ref { - return getRef(v) -} - -func (v Int8) Chunks() []Ref { - return nil -} - -func (v Int8) ChildValues() []Value { - return nil -} - -func (v Int8) ToPrimitive() interface{} { - return int8(v) -} - -var typeForInt8 = Int8Type - -func (v Int8) Type() *Type { - return typeForInt8 -} - -func (v Int8) Less(other OrderedValue) bool { - return v < other.(Int8) -} - -type Uint16 uint16 - -func (p Uint16) Equals(other Value) bool { - return p == other -} - -func (v Uint16) Ref() ref.Ref { - return getRef(v) -} - -func (v Uint16) Chunks() []Ref { - return nil -} - -func (v Uint16) ChildValues() []Value { - return nil -} - -func (v Uint16) ToPrimitive() interface{} { - return uint16(v) -} - -var typeForUint16 = Uint16Type - -func (v Uint16) Type() *Type { - return typeForUint16 -} - -func (v Uint16) Less(other OrderedValue) bool { - return v < other.(Uint16) -} - -type Uint32 uint32 - -func (p Uint32) Equals(other Value) bool { - return p == other -} - -func (v Uint32) Ref() ref.Ref { - return getRef(v) -} - -func (v Uint32) Chunks() []Ref { - return nil -} - -func (v Uint32) ChildValues() []Value { - return nil -} - -func (v Uint32) ToPrimitive() interface{} { - return uint32(v) -} - -var typeForUint32 = Uint32Type - -func (v Uint32) Type() *Type { - return typeForUint32 -} - -func (v Uint32) Less(other OrderedValue) bool { - return v < other.(Uint32) -} - -type Uint64 uint64 - -func (p Uint64) Equals(other Value) bool { - return p == other -} - -func (v Uint64) Ref() ref.Ref { - return getRef(v) -} - -func (v Uint64) Chunks() []Ref { - return nil -} - -func (v Uint64) ChildValues() []Value { - return nil -} - -func (v Uint64) ToPrimitive() interface{} { - return uint64(v) -} - -var typeForUint64 = Uint64Type - -func (v Uint64) Type() *Type { - return typeForUint64 -} - -func (v Uint64) Less(other OrderedValue) bool { - return v < other.(Uint64) -} - -type Uint8 uint8 - -func (p Uint8) Equals(other Value) bool { - return p == other -} - -func (v Uint8) Ref() ref.Ref { - return getRef(v) -} - -func (v Uint8) Chunks() []Ref { - return nil -} - -func (v Uint8) ChildValues() []Value { - return nil -} - -func (v Uint8) ToPrimitive() interface{} { - return uint8(v) -} - -var typeForUint8 = Uint8Type - -func (v Uint8) Type() *Type { - return typeForUint8 -} - -func (v Uint8) Less(other OrderedValue) bool { - return v < other.(Uint8) -} - diff --git a/types/primitives_test.go b/types/primitives_test.go index 82f12b9625..bb1b6a5c09 100644 --- a/types/primitives_test.go +++ b/types/primitives_test.go @@ -9,14 +9,8 @@ import ( func TestPrimitives(t *testing.T) { data := []Value{ Bool(true), Bool(false), - Int16(0), Int16(-1), - Int32(0), Int32(-1), - Int64(0), Int64(-1), - Uint16(0), Uint16(1), - Uint32(0), Uint32(1), - Uint64(0), Uint64(1), - Float32(0.0), Float32(0.1), - Float64(0.0), Float64(0.1), + Number(0), Number(-1), + Number(-0.1), Number(0.1), } for i := range data { @@ -36,16 +30,7 @@ func TestPrimitivesType(t *testing.T) { k NomsKind }{ {Bool(false), BoolKind}, - {Int8(0), Int8Kind}, - {Int16(0), Int16Kind}, - {Int32(0), Int32Kind}, - {Int64(0), Int64Kind}, - {Float32(0), Float32Kind}, - {Float64(0), Float64Kind}, - {Uint8(0), Uint8Kind}, - {Uint16(0), Uint16Kind}, - {Uint32(0), Uint32Kind}, - {Uint64(0), Uint64Kind}, + {Number(0), NumberKind}, } for _, d := range data { diff --git a/types/ref_test.go b/types/ref_test.go index a68085487e..35b1c5b54c 100644 --- a/types/ref_test.go +++ b/types/ref_test.go @@ -31,12 +31,12 @@ func TestRefInMap(t *testing.T) { m := NewMap() r := NewRef(m.Ref()) - m = m.Set(Int32(0), r).Set(r, Int32(1)) - r2 := m.Get(Int32(0)) + m = m.Set(Number(0), r).Set(r, Number(1)) + r2 := m.Get(Number(0)) assert.True(r.Equals(r2)) i := m.Get(r) - assert.Equal(int32(1), int32(i.(Int32))) + assert.Equal(int32(1), int32(i.(Number))) } func TestRefChunks(t *testing.T) { diff --git a/types/sequence_chunker_test.go b/types/sequence_chunker_test.go index 76704942c7..613ac8fcbf 100644 --- a/types/sequence_chunker_test.go +++ b/types/sequence_chunker_test.go @@ -21,7 +21,7 @@ func (b modBoundaryChecker) WindowSize() int { func listFromInts(ints []int) List { vals := make([]Value, len(ints)) for i, v := range ints { - vals[i] = Int64(v) + vals[i] = Number(v) } return NewList(vals...) diff --git a/types/set_test.go b/types/set_test.go index 3c187be85f..5cb693e26c 100644 --- a/types/set_test.go +++ b/types/set_test.go @@ -10,7 +10,7 @@ import ( func TestSetLen(t *testing.T) { assert := assert.New(t) - s1 := NewSet(Bool(true), Int32(1), NewString("hi")) + s1 := NewSet(Bool(true), Number(1), NewString("hi")) assert.Equal(uint64(3), s1.Len()) s2 := s1.Insert(Bool(false)) assert.Equal(uint64(4), s2.Len()) @@ -24,24 +24,24 @@ func TestSetEmpty(t *testing.T) { assert.True(s.Empty()) s = s.Insert(Bool(false)) assert.False(s.Empty()) - s = s.Insert(Int32(42)) + s = s.Insert(Number(42)) assert.False(s.Empty()) } // BUG 98 func TestSetDuplicateInsert(t *testing.T) { assert := assert.New(t) - s1 := NewSet(Bool(true), Int32(42), Int32(42)) + s1 := NewSet(Bool(true), Number(42), Number(42)) assert.Equal(uint64(2), s1.Len()) } func TestSetHas(t *testing.T) { assert := assert.New(t) - s1 := NewSet(Bool(true), Int32(1), NewString("hi")) + s1 := NewSet(Bool(true), Number(1), NewString("hi")) assert.True(s1.Has(Bool(true))) assert.False(s1.Has(Bool(false))) - assert.True(s1.Has(Int32(1))) - assert.False(s1.Has(Int32(0))) + assert.True(s1.Has(Number(1))) + assert.False(s1.Has(Number(0))) assert.True(s1.Has(NewString("hi"))) assert.False(s1.Has(NewString("ho"))) @@ -58,7 +58,7 @@ func TestSetInsert(t *testing.T) { s := NewSet() v1 := Bool(false) v2 := Bool(true) - v3 := Int32(0) + v3 := Number(0) assert.False(s.Has(v1)) s = s.Insert(v1) @@ -79,7 +79,7 @@ func TestSetRemove(t *testing.T) { assert := assert.New(t) v1 := Bool(false) v2 := Bool(true) - v3 := Int32(0) + v3 := Number(0) s := NewSet(v1, v2, v3) assert.True(s.Has(v1)) assert.True(s.Has(v2)) @@ -100,30 +100,30 @@ func TestSetRemove(t *testing.T) { func TestSetUnion(t *testing.T) { assert := assert.New(t) - assert.True(NewSet(Int32(1), Int32(2)).Union( - NewSet(Int32(2), Int32(3)), - NewSet(Int32(-1)), + assert.True(NewSet(Number(1), Number(2)).Union( + NewSet(Number(2), Number(3)), + NewSet(Number(-1)), NewSet()).Equals( - NewSet(Int32(1), Int32(2), Int32(3), Int32(-1)))) - assert.True(NewSet(Int32(1)).Union().Equals(NewSet(Int32(1)))) + NewSet(Number(1), Number(2), Number(3), Number(-1)))) + assert.True(NewSet(Number(1)).Union().Equals(NewSet(Number(1)))) } func TestSetFirst(t *testing.T) { assert := assert.New(t) s := NewSet() assert.Nil(s.First()) - s = s.Insert(Int32(1)) + s = s.Insert(Number(1)) assert.NotNil(s.First()) - s = s.Insert(Int32(2)) + s = s.Insert(Number(2)) assert.NotNil(s.First()) } func TestSetIter(t *testing.T) { assert := assert.New(t) - s := NewSet(Int32(0), Int32(1), Int32(2), Int32(3), Int32(4)) + s := NewSet(Number(0), Number(1), Number(2), Number(3), Number(4)) acc := NewSet() s.Iter(func(v Value) bool { - _, ok := v.(Int32) + _, ok := v.(Number) assert.True(ok) acc = acc.Insert(v) return false @@ -139,10 +139,10 @@ func TestSetIter(t *testing.T) { func TestSetIterAll(t *testing.T) { assert := assert.New(t) - s := NewSet(Int32(0), Int32(1), Int32(2), Int32(3), Int32(4)) + s := NewSet(Number(0), Number(1), Number(2), Number(3), Number(4)) acc := NewSet() s.IterAll(func(v Value) { - _, ok := v.(Int32) + _, ok := v.(Number) assert.True(ok) acc = acc.Insert(v) }) @@ -155,7 +155,7 @@ func TestSetIterAllP(t *testing.T) { testIter := func(concurrency, setLen int) { values := make([]Value, setLen) for i := 0; i < setLen; i++ { - values[i] = Uint64(i) + values[i] = Number(i) } s := newSetLeaf(setType, values...) @@ -181,7 +181,7 @@ func TestSetIterAllP(t *testing.T) { for getCur() < expectConcurreny { } - visited[v.(Uint64)] = true + visited[uint64(v.(Number))] = true } if concurrency == 1 { @@ -237,62 +237,62 @@ func TestSetOrdering(t *testing.T) { ) testSetOrder(assert, - Uint64Type, + NumberType, []Value{ - Uint64(0), - Uint64(1000), - Uint64(1), - Uint64(100), - Uint64(2), - Uint64(10), + Number(0), + Number(1000), + Number(1), + Number(100), + Number(2), + Number(10), }, []Value{ - Uint64(0), - Uint64(1), - Uint64(2), - Uint64(10), - Uint64(100), - Uint64(1000), + Number(0), + Number(1), + Number(2), + Number(10), + Number(100), + Number(1000), }, ) testSetOrder(assert, - Int16Type, + NumberType, []Value{ - Int16(0), - Int16(-30), - Int16(25), - Int16(1002), - Int16(-5050), - Int16(23), + Number(0), + Number(-30), + Number(25), + Number(1002), + Number(-5050), + Number(23), }, []Value{ - Int16(-5050), - Int16(-30), - Int16(0), - Int16(23), - Int16(25), - Int16(1002), + Number(-5050), + Number(-30), + Number(0), + Number(23), + Number(25), + Number(1002), }, ) testSetOrder(assert, - Float32Type, + NumberType, []Value{ - Float32(0.0001), - Float32(0.000001), - Float32(1), - Float32(25.01e3), - Float32(-32.231123e5), - Float32(23), + Number(0.0001), + Number(0.000001), + Number(1), + Number(25.01e3), + Number(-32.231123e5), + Number(23), }, []Value{ - Float32(-32.231123e5), - Float32(0.000001), - Float32(0.0001), - Float32(1), - Float32(23), - Float32(25.01e3), + Number(-32.231123e5), + Number(0.000001), + Number(0.0001), + Number(1), + Number(23), + Number(25.01e3), }, ) @@ -334,14 +334,14 @@ func TestSetOrdering(t *testing.T) { func TestSetFilter(t *testing.T) { assert := assert.New(t) - s := NewSet(Int32(0), Int32(1), Int32(2), Int32(3), Int32(4)) + s := NewSet(Number(0), Number(1), Number(2), Number(3), Number(4)) s2 := s.Filter(func(v Value) bool { - i, ok := v.(Int32) + i, ok := v.(Number) assert.True(ok) - return i%2 == 0 + return uint64(i)%2 == 0 }) - assert.True(NewSet(Int32(0), Int32(2), Int32(4)).Equals(s2)) + assert.True(NewSet(Number(0), Number(2), Number(4)).Equals(s2)) } func TestSetType(t *testing.T) { @@ -350,12 +350,12 @@ func TestSetType(t *testing.T) { s := newSetLeaf(setType) assert.True(s.Type().Equals(MakeSetType(ValueType))) - tr := MakeSetType(Uint64Type) + tr := MakeSetType(NumberType) s = newSetLeaf(tr) assert.Equal(tr, s.Type()) - s2 := s.Remove(Uint64(1)) + s2 := s.Remove(Number(1)) assert.True(tr.Equals(s2.Type())) s2 = s.Filter(func(v Value) bool { @@ -363,12 +363,12 @@ func TestSetType(t *testing.T) { }) assert.True(tr.Equals(s2.Type())) - s2 = s.Insert(Uint64(0), Uint64(1)) + s2 = s.Insert(Number(0), Number(1)) assert.True(tr.Equals(s2.Type())) assert.Panics(func() { s.Insert(Bool(true)) }) - assert.Panics(func() { s.Insert(Uint64(3), Bool(true)) }) - assert.Panics(func() { s.Union(NewSet(Uint64(2))) }) + assert.Panics(func() { s.Insert(Number(3), Bool(true)) }) + assert.Panics(func() { s.Union(NewSet(Number(2))) }) assert.Panics(func() { s.Union(NewSet(Bool(true))) }) assert.Panics(func() { s.Union(s, NewSet(Bool(true))) }) } @@ -376,11 +376,11 @@ func TestSetType(t *testing.T) { func TestSetChunks(t *testing.T) { assert := assert.New(t) - l1 := NewSet(Int32(0)) + l1 := NewSet(Number(0)) c1 := l1.Chunks() assert.Len(c1, 0) - l2 := NewSet(NewRef(Int32(0).Ref())) + l2 := NewSet(NewRef(Number(0).Ref())) c2 := l2.Chunks() assert.Len(c2, 1) } diff --git a/types/struct.go b/types/struct.go index 36e7cae490..cddca68651 100644 --- a/types/struct.go +++ b/types/struct.go @@ -191,7 +191,7 @@ func structBuilder(values []Value, typ, typeDef *Type) Value { } } if len(desc.Union) > 0 { - unionIndex = uint32(values[i].(Uint32)) + unionIndex = uint32(values[i].(Number)) i++ unionValue = values[i] i++ @@ -217,7 +217,7 @@ func structReader(s Struct, typ, typeDef *Type) []Value { } } if len(desc.Union) > 0 { - values = append(values, Uint32(s.unionIndex), s.unionValue) + values = append(values, Number(s.unionIndex), s.unionValue) } return values diff --git a/types/struct_test.go b/types/struct_test.go index 757af706c4..e1c918fcdc 100644 --- a/types/struct_test.go +++ b/types/struct_test.go @@ -158,8 +158,8 @@ func TestGenericStructSet(t *testing.T) { s := NewStruct(typ, typeDef, map[string]Value{"b": Bool(true)}) s2 := s.Set("b", Bool(false)) - assert.Panics(func() { s.Set("b", Int32(1)) }) - assert.Panics(func() { s.Set("x", Int32(1)) }) + assert.Panics(func() { s.Set("b", Number(1)) }) + assert.Panics(func() { s.Set("x", Number(1)) }) s3 := s2.Set("b", Bool(true)) assert.True(s.Equals(s3)) diff --git a/types/type.go b/types/type.go index fa4fcbbdb7..cbaa38fef8 100644 --- a/types/type.go +++ b/types/type.go @@ -62,7 +62,7 @@ func (t *Type) Kind() NomsKind { func (t *Type) IsOrdered() bool { switch t.Desc.Kind() { - case Float32Kind, Float64Kind, Int8Kind, Int16Kind, Int32Kind, Int64Kind, Uint8Kind, Uint16Kind, Uint32Kind, Uint64Kind, StringKind, RefKind: + case NumberKind, StringKind, RefKind: return true default: return false @@ -153,26 +153,8 @@ func MakePrimitiveType(k NomsKind) *Type { switch k { case BoolKind: return BoolType - case Int8Kind: - return Int8Type - case Int16Kind: - return Int16Type - case Int32Kind: - return Int32Type - case Int64Kind: - return Int64Type - case Float32Kind: - return Float32Type - case Float64Kind: - return Float64Type - case Uint8Kind: - return Uint8Type - case Uint16Kind: - return Uint16Type - case Uint32Kind: - return Uint32Type - case Uint64Kind: - return Uint64Type + case NumberKind: + return NumberType case StringKind: return StringType case BlobKind: @@ -196,26 +178,8 @@ func MakePrimitiveTypeByString(p string) *Type { switch p { case "Bool": return BoolType - case "Int8": - return Int8Type - case "Int16": - return Int16Type - case "Int32": - return Int32Type - case "Int64": - return Int64Type - case "Float32": - return Float32Type - case "Float64": - return Float64Type - case "Uint8": - return Uint8Type - case "Uint16": - return Uint16Type - case "Uint32": - return Uint32Type - case "Uint64": - return Uint64Type + case "Number": + return NumberType case "String": return StringType case "Blob": @@ -284,16 +248,7 @@ func buildType(n string, desc TypeDesc) *Type { } } -var Uint8Type = makePrimitiveType(Uint8Kind) -var Uint16Type = makePrimitiveType(Uint16Kind) -var Uint32Type = makePrimitiveType(Uint32Kind) -var Uint64Type = makePrimitiveType(Uint64Kind) -var Int8Type = makePrimitiveType(Int8Kind) -var Int16Type = makePrimitiveType(Int16Kind) -var Int32Type = makePrimitiveType(Int32Kind) -var Int64Type = makePrimitiveType(Int64Kind) -var Float32Type = makePrimitiveType(Float32Kind) -var Float64Type = makePrimitiveType(Float64Kind) +var NumberType = makePrimitiveType(NumberKind) var BoolType = makePrimitiveType(BoolKind) var StringType = makePrimitiveType(StringKind) var BlobType = makePrimitiveType(BlobKind) diff --git a/types/type_desc.go b/types/type_desc.go index e71c38c9d6..b9269da4fe 100644 --- a/types/type_desc.go +++ b/types/type_desc.go @@ -2,7 +2,7 @@ package types import "github.com/attic-labs/noms/ref" -// TypeDesc describes a type of the kind returned by Kind(), e.g. Map, Int32, or a custom type. +// TypeDesc describes a type of the kind returned by Kind(), e.g. Map, Number, or a custom type. type TypeDesc interface { Kind() NomsKind Equals(other TypeDesc) bool @@ -11,19 +11,10 @@ type TypeDesc interface { // PrimitiveDesc implements TypeDesc for all primitive Noms types: // Blob // Bool -// Float32 -// Float64 -// Int16 -// Int32 -// Int64 -// Int8 +// Number // Package // String // Type -// Uint16 -// Uint32 -// Uint64 -// Uint8 // Value type PrimitiveDesc NomsKind @@ -38,23 +29,14 @@ func (p PrimitiveDesc) Equals(other TypeDesc) bool { var KindToString = map[NomsKind]string{ BlobKind: "Blob", BoolKind: "Bool", - Float32Kind: "Float32", - Float64Kind: "Float64", - Int16Kind: "Int16", - Int32Kind: "Int32", - Int64Kind: "Int64", - Int8Kind: "Int8", ListKind: "List", MapKind: "Map", + NumberKind: "Number", PackageKind: "Package", RefKind: "Ref", SetKind: "Set", StringKind: "String", TypeKind: "Type", - Uint16Kind: "Uint16", - Uint32Kind: "Uint32", - Uint64Kind: "Uint64", - Uint8Kind: "Uint8", ValueKind: "Value", } diff --git a/types/type_test.go b/types/type_test.go index c4481c19d4..0a0e16ec09 100644 --- a/types/type_test.go +++ b/types/type_test.go @@ -12,9 +12,9 @@ func TestTypes(t *testing.T) { vs := NewTestValueStore() boolType := BoolType - uint8Type := Uint8Type + numberType := NumberType stringType := StringType - mapType := MakeMapType(stringType, uint8Type) + mapType := MakeMapType(stringType, numberType) setType := MakeSetType(stringType) mahType := MakeStructType("MahStruct", []Field{ Field{"Field1", stringType, false}, @@ -44,7 +44,7 @@ func TestTypeWithPkgRef(t *testing.T) { assert := assert.New(t) vs := NewTestValueStore() - pkg := NewPackage([]*Type{Float64Type}, []ref.Ref{}) + pkg := NewPackage([]*Type{NumberType}, []ref.Ref{}) pkgRef := RegisterPackage(&pkg) unresolvedType := MakeType(pkgRef, 42) @@ -62,15 +62,15 @@ func TestTypeType(t *testing.T) { func TestTypeRefDescribe(t *testing.T) { assert := assert.New(t) boolType := BoolType - uint8Type := Uint8Type + numberType := NumberType stringType := StringType - mapType := MakeMapType(stringType, uint8Type) + mapType := MakeMapType(stringType, numberType) setType := MakeSetType(stringType) assert.Equal("Bool", boolType.Describe()) - assert.Equal("Uint8", uint8Type.Describe()) + assert.Equal("Number", numberType.Describe()) assert.Equal("String", stringType.Describe()) - assert.Equal("Map", mapType.Describe()) + assert.Equal("Map", mapType.Describe()) assert.Equal("Set", setType.Describe()) mahType := MakeStructType("MahStruct", []Field{ @@ -83,26 +83,17 @@ func TestTypeRefDescribe(t *testing.T) { Field{"Field1", stringType, false}, Field{"Field2", boolType, true}, }, []Field{ - Field{"Uint8Field", uint8Type, false}, + Field{"NumberField", numberType, false}, Field{"StringField", stringType, false}, }) - assert.Equal("struct MahOtherStruct {\n Field1: String\n Field2: optional Bool\n union {\n Uint8Field: Uint8\n StringField: String\n }\n}", otherType.Describe()) + assert.Equal("struct MahOtherStruct {\n Field1: String\n Field2: optional Bool\n union {\n NumberField: Number\n StringField: String\n }\n}", otherType.Describe()) } func TestTypeOrdered(t *testing.T) { assert := assert.New(t) assert.False(BoolType.IsOrdered()) - assert.True(Uint8Type.IsOrdered()) - assert.True(Uint16Type.IsOrdered()) - assert.True(Uint32Type.IsOrdered()) - assert.True(Uint64Type.IsOrdered()) - assert.True(Int8Type.IsOrdered()) - assert.True(Int16Type.IsOrdered()) - assert.True(Int32Type.IsOrdered()) - assert.True(Int64Type.IsOrdered()) - assert.True(Float32Type.IsOrdered()) - assert.True(Float64Type.IsOrdered()) + assert.True(NumberType.IsOrdered()) assert.True(StringType.IsOrdered()) assert.False(BlobType.IsOrdered()) assert.False(ValueType.IsOrdered()) diff --git a/types/value_store_test.go b/types/value_store_test.go index 2bf038b1bc..cf7400f521 100644 --- a/types/value_store_test.go +++ b/types/value_store_test.go @@ -81,14 +81,14 @@ func TestWritePackageWhenValueIsWritten(t *testing.T) { vs := NewTestValueStore() typeDef := MakeStructType("S", []Field{ - Field{"X", Int32Type, false}, + Field{"X", NumberType, false}, }, []Field{}) pkg1 := NewPackage([]*Type{typeDef}, []ref.Ref{}) // Don't write package pkgRef1 := RegisterPackage(&pkg1) typ := MakeType(pkgRef1, 0) - s := NewStruct(typ, typeDef, structData{"X": Int32(42)}) + s := NewStruct(typ, typeDef, structData{"X": Number(42)}) vs.WriteValue(s) pkg2 := vs.ReadValue(pkgRef1) diff --git a/walk/walk_test.go b/walk/walk_test.go index e361bd76fb..278c58ec0e 100644 --- a/walk/walk_test.go +++ b/walk/walk_test.go @@ -35,17 +35,17 @@ func (suite *WalkAllTestSuite) storeAndRef(v types.Value) types.Ref { } func (suite *WalkAllTestSuite) TestWalkPrimitives() { - suite.walkWorker(suite.storeAndRef(types.Float64(0.0)), 2) + suite.walkWorker(suite.storeAndRef(types.Number(0.0)), 2) suite.walkWorker(suite.storeAndRef(types.NewString("hello")), 2) } func (suite *WalkAllTestSuite) TestWalkComposites() { suite.walkWorker(suite.storeAndRef(types.NewList()), 2) - suite.walkWorker(suite.storeAndRef(types.NewList(types.Bool(false), types.Int32(8))), 4) + suite.walkWorker(suite.storeAndRef(types.NewList(types.Bool(false), types.Number(8))), 4) suite.walkWorker(suite.storeAndRef(types.NewSet()), 2) - suite.walkWorker(suite.storeAndRef(types.NewSet(types.Bool(false), types.Int32(8))), 4) + suite.walkWorker(suite.storeAndRef(types.NewSet(types.Bool(false), types.Number(8))), 4) suite.walkWorker(suite.storeAndRef(types.NewMap()), 2) - suite.walkWorker(suite.storeAndRef(types.NewMap(types.Int32(8), types.Bool(true), types.Int32(0), types.Bool(false))), 6) + suite.walkWorker(suite.storeAndRef(types.NewMap(types.Number(8), types.Bool(true), types.Number(0), types.Bool(false))), 6) } func (suite *WalkAllTestSuite) NewList(cs chunks.ChunkStore, vs ...types.Value) types.Ref { @@ -65,7 +65,7 @@ func (suite *WalkAllTestSuite) NewSet(cs chunks.ChunkStore, vs ...types.Value) t func (suite *WalkAllTestSuite) TestWalkNestedComposites() { cs := chunks.NewMemoryStore() - suite.walkWorker(suite.storeAndRef(types.NewList(suite.NewSet(cs), types.Int32(8))), 5) + suite.walkWorker(suite.storeAndRef(types.NewList(suite.NewSet(cs), types.Number(8))), 5) suite.walkWorker(suite.storeAndRef(types.NewSet(suite.NewList(cs), suite.NewSet(cs))), 6) // {"string": "string", // "list": [false true], @@ -79,7 +79,7 @@ func (suite *WalkAllTestSuite) TestWalkNestedComposites() { types.NewString("list"), suite.NewList(cs, types.Bool(false), types.Bool(true)), types.NewString("map"), suite.NewMap(cs, types.NewString("nested"), types.NewString("string")), types.NewString("mtlist"), suite.NewList(cs), - types.NewString("set"), suite.NewSet(cs, types.Int32(5), types.Int32(7), types.Int32(8)), + types.NewString("set"), suite.NewSet(cs, types.Number(5), types.Number(7), types.Number(8)), suite.NewList(cs), types.NewString("wow"), // note that the dupe list chunk is skipped ) suite.walkWorker(suite.storeAndRef(nested), 25) @@ -97,7 +97,7 @@ func (suite *WalkTestSuite) SetupTest() { suite.vs = types.NewTestValueStore() suite.shouldSeeItem = types.NewString("zzz") suite.shouldSee = types.NewList(suite.shouldSeeItem) - suite.deadValue = types.Uint64(0xDEADBEEF) + suite.deadValue = types.Number(0xDEADBEEF) suite.mustSkip = types.NewList(suite.deadValue) }