i dunno if this is a good idea.

selection
Jordan Orelli 4 years ago
parent e43149ab98
commit acb92cc4d6

@ -0,0 +1,16 @@
package tea
var lastID int
func nextNodeID() int {
lastID++
return lastID
}
type node struct {
id int
test Test
name string
parents []*node
children []*node
}

@ -0,0 +1,47 @@
package tea
import (
"testing"
)
func NewSelection(test Test) Selection {
n := node{test: test}
return Selection{
nodes: []*node{&n},
}
}
func RunSelection(t *testing.T, s Selection) {
}
type Selection struct {
nodes []*node
}
func (s Selection) Child(test Test) Selection {
child := &node{
id: nextNodeID(),
test: test,
name: parseName(test),
parents: s.nodes,
}
for _, sn := range s.nodes {
sn.children = append(sn.children, child)
}
return Selection{nodes: []*node{child}}
}
func (s Selection) And(other Selection) Selection {
included := make(map[int]bool)
out := make([]*node, 0, len(s.nodes)+len(other.nodes))
for _, n := range append(s.nodes, other.nodes...) {
if !included[n.id] {
out = append(out, n)
included[n.id] = true
}
}
return Selection{nodes: out}
}

@ -0,0 +1 @@
package tea

@ -12,6 +12,18 @@ type Test interface {
Run(*testing.T) Run(*testing.T)
} }
// clone clones a test value, yielding a new test value that can be executed
// and mutated such that the original is not mutated. Tests containing pointers
// to objects that were not created by tea will probably not work right. That's
// like, kinda on you though, I can't really enforce things that the Go type
// system doesn't let me enforce.
func clone(t Test) Test {
srcV := reflect.ValueOf(t).Elem()
destV := reflect.New(srcV.Type())
destV.Elem().Set(srcV)
return destV.Interface().(Test)
}
// After defines the interface used for performing test cleanup. If a Test // After defines the interface used for performing test cleanup. If a Test
// value also implements After, that test's After method will be called after // value also implements After, that test's After method will be called after
// all tests are run. Tests in a sequence will have their After methods called // all tests are run. Tests in a sequence will have their After methods called

@ -100,15 +100,6 @@ func (t *Tree) Child(test Test) *Tree {
return child return child
} }
// clone clones a test value, yielding a new test value that can be executed
// and mutated such that the original is not mutated.
func clone(t Test) Test {
srcV := reflect.ValueOf(t).Elem()
destV := reflect.New(srcV.Type())
destV.Elem().Set(srcV)
return destV.Interface().(Test)
}
// isSaveField takes a struct field and checks its tags for a save tag, // isSaveField takes a struct field and checks its tags for a save tag,
// indicating that the field's value should persist between tests // indicating that the field's value should persist between tests
func isSaveField(f reflect.StructField) bool { func isSaveField(f reflect.StructField) bool {

Loading…
Cancel
Save