-
Notifications
You must be signed in to change notification settings - Fork 8
/
all.go
111 lines (97 loc) · 2.85 KB
/
all.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2016 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package vomtest provides protocol conformance tests for the Vanadium Object
// Marshaller (VOM).
package vomtest
import (
"flag"
"reflect"
"strings"
)
// The following causes data files to be generated when "go generate" is run.
//go:generate ./gen.sh
var flagVOMTest string
// TODO(toddw): There seems to be a bug in the Go toolchain that prevents this
// init func from being run from the v.io/v23/vom tests, so the flag isn't
// registered. Investigate this.
func init() {
flag.StringVar(&flagVOMTest, "vomtest", "", `Filter vomtest.All to only return entries that contain the given substring. If the value starts with "!", only returns entries that don't contain the given substring.`)
}
func filter() (bool, string) {
if strings.HasPrefix(flagVOMTest, "!") {
return false, strings.TrimPrefix(flagVOMTest, "!")
}
return true, flagVOMTest
}
// The following vars are defined in generated files:
// var pass81 []Entry
// AllPass returns all entries that pass encoding and decoding tests.
//
// The -vomtest flag may be used to filter the returned entries.
func AllPass() []Entry {
var result []Entry
for _, e := range fromVDLEntries(pass81) {
if want, substr := filter(); strings.Contains(e.Name(), substr) == want {
result = append(result, e)
}
}
return result
}
// AllPassFunc returns the entries in AllPass where fn(e) returns true for each
// returned entry.
func AllPassFunc(fn func(e Entry) bool) []Entry {
var result []Entry
for _, e := range AllPass() {
if fn(e) {
result = append(result, e)
}
}
return result
}
// AllFail returns all entries that fail encoding and decoding tests.
//
// The -vomtest flag may be used to filter the returned entries.
func AllFail() []Entry {
var result []Entry
// TODO(toddw): Add failing tests.
return result
}
// AllFailFunc returns the entries in AllFail where fn(e) returns true for each
// returned entry.
func AllFailFunc(fn func(e Entry) bool) []Entry {
var result []Entry
for _, e := range AllFail() {
if fn(e) {
result = append(result, e)
}
}
return result
}
func fromVDLEntries(groups ...[]vdlEntry) []Entry {
var result []Entry
for _, entries := range groups {
for _, e := range entries {
result = append(result, fromVDLEntry(e))
}
}
return result
}
func fromVDLEntry(e vdlEntry) Entry {
return Entry{
Label: e.Label,
ValueLabel: e.ValueLabel,
Value: rvSafeValueOf(e.Value),
Version: e.Version,
HexType: e.HexType,
HexValue: e.HexValue,
}
}
func rvSafeValueOf(v interface{}) reflect.Value {
// reflect.ValueOf(nil) returns an invalid reflect.Value, but we want a valid
// reflect.Value representing nil.
if v == nil {
return reflect.ValueOf(&v).Elem()
}
return reflect.ValueOf(v)
}