示例#1
0
        public void Any()
        {
            var a1 = A1();
            var a2 = A2();
            var b1 = B1();
            var b2 = B2();
            var m1 = new MethodType(new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a2)), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b1)));
            var m2 = new MethodType(new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a1)), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b2)));
            var t1 = new HasMembersType(new WeakScope(new List <WeakMemberDefinition> {
                new WeakMemberDefinition(Access.ReadWrite, new NameKey("a"), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a1))),
                new WeakMemberDefinition(Access.ReadWrite, new NameKey("b"), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b1)))
            }));
            var t2 = new HasMembersType(new WeakScope(new List <WeakMemberDefinition> {
                new WeakMemberDefinition(Access.ReadWrite, new NameKey("a"), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a2))),
                new WeakMemberDefinition(Access.ReadWrite, new NameKey("b"), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b2)))
            }));
            var or1 = new FrontEndOrType(
                new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a1)),
                new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b1)),
                OrType.Make <IReadOnlyList <WeakMemberDefinition>, IError>(Array.Empty <WeakMemberDefinition>()),
                Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >(),
                Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >()
                );
            var or2 = new FrontEndOrType(
                new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b1)),
                new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a1)),
                OrType.Make <IReadOnlyList <WeakMemberDefinition>, IError>(Array.Empty <WeakMemberDefinition>()),
                Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >(),
                Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >()
                );

            var any = new AnyType();

            Assert.All(new[] { a1, a2, b1, b2, m1, m2, t1, t2, or1, or2 }, x => any.TheyAreUs(x, new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>()));
        }
示例#2
0
        public void OrTypesAreVarient()
        {
            var a1 = A1();
            var a2 = A2();
            var b1 = B1();
            var b2 = B2();

            var or1 = new FrontEndOrType(
                new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a1)),
                new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b1)),
                OrType.Make <IReadOnlyList <WeakMemberDefinition>, IError>(Array.Empty <WeakMemberDefinition>()),
                Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >(),
                Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >()
                );
            var or2 = new FrontEndOrType(
                new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a2)),
                new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b2)),
                OrType.Make <IReadOnlyList <WeakMemberDefinition>, IError>(Array.Empty <WeakMemberDefinition>()),
                Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >(),
                Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >()
                );

            Assert.True(or1.TheyAreUs(or2, new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>()).Is1OrThrow());
            Assert.False(or2.TheyAreUs(or1, new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>()).Is1OrThrow());
        }
示例#3
0
        public void OrTypesJustNeedBothToMatchOne()
        {
            var a1 = A1();
            var b1 = B1();
            var b2 = B2();
            var b3 = B3();

            var or1 = new FrontEndOrType(
                new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(a1)),
                new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b1)),
                OrType.Make <IReadOnlyList <WeakMemberDefinition>, IError>(Array.Empty <WeakMemberDefinition>()),
                Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >(),
                Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >());
            var or2 = new FrontEndOrType(
                new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b2)),
                new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(b3)),
                OrType.Make <IReadOnlyList <WeakMemberDefinition>, IError>(new List <WeakMemberDefinition> {
                new WeakMemberDefinition(Access.ReadWrite, new NameKey("bm1"), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(new NumberType()))),
                new WeakMemberDefinition(Access.ReadWrite, new NameKey("bm2"), new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(new NumberType())))
            }),
                Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >(),
                Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >());

            // this works since both b2 and b3 are b1
            Assert.True(or1.TheyAreUs(or2, new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>()).Is1OrThrow());
            // this does not work because niether b2 nor b3 are a1
            Assert.False(or2.TheyAreUs(or1, new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>()).Is1OrThrow());
        }
示例#4
0
        public void OrTypesWork()
        {
            var or = new FrontEndOrType(
                new Box <IOrType <IFrontendType <IVerifiableType>, IError> > (OrType.Make <IFrontendType <IVerifiableType>, IError>(new NumberType())),
                new Box <IOrType <IFrontendType <IVerifiableType>, IError> >(OrType.Make <IFrontendType <IVerifiableType>, IError>(new StringType())),
                OrType.Make <IReadOnlyList <WeakMemberDefinition>, IError>(Array.Empty <WeakMemberDefinition>()),
                Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >(),
                Possibly.IsNot <IBox <IOrType <IFrontendType <IVerifiableType>, IError> > >());

            Assert.True(or.TheyAreUs(new NumberType(), new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>()).Is1OrThrow());
            Assert.True(or.TheyAreUs(new StringType(), new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>()).Is1OrThrow());

            Assert.False(new NumberType().TheyAreUs(or, new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>()).Is1OrThrow());
            Assert.False(new StringType().TheyAreUs(or, new List <(IFrontendType <IVerifiableType>, IFrontendType <IVerifiableType>)>()).Is1OrThrow());
        }