Пример #1
0
        public void NamedTypeTest()
        {
            var address = new BifoqlNamedType("Address", BifoqlType.Map(BifoqlType.Property("street", BifoqlType.String)));
            var person  = new BifoqlNamedType("Person", BifoqlType.Map(BifoqlType.Property("name", BifoqlType.String), BifoqlType.Property("address", BifoqlType.Named(() => address))));

            var optionalPerson = BifoqlType.Map(BifoqlType.Property("p",
                                                                    BifoqlType.Index(BifoqlType.Named(() => person),
                                                                                     BifoqlType.IndexParameter("id", BifoqlType.Number),
                                                                                     BifoqlType.IndexParameter("locale", BifoqlType.String, optional: true))));

            var s = new Schema(optionalPerson, address, person);

            var schema =
                @"{
    p: (id: number, locale?: string) => Person
}

Address = {
    street: string
}

Person = {
    name: string,
    address: Address
}
";

            Assert.Equal(schema, s.BuildDocumentation());
        }
Пример #2
0
        public void MapWithOverloadedLookups()
        {
            var expected =
                @"{
    foo: string,
    foo: (id: number) => string
}";
            var type = new Schema(BifoqlType.Map(
                                      BifoqlType.Property("foo", BifoqlType.String),
                                      BifoqlType.Property("foo", BifoqlType.Index(BifoqlType.String,
                                                                                  BifoqlType.IndexParameter("id", BifoqlType.Number)
                                                                                  ))));

            Assert.Equal(expected, type.BuildDocumentation());
        }
Пример #3
0
        public void MapTypes()
        {
            var expected =
                @"{
    x: number,
    burger: [
        boolean
    ],
    street: string
}";
            var type = new Schema(BifoqlType.Map(
                                      BifoqlType.Property("x", BifoqlType.Number),
                                      BifoqlType.Property("burger", BifoqlType.Tuple(BifoqlType.Boolean)),
                                      BifoqlType.Property("street", BifoqlType.String)));

            Assert.Equal(expected, type.BuildDocumentation());
        }
Пример #4
0
        public void MapTypesWithDocumentation()
        {
            var expected =
                @"{
    // A number
    x: number,

    // A tasty burger
    // yum!
    burger: [
        boolean
    ],

    // The street
    street: string
}";
            var type = new Schema(BifoqlType.Map(
                                      BifoqlType.Property("x", BifoqlType.Number, "A number"),
                                      BifoqlType.Property("burger", BifoqlType.Tuple(BifoqlType.Boolean), "A tasty burger\nyum!"),
                                      BifoqlType.Property("street", BifoqlType.String, "The street")));

            Assert.Equal(expected, type.BuildDocumentation());
        }
Пример #5
0
        public void NamedTypeWithDocumentationTest()
        {
            var person = new BifoqlNamedType("Person", BifoqlType.Map(BifoqlType.Property("name", BifoqlType.String)), "A human being");

            var optionalPerson = BifoqlType.Map(BifoqlType.Property("p",
                                                                    BifoqlType.Index(BifoqlType.Named(() => person),
                                                                                     BifoqlType.IndexParameter("id", BifoqlType.Number),
                                                                                     BifoqlType.IndexParameter("locale", BifoqlType.String, optional: true))));

            var s = new Schema(optionalPerson, person);

            var schema =
                @"{
    p: (id: number, locale?: string) => Person
}

// A human being
Person = {
    name: string
}
";

            Assert.Equal(schema, s.BuildDocumentation());
        }