| 64 | } |
| 65 | |
| 66 | TEST(Schema, GlobalFuncTypeSchema) { |
| 67 | // Helper to fetch global function type schema via the exposed utility |
| 68 | Function get_metadata = Function::GetGlobalRequired("ffi.GetGlobalFuncMetadata"); |
| 69 | auto fetch = [&](const char* name) -> std::string { |
| 70 | String metadata = get_metadata(String(name)).cast<String>(); |
| 71 | return ParseMetadataToSchema(metadata); |
| 72 | }; |
| 73 | // Simple IDs |
| 74 | EXPECT_EQ(fetch("testing.schema_id_int"), |
| 75 | R"({"type":"ffi.Function","args":[{"type":"int"},{"type":"int"}]})"); |
| 76 | EXPECT_EQ(fetch("testing.schema_id_float"), |
| 77 | R"({"type":"ffi.Function","args":[{"type":"float"},{"type":"float"}]})"); |
| 78 | EXPECT_EQ(fetch("testing.schema_id_bool"), |
| 79 | R"({"type":"ffi.Function","args":[{"type":"bool"},{"type":"bool"}]})"); |
| 80 | EXPECT_EQ(fetch("testing.schema_id_device"), |
| 81 | R"({"type":"ffi.Function","args":[{"type":"Device"},{"type":"Device"}]})"); |
| 82 | EXPECT_EQ(fetch("testing.schema_id_dtype"), |
| 83 | R"({"type":"ffi.Function","args":[{"type":"DataType"},{"type":"DataType"}]})"); |
| 84 | EXPECT_EQ(fetch("testing.schema_id_string"), |
| 85 | R"({"type":"ffi.Function","args":[{"type":"ffi.String"},{"type":"ffi.String"}]})"); |
| 86 | EXPECT_EQ(fetch("testing.schema_id_bytes"), |
| 87 | R"({"type":"ffi.Function","args":[{"type":"ffi.Bytes"},{"type":"ffi.Bytes"}]})"); |
| 88 | EXPECT_EQ(fetch("testing.schema_id_func"), |
| 89 | R"({"type":"ffi.Function","args":[{"type":"ffi.Function"},{"type":"ffi.Function"}]})"); |
| 90 | EXPECT_EQ( |
| 91 | fetch("testing.schema_id_func_typed"), |
| 92 | R"({"type":"ffi.Function","args":[{"type":"ffi.Function","args":[{"type":"None"},{"type":"int"},{"type":"float"},{"type":"ffi.Function"}]},{"type":"ffi.Function","args":[{"type":"None"},{"type":"int"},{"type":"float"},{"type":"ffi.Function"}]}]})"); |
| 93 | |
| 94 | EXPECT_EQ(fetch("testing.schema_id_any"), |
| 95 | R"({"type":"ffi.Function","args":[{"type":"Any"},{"type":"Any"}]})"); |
| 96 | EXPECT_EQ(fetch("testing.schema_id_object"), |
| 97 | R"({"type":"ffi.Function","args":[{"type":"ffi.Object"},{"type":"ffi.Object"}]})"); |
| 98 | EXPECT_EQ(fetch("testing.schema_id_dltensor"), |
| 99 | R"({"type":"ffi.Function","args":[{"type":"DLTensor*"},{"type":"DLTensor*"}]})"); |
| 100 | EXPECT_EQ(fetch("testing.schema_id_tensor"), |
| 101 | R"({"type":"ffi.Function","args":[{"type":"ffi.Tensor"},{"type":"ffi.Tensor"}]})"); |
| 102 | EXPECT_EQ(fetch("testing.schema_tensor_view_input"), |
| 103 | R"({"type":"ffi.Function","args":[{"type":"None"},{"type":"DLTensor*"}]})"); |
| 104 | EXPECT_EQ( |
| 105 | fetch("testing.schema_id_opt_int"), |
| 106 | R"({"type":"ffi.Function","args":[{"type":"Optional","args":[{"type":"int"}]},{"type":"Optional","args":[{"type":"int"}]}]})"); |
| 107 | EXPECT_EQ( |
| 108 | fetch("testing.schema_id_opt_str"), |
| 109 | R"({"type":"ffi.Function","args":[{"type":"Optional","args":[{"type":"ffi.String"}]},{"type":"Optional","args":[{"type":"ffi.String"}]}]})"); |
| 110 | EXPECT_EQ( |
| 111 | fetch("testing.schema_id_opt_obj"), |
| 112 | R"({"type":"ffi.Function","args":[{"type":"Optional","args":[{"type":"ffi.Object"}]},{"type":"Optional","args":[{"type":"ffi.Object"}]}]})"); |
| 113 | EXPECT_EQ( |
| 114 | fetch("testing.schema_id_arr_int"), |
| 115 | R"({"type":"ffi.Function","args":[{"type":"ffi.Array","args":[{"type":"int"}]},{"type":"ffi.Array","args":[{"type":"int"}]}]})"); |
| 116 | EXPECT_EQ( |
| 117 | fetch("testing.schema_id_arr_str"), |
| 118 | R"({"type":"ffi.Function","args":[{"type":"ffi.Array","args":[{"type":"ffi.String"}]},{"type":"ffi.Array","args":[{"type":"ffi.String"}]}]})"); |
| 119 | EXPECT_EQ( |
| 120 | fetch("testing.schema_id_arr_obj"), |
| 121 | R"({"type":"ffi.Function","args":[{"type":"ffi.Array","args":[{"type":"ffi.Object"}]},{"type":"ffi.Array","args":[{"type":"ffi.Object"}]}]})"); |
| 122 | EXPECT_EQ(fetch("testing.schema_id_arr"), |
| 123 | R"({"type":"ffi.Function","args":[{"type":"ffi.Array"},{"type":"ffi.Array"}]})"); |
nothing calls this directly
no test coverage detected