@@ -114,6 +114,28 @@ func ExampleEnv() {
114114 // Output: true
115115}
116116
117+ func ExampleEnv_tagged_field_names () {
118+ env := struct {
119+ FirstWord string
120+ Separator string `expr:"Space"`
121+ SecondWord string `expr:"second_word"`
122+ }{
123+ FirstWord : "Hello" ,
124+ Separator : " " ,
125+ SecondWord : "World" ,
126+ }
127+
128+ output , err := expr .Eval (`FirstWord + Space + second_word` , env )
129+ if err != nil {
130+ fmt .Printf ("%v" , err )
131+ return
132+ }
133+
134+ fmt .Printf ("%v" , output )
135+
136+ // Output : Hello World
137+ }
138+
117139func ExampleAsBool () {
118140 env := map [string ]int {
119141 "foo" : 0 ,
@@ -513,9 +535,10 @@ func TestExpr(t *testing.T) {
513535 }
514536 return ret
515537 },
516- Inc : func (a int ) int { return a + 1 },
517- Nil : nil ,
518- Tweets : []tweet {{"Oh My God!" , date }, {"How you doin?" , date }, {"Could I be wearing any more clothes?" , date }},
538+ Inc : func (a int ) int { return a + 1 },
539+ Nil : nil ,
540+ Tweets : []tweet {{"Oh My God!" , date }, {"How you doin?" , date }, {"Could I be wearing any more clothes?" , date }},
541+ Lowercase : "lowercase" ,
519542 }
520543
521544 tests := []struct {
@@ -934,6 +957,10 @@ func TestExpr(t *testing.T) {
934957 `OneDayDuration + Now` ,
935958 tnowPlusOne ,
936959 },
960+ {
961+ `lowercase` ,
962+ "lowercase" ,
963+ },
937964 }
938965
939966 for _ , tt := range tests {
@@ -1229,6 +1256,7 @@ type divideError struct{ Message string }
12291256func (e divideError ) Error () string {
12301257 return e .Message
12311258}
1259+
12321260func TestConstExpr_error_as_error (t * testing.T ) {
12331261 env := map [string ]interface {}{
12341262 "divide" : func (a , b int ) (int , error ) {
@@ -1415,6 +1443,7 @@ type mockEnv struct {
14151443 NilInt * int
14161444 NilSlice []ticket
14171445 Tweets []tweet
1446+ Lowercase string `expr:"lowercase"`
14181447}
14191448
14201449func (e * mockEnv ) GetInt () int {
0 commit comments