93 lines
3.4 KiB
C++
93 lines
3.4 KiB
C++
|
|
// Step 1924: DebugAdapterRouter
|
||
|
|
// Routes DAP commands to the correct language debug adapter.
|
||
|
|
//
|
||
|
|
// t1: setActiveLanguage / getActiveLanguage
|
||
|
|
// t2: registerAdapter and adapterSupports
|
||
|
|
// t3: routeCommand true only when active language AND supports command
|
||
|
|
// t4: adaptersSupporting finds all langs with a command
|
||
|
|
// t5: registeredAdapters lists all registered languages
|
||
|
|
|
||
|
|
#include "DebugAdapterRouter.h"
|
||
|
|
#include <iostream>
|
||
|
|
|
||
|
|
namespace ws = whetstone;
|
||
|
|
|
||
|
|
static int p=0,f=0;
|
||
|
|
#define T(n) { std::cout<<" "<<#n<<"... "; }
|
||
|
|
#define P() { std::cout<<"PASS\n"; ++p; }
|
||
|
|
#define F(m) { std::cout<<"FAIL: "<<m<<"\n"; ++f; }
|
||
|
|
#define C(c,m) if(!(c)){F(m);return;}
|
||
|
|
|
||
|
|
void t1(){
|
||
|
|
T(setActiveLanguage_getActiveLanguage);
|
||
|
|
ws::DebugAdapterRouter r;
|
||
|
|
C(r.getActiveLanguage().empty(), "empty initially");
|
||
|
|
r.setActiveLanguage("Python");
|
||
|
|
C(r.getActiveLanguage() == "Python", "Python active");
|
||
|
|
r.setActiveLanguage("Rust");
|
||
|
|
C(r.getActiveLanguage() == "Rust", "Rust active after switch");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t2(){
|
||
|
|
T(registerAdapter_and_adapterSupports);
|
||
|
|
ws::DebugAdapterRouter r;
|
||
|
|
r.registerAdapter("Python", {"stackTrace","scopes","variables","continue","next","stepIn"});
|
||
|
|
r.registerAdapter("Rust", {"stackTrace","scopes","variables","continue","next"});
|
||
|
|
C( r.adapterSupports("Python","stepIn"), "Python supports stepIn");
|
||
|
|
C(!r.adapterSupports("Rust", "stepIn"), "Rust lacks stepIn");
|
||
|
|
C( r.adapterSupports("Rust", "continue"),"Rust supports continue");
|
||
|
|
C(!r.adapterSupports("Go", "stackTrace"),"unregistered Go lacks stackTrace");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t3(){
|
||
|
|
T(routeCommand_active_and_supports);
|
||
|
|
ws::DebugAdapterRouter r;
|
||
|
|
r.registerAdapter("Python", {"stackTrace","continue","stepIn"});
|
||
|
|
r.registerAdapter("Rust", {"stackTrace","continue"});
|
||
|
|
r.setActiveLanguage("Python");
|
||
|
|
// active + supports → true
|
||
|
|
C( r.routeCommand("stackTrace","Python"), "Python active stackTrace");
|
||
|
|
C( r.routeCommand("stepIn", "Python"), "Python active stepIn");
|
||
|
|
// active but other lang → false
|
||
|
|
C(!r.routeCommand("stackTrace","Rust"), "Rust not active → false");
|
||
|
|
// switch active
|
||
|
|
r.setActiveLanguage("Rust");
|
||
|
|
C( r.routeCommand("stackTrace","Rust"), "Rust now active stackTrace");
|
||
|
|
C(!r.routeCommand("stepIn", "Rust"), "Rust active but lacks stepIn");
|
||
|
|
C(!r.routeCommand("stackTrace","Python"), "Python no longer active");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t4(){
|
||
|
|
T(adaptersSupporting_finds_all);
|
||
|
|
ws::DebugAdapterRouter r;
|
||
|
|
r.registerAdapter("Python", {"stackTrace","continue","stepIn"});
|
||
|
|
r.registerAdapter("Rust", {"stackTrace","continue"});
|
||
|
|
r.registerAdapter("Go", {"stackTrace","continue","next"});
|
||
|
|
auto st = r.adaptersSupporting("stackTrace");
|
||
|
|
C(st.size() == 3, "three adapters support stackTrace");
|
||
|
|
auto si = r.adaptersSupporting("stepIn");
|
||
|
|
C(si.size() == 1 && si[0] == "Python", "only Python supports stepIn");
|
||
|
|
C(r.adaptersSupporting("attach").empty(), "none support attach");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t5(){
|
||
|
|
T(registeredAdapters_lists_all);
|
||
|
|
ws::DebugAdapterRouter r;
|
||
|
|
C(r.registeredAdapters().empty(), "empty initially");
|
||
|
|
r.registerAdapter("Python", {"continue"});
|
||
|
|
r.registerAdapter("Rust", {"continue"});
|
||
|
|
C(r.registeredAdapters().size() == 2, "two registered");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(){
|
||
|
|
std::cout << "Step 1924: DebugAdapterRouter\n";
|
||
|
|
t1(); t2(); t3(); t4(); t5();
|
||
|
|
std::cout << "\n" << p << "/" << (p+f) << " passed\n";
|
||
|
|
return f > 0 ? 1 : 0;
|
||
|
|
}
|