13
13
#include < iterator>
14
14
#include < map>
15
15
#include < string>
16
+ #include < tuple>
16
17
17
18
#include < doctest/doctest.h>
18
19
#include < nlohmann/json-schema.hpp>
@@ -31,6 +32,8 @@ namespace xw
31
32
nl::json serialize ();
32
33
template <typename Widget>
33
34
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>>;
34
37
35
38
#ifndef XWIDGETS_MODELS_FILE
36
39
#error "XWIDGETS_MODELS_FILE must be defined pointing to model file"
@@ -78,6 +81,56 @@ namespace xw
78
81
79
82
TEST_CASE_TEMPLATE_APPLY (packages_widgets, AllWidgets);
80
83
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
+ }
81
134
}
82
135
83
136
/* **************************************
@@ -253,4 +306,25 @@ namespace xw
253
306
throw std::invalid_argument (" Widget does not have a model name" );
254
307
}
255
308
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
+ }
256
330
}
0 commit comments