Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate ReflectionTypeCheck #528

Merged
merged 9 commits into from
May 1, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Tests
  • Loading branch information
smaye81 committed Apr 29, 2023
commit 9cce61c8e6b2d919439b1ac7364b951bcd2ea5b8
40 changes: 24 additions & 16 deletions packages/test-generated/spec/reflection-type-check.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {assert, isOneofGroup, normalizeFieldInfo, PartialMessage, ReflectionTypeCheck, ScalarType} from "@protobuf-ts/runtime";
import {ScalarValuesMessage} from "../ts-out/msg-scalar";
import {OneofScalarMemberMessage, ScalarValuesMessage} from "../ts-out/msg-scalar";


describe('ReflectionTypeCheck.is()', function () {
Expand Down Expand Up @@ -75,23 +75,31 @@ describe('ReflectionTypeCheck.is()', function () {

const depth = 1;

it('checks oneof group structure', function () {
let check = new ReflectionTypeCheck(fixtures.makeMessageInfo('spec.OneofScalarMemberMessage'));
let m = fixtures.getMessage('spec.OneofScalarMemberMessage', 'err');
assert(isOneofGroup(m.result));
m.result.oneofKind = 'xxx';
let is = check.is(m, depth, false);
expect(is).toBe(false);
describe("oneof scalar member messages", () => {
const mi = {
typeName: OneofScalarMemberMessage.typeName,
fields: OneofScalarMemberMessage.fields.map(normalizeFieldInfo),
options: {}
};
it('checks oneof group structure', function () {
let check = new ReflectionTypeCheck(mi);
let m = {result: {oneofKind: 'error', error: 'hello'}};
assert(isOneofGroup(m.result));
m.result.oneofKind = 'xxx';
let is = check.is(m, depth, false);
expect(is).toBe(false);
});
it('checks oneof member type', function () {
let check = new ReflectionTypeCheck(mi);
let m = {result: {oneofKind: 'error', error: 'hello'}};
assert(isOneofGroup(m.result));
m.result.error = 123;
let is = check.is(m, depth, false);
expect(is).toBe(false);
});
});

it('checks oneof member type', function () {
let check = new ReflectionTypeCheck(fixtures.makeMessageInfo('spec.OneofScalarMemberMessage'));
let m = fixtures.getMessage('spec.OneofScalarMemberMessage', 'err');
assert(isOneofGroup(m.result));
m.result.error = 123;
let is = check.is(m, depth, false);
expect(is).toBe(false);
});


it('checks oneof discriminator', function () {
let check = new ReflectionTypeCheck(fixtures.makeMessageInfo('spec.OneofScalarMemberMessage'));
Expand Down