コード例 #1
0
ファイル: enum_struct_test.go プロジェクト: arv/noms-old
func TestEnumIsValue(t *testing.T) {
	ds := datas.NewDataStore(chunks.NewMemoryStore())
	var v types.Value = gen.NewEnumStruct()
	ref := ds.WriteValue(v).TargetRef()
	v2 := ds.ReadValue(ref)
	assert.True(t, v.Equals(v2))
}
コード例 #2
0
ファイル: enum_struct_test.go プロジェクト: arv/noms-old
func TestEnumValue(t *testing.T) {
	assert := assert.New(t)

	def := gen.EnumStructDef{gen.Switch}
	var st types.Value
	st = def.New()
	st2 := st.(gen.EnumStruct)
	assert.True(st.Equals(st2))
}
コード例 #3
0
ファイル: map_test.go プロジェクト: arv/noms-old
func TestValueMapValue(t *testing.T) {
	assert := assert.New(t)

	def := gen.MapOfStringToValueDef{"s": types.NewString("s"), "i": types.Int32(42)}
	var m types.Value
	m = def.New()
	m2 := m.(gen.MapOfStringToValue)
	assert.True(m.Equals(m2))
}
コード例 #4
0
ファイル: struct_test.go プロジェクト: arv/noms-old
func TestValue(t *testing.T) {
	assert := assert.New(t)

	def := gen.StructDef{"hi", true}
	var st types.Value
	st = def.New()
	st2 := st.(gen.Struct)
	assert.True(st.Equals(st2))
}
コード例 #5
0
ファイル: datastore_common.go プロジェクト: arv/noms-old
// WriteValue takes a Value, schedules it to be written it to ds, and returns v.Ref(). v is not guaranteed to be actually written until after a successful Commit().
func (ds *dataStoreCommon) WriteValue(v types.Value) (r types.RefBase) {
	if v == nil {
		return
	}

	targetRef := v.Ref()
	r = types.PrivateRefFromType(targetRef, types.MakeRefType(v.Type()))
	if entry := ds.checkCache(targetRef); entry != nil && entry.Present() {
		return
	}

	// Encoding v causes any child chunks, e.g. internal nodes if v is a meta sequence, to get written. That needs to happen before we try to validate v.
	chunk := types.EncodeValue(v, ds)

	for _, reachable := range v.Chunks() {
		entry := ds.checkCache(reachable.TargetRef())
		d.Chk.True(entry != nil && entry.Present(), "Value to write contains ref %s, which points to a non-existent Value.", reachable.TargetRef())

		// BUG 1121
		// It's possible that entry.Type() will be simply 'Value', but that 'reachable' is actually a properly-typed object -- that is, a Ref to some specific Type. The Chk below would fail, though it's possible that the Type is actually correct. We wouldn't be able to verify without reading it, though, so we'll dig into this later.
		targetType := getTargetType(reachable)
		if targetType.Equals(types.MakePrimitiveType(types.ValueKind)) {
			continue
		}
		d.Chk.True(entry.Type().Equals(targetType), "Value to write contains ref %s, which points to a value of a different type: %+v != %+v", reachable.TargetRef(), entry.Type(), targetType)
	}
	ds.cs.Put(chunk) // TODO: DataStore should manage batching and backgrounding Puts.
	ds.setCache(targetRef, presentChunk(v.Type()))

	return
}
コード例 #6
0
ファイル: datastore_test.go プロジェクト: arv/noms-old
func TestReadWriteCache(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	ds := NewDataStore(cs)

	var v types.Value = types.Bool(true)
	assert.NotEqual(ref.Ref{}, ds.WriteValue(v))
	assert.Equal(1, cs.Writes)
	r := ds.WriteValue(v).TargetRef()
	assert.Equal(1, cs.Writes)

	v = ds.ReadValue(r)
	assert.True(v.Equals(types.Bool(true)))
}
コード例 #7
0
ファイル: index.go プロジェクト: arv/noms-old
func processPitches(v types.Value) (pitches []PitchDef) {
	switch v := v.(type) {
	case types.List:
		for i := uint64(0); i < v.Len(); i++ {
			pitches = append(pitches, processPitches(v.Get(i))...)
		}
	case MapOfStringToValue:
		if checkPitch(v) {
			pitches = append(pitches, getPitch(v))
		}
	case nil:
		return // Yes, an at-bat can end with no pitches thrown.
	default:
		d.Chk.Fail("Impossible pitch", "No pitch should be %+v, which is of type %s!\n", v, reflect.TypeOf(v).String())
	}
	return
}
コード例 #8
0
ファイル: struct_with_list_test.go プロジェクト: arv/noms-old
func TestStructIsValue(t *testing.T) {
	assert := assert.New(t)
	ds := datas.NewDataStore(chunks.NewMemoryStore())
	var v types.Value = gen.StructWithListDef{
		L: gen.ListOfUint8Def{0, 1, 2},
		B: true,
		S: "world",
		I: 42,
	}.New()

	ref := ds.WriteValue(v).TargetRef()
	v2 := ds.ReadValue(ref)
	assert.True(v.Equals(v2))

	s2 := v2.(gen.StructWithList)
	assert.True(s2.L().Equals(gen.NewListOfUint8().Append(0, 1, 2)))
	assert.True(s2.B())
	assert.Equal("world", s2.S())
	assert.Equal(int64(42), s2.I())
}
コード例 #9
0
ファイル: write.go プロジェクト: arv/noms-old
// ValueToListAndElemDesc ensures that v is a types.List of structs, pulls the types.StructDesc that describes the elements of v out of vr, and returns the List and related StructDesc.
func ValueToListAndElemDesc(v types.Value, vr types.ValueReader) (types.List, types.StructDesc) {
	d.Exp.Equal(types.ListKind, v.Type().Desc.Kind(),
		"Dataset must be List<>, found: %s", v.Type().Desc.Describe())

	u := v.Type().Desc.(types.CompoundDesc).ElemTypes[0]
	d.Exp.Equal(types.UnresolvedKind, u.Desc.Kind(),
		"List<> must be UnresolvedKind, found: %s", u.Desc.Describe())

	pkg := types.ReadPackage(u.PackageRef(), vr)
	d.Exp.Equal(types.PackageKind, pkg.Type().Desc.Kind(),
		"Failed to read package: %s", pkg.Type().Desc.Describe())

	desc := pkg.Types()[u.Ordinal()].Desc
	d.Exp.Equal(types.StructKind, desc.Kind(), "Did not find Struct: %s", desc.Describe())
	return v.(types.List), desc.(types.StructDesc)
}
コード例 #10
0
func (s __unionOfEOfFloat64AndFOfString) Equals(other types.Value) bool {
	return other != nil && __typeFor__unionOfEOfFloat64AndFOfString.Equals(other.Type()) && s.Ref() == other.Ref()
}
コード例 #11
0
ファイル: enum_struct.noms.go プロジェクト: arv/noms-old
func (s EnumStruct) Equals(other types.Value) bool {
	return other != nil && __typeForEnumStruct.Equals(other.Type()) && s.Ref() == other.Ref()
}
コード例 #12
0
func (s StructPrimitives) Equals(other types.Value) bool {
	return other != nil && __typeForStructPrimitives.Equals(other.Type()) && s.Ref() == other.Ref()
}
コード例 #13
0
ファイル: types.noms.go プロジェクト: arv/noms-old
func (r RefOfMapOfStringToValue) Equals(other types.Value) bool {
	return other != nil && __typeForRefOfMapOfStringToValue.Equals(other.Type()) && r.Ref() == other.Ref()
}
コード例 #14
0
ファイル: ref.noms.go プロジェクト: arv/noms-old
func (s SetOfFloat32) Equals(other types.Value) bool {
	return other != nil && __typeForSetOfFloat32.Equals(other.Type()) && s.Ref() == other.Ref()
}
コード例 #15
0
ファイル: sha1_6c64b08.go プロジェクト: arv/noms-old
func (m MapOfStringToRefOfCompany) Equals(other types.Value) bool {
	return other != nil && __typeForMapOfStringToRefOfCompany.Equals(other.Type()) && m.Ref() == other.Ref()
}
コード例 #16
0
ファイル: geo.noms.go プロジェクト: arv/noms-old
func (s Geoposition) Equals(other types.Value) bool {
	return other != nil && __typeForGeoposition.Equals(other.Type()) && s.Ref() == other.Ref()
}
コード例 #17
0
ファイル: photo.noms.go プロジェクト: arv/noms-old
func (m MapOfSizeToString) Equals(other types.Value) bool {
	return other != nil && __typeForMapOfSizeToString.Equals(other.Type()) && m.Ref() == other.Ref()
}
コード例 #18
0
ファイル: types.noms.go プロジェクト: arv/noms-old
func (m MapOfStringToRefOfListOfPitch) Equals(other types.Value) bool {
	return other != nil && __typeForMapOfStringToRefOfListOfPitch.Equals(other.Type()) && m.Ref() == other.Ref()
}
コード例 #19
0
ファイル: types.noms.go プロジェクト: arv/noms-old
func (r RefOfListOfPitch) Equals(other types.Value) bool {
	return other != nil && __typeForRefOfListOfPitch.Equals(other.Type()) && r.Ref() == other.Ref()
}
コード例 #20
0
ファイル: ref.noms.go プロジェクト: arv/noms-old
func (l ListOfRefOfFloat32) Equals(other types.Value) bool {
	return other != nil && __typeForListOfRefOfFloat32.Equals(other.Type()) && l.Ref() == other.Ref()
}
コード例 #21
0
ファイル: ref.noms.go プロジェクト: arv/noms-old
func (l ListOfString) Equals(other types.Value) bool {
	return other != nil && __typeForListOfString.Equals(other.Type()) && l.Ref() == other.Ref()
}
コード例 #22
0
ファイル: facebook.noms.go プロジェクト: arv/noms-old
func (r RefOfRemotePhoto) Equals(other types.Value) bool {
	return other != nil && __typeForRefOfRemotePhoto.Equals(other.Type()) && r.Ref() == other.Ref()
}
コード例 #23
0
ファイル: geo.noms.go プロジェクト: arv/noms-old
func (s Georectangle) Equals(other types.Value) bool {
	return other != nil && __typeForGeorectangle.Equals(other.Type()) && s.Ref() == other.Ref()
}
コード例 #24
0
ファイル: types.noms.go プロジェクト: arv/noms-old
func (s SetOfRefOfCommit) Equals(other types.Value) bool {
	return other != nil && __typeForSetOfRefOfCommit.Equals(other.Type()) && s.Ref() == other.Ref()
}
コード例 #25
0
ファイル: leafDep.noms.go プロジェクト: arv/noms-old
func (s S) Equals(other types.Value) bool {
	return other != nil && __typeForS.Equals(other.Type()) && s.Ref() == other.Ref()
}
コード例 #26
0
func (s ImportUser) Equals(other types.Value) bool {
	return other != nil && __typeForImportUser.Equals(other.Type()) && s.Ref() == other.Ref()
}
コード例 #27
0
ファイル: facebook.noms.go プロジェクト: arv/noms-old
func (r RefOfUser) Equals(other types.Value) bool {
	return other != nil && __typeForRefOfUser.Equals(other.Type()) && r.Ref() == other.Ref()
}
コード例 #28
0
ファイル: index.noms.go プロジェクト: arv/noms-old
func (m MapOfRefOfKeyToSetOfRefOfRound) Equals(other types.Value) bool {
	return other != nil && __typeForMapOfRefOfKeyToSetOfRefOfRound.Equals(other.Type()) && m.Ref() == other.Ref()
}
コード例 #29
0
ファイル: struct_with_list.noms.go プロジェクト: arv/noms-old
func (s StructWithList) Equals(other types.Value) bool {
	return other != nil && __typeForStructWithList.Equals(other.Type()) && s.Ref() == other.Ref()
}
コード例 #30
0
ファイル: walk.go プロジェクト: arv/noms-old
func doTreeWalkP(v types.Value, vr types.ValueReader, cb SomeCallback, concurrency int) {
	rq := newRefQueue()
	f := newFailure()

	visited := map[ref.Ref]bool{}
	mu := sync.Mutex{}
	wg := sync.WaitGroup{}

	var processVal func(v types.Value)
	processVal = func(v types.Value) {
		if cb(v) {
			return
		}

		if r, ok := v.(types.RefBase); ok {
			wg.Add(1)
			rq.tail() <- r.TargetRef()
		} else {
			for _, c := range v.ChildValues() {
				processVal(c)
			}
		}
	}

	processRef := func(r ref.Ref) {
		defer wg.Done()

		mu.Lock()
		skip := visited[r]
		visited[r] = true
		mu.Unlock()

		if skip || f.didFail() {
			return
		}

		v := vr.ReadValue(r)
		if v == nil {
			f.fail(fmt.Errorf("Attempt to copy absent ref:%s", r.String()))
			return
		}
		processVal(v)
	}

	iter := func() {
		for r := range rq.head() {
			processRef(r)
		}
	}

	for i := 0; i < concurrency; i++ {
		go iter()
	}

	processVal(v)
	wg.Wait()

	rq.close()

	f.checkNotFailed()
}