Skip to content

Commit 38b5cb0

Browse files
committed
Add test for missing widgets
1 parent 9b120bd commit 38b5cb0

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

test/test_widget_model.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <iterator>
1414
#include <map>
1515
#include <string>
16+
#include <tuple>
1617

1718
#include <doctest/doctest.h>
1819
#include <nlohmann/json-schema.hpp>
@@ -31,6 +32,8 @@ namespace xw
3132
nl::json serialize();
3233
template <typename Widget>
3334
std::string model_name();
35+
auto all_widget_model_names() -> std::array<std::string, std::tuple_size_v<AllWidgets>>;
36+
auto all_style_model_names() -> std::array<std::string, std::tuple_size_v<AllStyles>>;
3437

3538
#ifndef XWIDGETS_MODELS_FILE
3639
#error "XWIDGETS_MODELS_FILE must be defined pointing to model file"
@@ -78,6 +81,56 @@ namespace xw
7881

7982
TEST_CASE_TEMPLATE_APPLY(packages_widgets, AllWidgets);
8083
TEST_CASE_TEMPLATE_APPLY(packages_widgets, AllStyles);
84+
85+
TEST_CASE("missing")
86+
{
87+
auto widgets_contains = [](auto const& val)
88+
{
89+
static auto const all_widgets = all_widget_model_names();
90+
return std::find(all_widgets.begin(), all_widgets.end(), val) < all_widgets.end();
91+
};
92+
93+
auto styles_contains = [](auto const& val)
94+
{
95+
static auto const all_styles = all_style_model_names();
96+
return std::find(all_styles.begin(), all_styles.end(), val) < all_styles.end();
97+
};
98+
99+
// Missing widgets tracked in https://github.com/jupyter-xeus/xwidgets/issues/249
100+
// This test is still useful even with the todo so that we don't get model names
101+
// wrong.
102+
auto todo_contains = [](auto const& val)
103+
{
104+
static auto const todo = std::array{
105+
"ColorsInputModel",
106+
"ComboboxModel",
107+
"DatePickerModel",
108+
"DatetimeModel",
109+
"FileUploadModel",
110+
"FloatLogSliderModel",
111+
"FloatRangeSliderModel",
112+
"FloatsInputModel",
113+
"GridBoxModel",
114+
"HTMLMathModel",
115+
"HTMLMathStyleModel",
116+
"IntRangeSliderModel",
117+
"IntsInputModel",
118+
"NaiveDatetimeModel",
119+
"StackModel",
120+
"TagsInputModel",
121+
"TimeModel",
122+
};
123+
return std::find(todo.begin(), todo.end(), val) < todo.end();
124+
};
125+
126+
for (auto const& [model, _] : schemas)
127+
{
128+
// Somehow using `model` directly in the macro does not compile on clang 15.0.7
129+
auto const& model_that_pleases_clang = model;
130+
INFO("Checking for model ", model_that_pleases_clang);
131+
CHECK((widgets_contains(model) || styles_contains(model) || todo_contains(model)));
132+
}
133+
}
81134
}
82135

83136
/***************************************
@@ -253,4 +306,25 @@ namespace xw
253306
throw std::invalid_argument("Widget does not have a model name");
254307
}
255308

309+
template <typename>
310+
struct all_model_names_impl;
311+
312+
template <typename... Widgets>
313+
struct all_model_names_impl<std::tuple<Widgets...>>
314+
{
315+
static auto get()
316+
{
317+
return std::array{model_name<Widgets>()...};
318+
}
319+
};
320+
321+
auto all_widget_model_names() -> std::array<std::string, std::tuple_size_v<AllWidgets>>
322+
{
323+
return all_model_names_impl<AllWidgets>{}.get();
324+
}
325+
326+
auto all_style_model_names() -> std::array<std::string, std::tuple_size_v<AllStyles>>
327+
{
328+
return all_model_names_impl<AllStyles>{}.get();
329+
}
256330
}

0 commit comments

Comments
 (0)