File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -388,6 +388,15 @@ func (e *Env) HasLibrary(libName string) bool {
388388 return exists && configured
389389}
390390
391+ // Libraries returns a list of SingletonLibrary that have been configured in the environment.
392+ func (e * Env ) Libraries () []string {
393+ libraries := make ([]string , len (e .libraries ))
394+ for libName := range e .libraries {
395+ libraries = append (libraries , libName )
396+ }
397+ return libraries
398+ }
399+
391400// HasValidator returns whether a specific ASTValidator has been configured in the environment.
392401func (e * Env ) HasValidator (name string ) bool {
393402 for _ , v := range e .validators {
Original file line number Diff line number Diff line change @@ -228,6 +228,26 @@ func TestTypeProviderInterop(t *testing.T) {
228228 }
229229}
230230
231+ func TestLibraries (t * testing.T ) {
232+ e , err := NewEnv (OptionalTypes ())
233+ if err != nil {
234+ t .Fatalf ("NewEnv() failed: %v" , err )
235+ }
236+ for _ , expected := range []string {"cel.lib.std" , "cel.lib.optional" } {
237+ if ! e .HasLibrary (expected ) {
238+ t .Errorf ("Expected HasLibrary() to return true for '%s'" , expected )
239+ }
240+ libMap := map [string ]struct {}{}
241+ for _ , lib := range e .Libraries () {
242+ libMap [lib ] = struct {}{}
243+ }
244+
245+ if _ , ok := libMap [expected ]; ! ok {
246+ t .Errorf ("Expected Libraries() to include '%s'" , expected )
247+ }
248+ }
249+ }
250+
231251func BenchmarkNewCustomEnvLazy (b * testing.B ) {
232252 b .ResetTimer ()
233253 for i := 0 ; i < b .N ; i ++ {
You can’t perform that action at this time.
0 commit comments