-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "conformance_tests/cel-spec"] | ||
path = conformance_tests/cel-spec | ||
url = [email protected]:google/cel-spec.git | ||
[submodule "conformance_tests/googleapis"] | ||
path = conformance_tests/googleapis | ||
url = [email protected]:googleapis/googleapis.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
[workspace] | ||
members = ["parser", "program", "web"] | ||
members = ["parser", "program", "web", "cel_spec"] | ||
resolver = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "cel_spec" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
prost = "0.12" | ||
prost-types = "0.12" | ||
prost-reflect = { version = "0.13.0", features = ["text-format"]} | ||
quote = "1.0.35" | ||
program = { path = "../program" } | ||
|
||
[build_dependencies] | ||
prost-build = "0.12.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use std::{env, io::Result, path::PathBuf}; | ||
|
||
fn main() -> Result<()> { | ||
let out = env::var("OUT_DIR").expect("OUT_DIR environment variable not set"); | ||
let out = PathBuf::from(out).join("cel.bin"); | ||
let mut config = prost_build::Config::new(); | ||
config.disable_comments(&["."]); | ||
config.file_descriptor_set_path(out); | ||
config.compile_protos( | ||
&["cel-spec/proto/test/v1/simple.proto"], | ||
&["cel-spec/proto/", "googleapis/"], | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use proc_macro::TokenStream; | ||
use quote::{format_ident, quote, ToTokens}; | ||
|
||
const BYTES: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/cel.bin")); | ||
|
||
#[proc_macro] | ||
pub fn cel_test(attr: TokenStream) -> TokenStream { | ||
println!("attr: \"{}\"", attr.to_string()); | ||
use prost_reflect::{DescriptorPool, DynamicMessage}; | ||
|
||
let pool = DescriptorPool::decode(BYTES.as_ref()).unwrap(); | ||
let message_descriptor = pool.get_message_by_name("google.api.expr.test.v1.SimpleTestFile").unwrap(); | ||
let bytes = include_str!("../cel-spec/tests/simple/testdata/basic.textproto"); | ||
let suite = DynamicMessage::parse_text_format(message_descriptor, &bytes).unwrap(); | ||
|
||
let mut ast = String::new(); | ||
for section in suite.get_field_by_name("section").unwrap().as_list().unwrap() { | ||
let section = section.as_message().unwrap(); | ||
let sname = section.get_field_by_name("name").unwrap(); | ||
|
||
ast.push_str(format!("pub mod {}{{", sname.as_str().unwrap()).as_str()); | ||
|
||
for case in section.get_field_by_name("test").unwrap().as_list().unwrap() { | ||
let case = case.as_message().unwrap(); | ||
let name = case.get_field_by_name("name").unwrap(); | ||
let expr = case.get_field_by_name("expr").unwrap(); | ||
|
||
let name = format_ident!("{}", name.as_str().unwrap()); | ||
let expr = expr.as_str().unwrap(); | ||
ast.push_str( | ||
"e!{ | ||
#[test] | ||
fn #name() { | ||
assert!(program::Program::new(#expr).expect("failed to compile").execute(program::context::Context::default())); | ||
} | ||
}.to_string() | ||
) | ||
} | ||
|
||
ast.push_str("}"); | ||
break; | ||
} | ||
ast.parse().unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
extern crate cel_spec; | ||
|
||
cel_spec::cel_test!(suite = "basic"); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters