File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed
staging/src/k8s.io/code-generator/cmd/go-to-protobuf Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ go_test(
37
37
srcs = [
38
38
"cmd_test.go" ,
39
39
"namer_test.go" ,
40
+ "parser_test.go" ,
40
41
],
41
42
embed = [":go_default_library" ],
42
43
)
Original file line number Diff line number Diff line change 1
1
/*
2
- Copyright 2016 The Kubernetes Authors.
2
+ Copyright 2020 The Kubernetes Authors.
3
3
4
4
Licensed under the Apache License, Version 2.0 (the "License");
5
5
you may not use this file except in compliance with the License.
@@ -21,12 +21,33 @@ import (
21
21
"testing"
22
22
)
23
23
24
+ /*
25
+ struct fields in go AST:
26
+
27
+ type Struct struct {
28
+ // fields with a direct field Name as <Ident>
29
+ A X // regular fields
30
+ B *X // pointer fields
31
+ C // embedded type field
32
+
33
+ // qualified embedded type fields use an <SelExpr> in the AST
34
+ v1.TypeMeta // X=v1, Sel=TypeMeta
35
+
36
+ // fields without a direct name, but
37
+ // a <StarExpr> in the go-AST
38
+ *D // type field embedded as pointer
39
+ *v1.ListMeta // qualified type field embedded as pointer
40
+ // with <StarExpr> pointing to <SelExpr>
41
+ }
42
+ */
43
+
24
44
func TestProtoParser (t * testing.T ) {
25
45
ident := ast .NewIdent ("FieldName" )
26
46
tests := []struct {
27
47
expr ast.Expr
28
48
err bool
29
49
}{
50
+ // valid struct field expressions
30
51
{
31
52
expr : ident ,
32
53
err : false ,
@@ -60,6 +81,7 @@ func TestProtoParser(t *testing.T) {
60
81
err : false ,
61
82
},
62
83
84
+ // something else should provide an error
63
85
{
64
86
expr : & ast.KeyValueExpr {
65
87
Key : ident ,
You can’t perform that action at this time.
0 commit comments