// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Simple end-to-end conformance tests.

syntax = "proto3";

package cel.expr.conformance;

import "cel/expr/checked.proto";
import "cel/expr/eval.proto";
import "cel/expr/value.proto";

option cc_enable_arenas = true;
option go_package = "cel.dev/expr/conformance";
option java_multiple_files = true;
option java_outer_classname = "SimpleProto";
option java_package = "dev.cel.expr.conformance";

// The format of a simple test file, expected to be stored in text format.
// A file is the unit of granularity for selecting conformance tests,
// so tests of optional features should be segregated into separate files.
message SimpleTestFile {
  // Required.  The name of the file.  Should match the filename.
  string name = 1;

  // A description of the file.
  string description = 2;

  // The contained sections.
  repeated SimpleTestSection section = 3;
}

// A collection of related SimpleTests.
//
// The section is the unit of organization within a test file, and should
// guide where new tests are added.
message SimpleTestSection {
  // Required.  The name of the section.
  string name = 1;

  // A description of the section.
  string description = 2;

  // The contained tests.
  repeated SimpleTest test = 3;
}

// A test which should run the given CEL program through parsing,
// optionally through checking, then evaluation, with the results
// of the pipeline validated by the given result matcher.
message SimpleTest {
  // Required.  The name of the test, which should be unique in the test file.
  string name = 1;

  // A description of the test.
  string description = 2;

  // Required.  The text of the CEL expression.
  string expr = 3;

  // Disables all macro expansion in parsing.
  bool disable_macros = 4;

  // Disables the check phase.
  bool disable_check = 5;

  // The type environment to use for the check phase.
  repeated cel.expr.Decl type_env = 6;

  // The container for name resolution.
  string container = 13;

  // The locale to use for the evaluation phase.
  string locale = 14;

  // Variable bindings to use for the eval phase.
  map<string, cel.expr.ExprValue> bindings = 7;

  // An unspecified result defaults to a matcher for the true boolean value.
  oneof result_matcher {
    // A normal value, which must match the evaluation result exactly
    // via value equality semantics.  This coincides with proto equality,
    // except for:
    // *   maps are order-agnostic.
    // *   a floating point NaN should match any NaN.
    cel.expr.Value value = 8;

    // Matches error evaluation results.
    cel.expr.ErrorSet eval_error = 9;

    // Matches one of several error results.
    // (Using explicit message since oneof can't handle repeated.)
    ErrorSetMatcher any_eval_errors = 10;

    // Matches unknown evaluation results.
    cel.expr.UnknownSet unknown = 11;

    // Matches one of several unknown results.
    // (Using explicit message since oneof can't handle repeated.)
    UnknownSetMatcher any_unknowns = 12;
  }
  // Next is 15.
}

// Matches error results from Eval.
message ErrorSetMatcher {
  // Success if we match any of these sets.
  repeated cel.expr.ErrorSet errors = 1;
}

// Matches unknown results from Eval.
message UnknownSetMatcher {
  // Success if we match any of these sets.
  repeated cel.expr.UnknownSet unknowns = 1;
}
