@@ -1076,3 +1076,73 @@ TEST_SUITE("file") {
1076
1076
infile.close ();
1077
1077
}
1078
1078
}
1079
+
1080
+ #if !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
1081
+ TEST_SUITE (" undo_and_redefinition" )
1082
+ {
1083
+ TEST_CASE (" RedefinitionAndUndoErrors" )
1084
+ {
1085
+ std::vector<const char *> Args = {/* "-v", "resource-dir", "..."*/ };
1086
+ xcpp::interpreter interpreter ((int ) Args.size (), Args.data ());
1087
+ std::string code = R"(
1088
+ int x = 5;
1089
+ )" ;
1090
+ nl::json user_expressions = nl::json::object ();
1091
+ xeus::execute_request_config config;
1092
+ config.silent = false ;
1093
+ config.store_history = false ;
1094
+ config.allow_stdin = false ;
1095
+ nl::json header = nl::json::object ();
1096
+ xeus::xrequest_context::guid_list id = {};
1097
+ xeus::xrequest_context context (header, id);
1098
+
1099
+ // Execute first code: define int x = 5
1100
+ std::promise<nl::json> promise1;
1101
+ std::future<nl::json> future1 = promise1.get_future ();
1102
+ auto callback1 = [&promise1](nl::json result)
1103
+ {
1104
+ promise1.set_value (result);
1105
+ };
1106
+ interpreter
1107
+ .execute_request (std::move (context), std::move (callback1), code, std::move (config), user_expressions);
1108
+ nl::json execute1 = future1.get ();
1109
+ REQUIRE (execute1[" status" ] == " ok" );
1110
+
1111
+ code = R"( %undo)" ;
1112
+ std::promise<nl::json> promise2;
1113
+ std::future<nl::json> future2 = promise2.get_future ();
1114
+ auto callback2 = [&promise2](nl::json result)
1115
+ {
1116
+ promise2.set_value (result);
1117
+ };
1118
+ interpreter
1119
+ .execute_request (std::move (context), std::move (callback2), code, std::move (config), user_expressions);
1120
+ nl::json execute2 = future2.get ();
1121
+ REQUIRE (execute2[" status" ] == " ok" );
1122
+
1123
+ code = " int x = 10;" ;
1124
+ std::promise<nl::json> promise3;
1125
+ std::future<nl::json> future3 = promise3.get_future ();
1126
+ auto callback3 = [&promise3](nl::json result)
1127
+ {
1128
+ promise3.set_value (result);
1129
+ };
1130
+ interpreter
1131
+ .execute_request (std::move (context), std::move (callback3), code, std::move (config), user_expressions);
1132
+ nl::json execute3 = future3.get ();
1133
+ REQUIRE (execute3[" status" ] == " ok" );
1134
+
1135
+ code = " int x = 20;" ;
1136
+ std::promise<nl::json> promise4;
1137
+ std::future<nl::json> future4 = promise4.get_future ();
1138
+ auto callback4 = [&promise4](nl::json result)
1139
+ {
1140
+ promise4.set_value (result);
1141
+ };
1142
+ interpreter
1143
+ .execute_request (std::move (context), std::move (callback4), code, std::move (config), user_expressions);
1144
+ nl::json execute4 = future4.get ();
1145
+ REQUIRE (execute4[" status" ] == " error" );
1146
+ }
1147
+ }
1148
+ #endif
0 commit comments