17
17
#include " ../src/xsystem.hpp"
18
18
#include " ../src/xmagics/os.hpp"
19
19
20
+ #include < iostream>
21
+
20
22
#include < fstream>
21
23
#if defined(__GNUC__) && !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
22
24
#include < sys/wait.h>
@@ -610,6 +612,20 @@ TEST_SUITE("xmagics_contains"){
610
612
}
611
613
}
612
614
615
+ class MyMagicLine : public xcpp ::xmagic_line {
616
+ public:
617
+ virtual void operator ()(const std::string& line) override {
618
+ std::cout << line << std::endl;
619
+ }
620
+ };
621
+
622
+ class MyMagicCell : public xcpp ::xmagic_cell {
623
+ public:
624
+ virtual void operator ()(const std::string& line, const std::string& cell) override {
625
+ std::cout << line << cell << std::endl;
626
+ }
627
+ };
628
+
613
629
TEST_SUITE (" xmagics_apply" ){
614
630
TEST_CASE (" bad_status_cell" ) {
615
631
xcpp::xmagics_manager manager;
@@ -626,6 +642,51 @@ TEST_SUITE("xmagics_apply"){
626
642
manager.apply (" %dummy" , kernel_res);
627
643
REQUIRE (kernel_res[" status" ] == " error" );
628
644
}
645
+
646
+ TEST_CASE (" good_status_line" ) {
647
+
648
+ xcpp::xpreamble_manager preamble_manager;
649
+
650
+ preamble_manager.register_preamble (" magics" , new xcpp::xmagics_manager ());
651
+
652
+ preamble_manager[" magics" ].get_cast <xcpp::xmagics_manager>().register_magic (" magic2" , MyMagicCell ());
653
+
654
+ nl::json kernel_res;
655
+
656
+ preamble_manager[" magics" ].get_cast <xcpp::xmagics_manager>().apply (" %%magic2 qwerty" , kernel_res);
657
+
658
+ REQUIRE (kernel_res[" status" ] == " ok" );
659
+ }
660
+
661
+ TEST_CASE (" good_status_cell" ) {
662
+
663
+ xcpp::xpreamble_manager preamble_manager;
664
+
665
+ preamble_manager.register_preamble (" magics" , new xcpp::xmagics_manager ());
666
+
667
+ preamble_manager[" magics" ].get_cast <xcpp::xmagics_manager>().register_magic (" magic1" , MyMagicLine ());
668
+
669
+ nl::json kernel_res;
670
+
671
+ preamble_manager[" magics" ].get_cast <xcpp::xmagics_manager>().apply (" %magic1 qwerty" , kernel_res);
672
+
673
+ REQUIRE (kernel_res[" status" ] == " ok" );
674
+ }
675
+
676
+ TEST_CASE (" cell magic with empty cell body" ) {
677
+ xcpp::xmagics_manager manager;
678
+
679
+ std::stringstream ss;
680
+ auto cerr_buff = std::cerr.rdbuf ();
681
+ std::cerr.rdbuf (ss.rdbuf ());
682
+
683
+ manager.apply (" test" , " line" , " " );
684
+
685
+ std::cerr.rdbuf (cerr_buff);
686
+ REQUIRE (ss.str () == " UsageError: %%test is a cell magic, but the cell body is empty.\n "
687
+ " If you only intend to display %%test help, please use a double line break to fill in the cell body.\n " );
688
+
689
+ }
629
690
}
630
691
631
692
#if defined(__GNUC__) && !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
0 commit comments