-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathshadowable_value_step_test.cc
More file actions
77 lines (60 loc) · 2.29 KB
/
Copy pathshadowable_value_step_test.cc
File metadata and controls
77 lines (60 loc) · 2.29 KB
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
#include "eval/eval/shadowable_value_step.h"
#include <string>
#include <utility>
#include "google/api/expr/v1alpha1/syntax.pb.h"
#include "google/protobuf/descriptor.h"
#include "absl/status/statusor.h"
#include "base/handle.h"
#include "base/value.h"
#include "eval/eval/evaluator_core.h"
#include "eval/eval/test_type_registry.h"
#include "eval/internal/interop.h"
#include "eval/public/activation.h"
#include "eval/public/cel_value.h"
#include "internal/status_macros.h"
#include "internal/testing.h"
namespace google::api::expr::runtime {
namespace {
using ::google::protobuf::Arena;
using testing::Eq;
absl::StatusOr<CelValue> RunShadowableExpression(std::string identifier,
cel::Handle<cel::Value> value,
const Activation& activation,
Arena* arena) {
CEL_ASSIGN_OR_RETURN(
auto step,
CreateShadowableValueStep(std::move(identifier), std::move(value), 1));
ExecutionPath path;
path.push_back(std::move(step));
CelExpressionFlatImpl impl(std::move(path), &TestTypeRegistry(),
cel::RuntimeOptions{});
return impl.Evaluate(activation, arena);
}
TEST(ShadowableValueStepTest, TestEvaluateNoShadowing) {
std::string type_name = "google.api.expr.runtime.TestMessage";
Activation activation;
Arena arena;
auto type_value = cel::interop_internal::CreateTypeValueFromView(type_name);
auto status =
RunShadowableExpression(type_name, type_value, activation, &arena);
ASSERT_OK(status);
auto value = status.value();
ASSERT_TRUE(value.IsCelType());
EXPECT_THAT(value.CelTypeOrDie().value(), Eq(type_name));
}
TEST(ShadowableValueStepTest, TestEvaluateShadowedIdentifier) {
std::string type_name = "int";
auto shadow_value = CelValue::CreateInt64(1024L);
Activation activation;
activation.InsertValue(type_name, shadow_value);
Arena arena;
auto type_value = cel::interop_internal::CreateTypeValueFromView(type_name);
auto status =
RunShadowableExpression(type_name, type_value, activation, &arena);
ASSERT_OK(status);
auto value = status.value();
ASSERT_TRUE(value.IsInt64());
EXPECT_THAT(value.Int64OrDie(), Eq(1024L));
}
} // namespace
} // namespace google::api::expr::runtime