Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,25 @@ message TestAllTypes {
optional string single_name = 405;
}

// Formerly defined as reserved field names.
optional bool as = 500;
optional bool break = 501;
optional bool const = 502;
optional bool continue = 503;
optional bool else = 504;
optional bool for = 505;
optional bool function = 506;
optional bool if = 507;
optional bool import = 508;
optional bool let = 509;
optional bool loop = 510;
optional bool package = 511;
optional bool namespace = 512;
optional bool return = 513;
optional bool var = 514;
optional bool void = 515;
optional bool while = 516;

extensions 1000 to max;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,25 @@ message TestAllTypes {
NestedMessage oneof_msg = 401;
bool oneof_bool = 402;
}

// Formerly defined as reserved field names.
bool as = 500;
bool break = 501;
bool const = 502;
bool continue = 503;
bool else = 504;
bool for = 505;
bool function = 506;
bool if = 507;
bool import = 508;
bool let = 509;
bool loop = 510;
bool package = 511;
bool namespace = 512;
bool return = 513;
bool var = 514;
bool void = 515;
bool while = 516;
}

// This proto includes a recursively nested message.
Expand Down
33 changes: 26 additions & 7 deletions packages/cel-spec/scripts/fetch-proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,34 @@ import {
readPackageJson,
writeFiles,
} from "./common.js";
import { parseArgs } from "node:util";
import { copyFileSync, readdirSync, realpathSync } from "node:fs";

/*
* Fetch Protobuf files from the upstream github.com/google/cel-spec
*/

const { upstreamCelSpecRef } = readPackageJson("package.json");
const archive = await fetchRepository(upstreamCelSpecRef);
const proto = extractFiles(
archive,
/^cel-spec-[^/]+\/proto\/(cel\/expr\/.+\.proto)$/,
);
writeFiles(proto, "proto");
const { positionals } = parseArgs({ allowPositionals: true });

if (positionals.length === 0) {
const { upstreamCelSpecRef } = readPackageJson("package.json");
const archive = await fetchRepository(upstreamCelSpecRef);
const proto = extractFiles(
archive,
/^cel-spec-[^/]+\/proto\/(cel\/expr\/.+\.proto)$/,
);
writeFiles(proto, "proto");
} else if (positionals.length === 1) {
// Copy from local directory containing CEL expression protos —
// useful when concurrently developing changes to the schemas
// e.g., `npm run fetch-proto ../../../../google/cel-spec/proto/cel/expr`
const source = realpathSync(positionals[0]);
const files = readdirSync(source, { recursive: true }).filter((f) =>
f.endsWith(".proto"),
);
for (const file of files) {
copyFileSync(`${source}/${file}`, `proto/cel/expr/${file}`);
}
} else {
throw new Error("Too many arguments.");
}
49 changes: 39 additions & 10 deletions packages/cel-spec/scripts/fetch-testdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,52 @@

import { extractFiles, fetchRepository, readPackageJson } from "./common.js";
import { spawnSync } from "node:child_process";
import { writeFileSync } from "node:fs";
import {
readdirSync,
readFileSync,
realpathSync,
writeFileSync,
} from "node:fs";
import { parseArgs } from "node:util";

/*
* Fetch conformance test data from the upstream github.com/google/cel-spec
* Because we convert the test data from textproto to JSON, this script depends
* on the directory "proto" to contain the corresponding Protobuf files.
*/

const { upstreamCelSpecRef } = readPackageJson("package.json");
const { positionals } = parseArgs({ allowPositionals: true });

let source;
const testdataTextProto = [];

if (positionals.length === 0) {
const { upstreamCelSpecRef } = readPackageJson("package.json");
source = `github.com/google/cel-spec ${upstreamCelSpecRef}`;

// Fetch github.com/google/cel-spec
const archive = await fetchRepository(upstreamCelSpecRef);
// Extract testdata/simple/*.textproto
const testdata = extractFiles(
archive,
/^cel-spec-[^/]+\/tests\/simple\/testdata\/([^/]+\.textproto)$/,
);

testdataTextProto.push(...testdata);
} else if (positionals.length === 1) {
// Read from local directory containing *.textproto instead —
// useful when concurrently developing new conformance tests
// e.g., `npm run fetch-testdata ../../../../google/cel-spec/tests/simple/testdata`
source = realpathSync(positionals[0]);

const paths = readdirSync(source).filter((p) => p.endsWith(".textproto"));
const testdata = paths.map((p) => [p, readFileSync(`${source}/${p}`)]);

testdataTextProto.push(...testdata);
} else {
throw new Error("Too many arguments.");
}

// Fetch github.com/google/cel-spec
const archive = await fetchRepository(upstreamCelSpecRef);
// Extract testdata/simple/*.textproto
const testdataTextProto = extractFiles(
archive,
/^cel-spec-[^/]+\/tests\/simple\/testdata\/([^/]+\.textproto)$/,
);
// Convert textproto to JSON with `buf convert`, using the local module "proto".
const testdataJson = convertTestDataToJson(
testdataTextProto,
Expand All @@ -40,7 +69,7 @@ const testdataJson = convertTestDataToJson(
// Write as JSON array to a TypeScript file
writeFileSync(
"src/testdata-json.ts",
`// Generated from github.com/google/cel-spec ${upstreamCelSpecRef} by scripts/fetch-testdata.js
`// Generated from ${source} by scripts/fetch-testdata.js

export const testdataJson = ${JSON.stringify(testdataJson, null, 2)} as const;`,
);
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading
Loading