| 1 | // Copyright 2025 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/ |
| 16 | |
| 17 | import ( |
| 18 | _ "embedscip-go gomod github.com/golang/go/src go1.23.0 embed/" |
| 19 | "testingscip-go gomod github.com/golang/go/src go1.23.0 testing/" |
| 20 | |
| 21 | "github.com/google/cel-go/common/envscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/env`/" |
| 22 | "github.com/google/cel-go/testscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/" |
| 23 | ) |
| 24 | |
| 25 | //go:embed testdata/basic.prompt.txt |
| 26 | var wantBasicPromptscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/wantBasicPrompt. string |
| 27 | |
| 28 | //go:embed testdata/macros.prompt.txt |
| 29 | var wantMacrosPromptscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/wantMacrosPrompt. string |
| 30 | |
| 31 | //go:embed testdata/standard_env.prompt.txt |
| 32 | var wantStandardEnvPromptscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/wantStandardEnvPrompt. string |
| 33 | |
| 34 | func TestPromptTemplatescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/TestPromptTemplate().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 35 | tests := []struct { |
| 36 | name string |
| 37 | envOpts []EnvOptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/EnvOption# |
| 38 | out string |
| 39 | }{ |
| 40 | { |
| 41 | name: "basic", |
| 42 | out: wantBasicPromptscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/wantBasicPrompt., |
| 43 | }, |
| 44 | { |
| 45 | name: "macros", |
| 46 | envOpts: []EnvOptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/EnvOption#{Macrosscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Macros().(StandardMacrosscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/StandardMacros....)}, |
| 47 | out: wantMacrosPromptscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/wantMacrosPrompt., |
| 48 | }, |
| 49 | { |
| 50 | name: "standard_env", |
| 51 | envOpts: []EnvOptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/EnvOption#{StdLibscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/StdLib().(StdLibSubsetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/StdLibSubset().(envscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/env`/.NewLibrarySubsetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/env`/NewLibrarySubset().().SetDisableMacrosscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/env`/LibrarySubset#SetDisableMacros().(true)))}, |
| 52 | out: wantStandardEnvPromptscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/wantStandardEnvPrompt., |
| 53 | }, |
| 54 | } |
| 55 | |
| 56 | for _, tst := range tests { |
| 57 | tc := tst |
| 58 | t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 59 | env, err := NewCustomEnvscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/NewCustomEnv().(tc.envOpts...) |
| 60 | if err != nil { |
| 61 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("cel.NewCustomEnv() failed: %v", err) |
| 62 | } |
| 63 | prompt, err := AuthoringPromptscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/AuthoringPrompt().(env) |
| 64 | if err != nil { |
| 65 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("cel.AuthoringPrompt() failed: %v", err) |
| 66 | } |
| 67 | out := prompt.Renderscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Prompt#Render().("<USER_PROMPT>") |
| 68 | if !testscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/.Comparescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Compare().(out, tc.out) { |
| 69 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %s, wanted %s", out, tc.out) |
| 70 | } |
| 71 | }) |
| 72 | } |
| 73 | } |