98 lines
3.5 KiB
C++
98 lines
3.5 KiB
C++
|
|
// Step 1930: ASTNodeBreakpointMapper
|
||
|
|
//
|
||
|
|
// t1: setBreakpoint and getBreakpoints
|
||
|
|
// t2: breakpointsForLanguage filters correctly
|
||
|
|
// t3: removeBreakpoint removes one language, others intact
|
||
|
|
// t4: activateAll/deactivateAll/hitCount
|
||
|
|
// t5: clear empties everything
|
||
|
|
|
||
|
|
#include "ASTNodeBreakpointMapper.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(setBreakpoint_and_getBreakpoints);
|
||
|
|
ws::ASTNodeBreakpointMapper m;
|
||
|
|
m.setBreakpoint("HandleRequest","Go", "server/main.go", 42);
|
||
|
|
m.setBreakpoint("HandleRequest","TypeScript", "client/api.ts", 17);
|
||
|
|
auto bps = m.getBreakpoints("HandleRequest");
|
||
|
|
C(bps.size() == 2, "two breakpoints");
|
||
|
|
C(m.getBreakpoints("other").empty(), "unknown node empty");
|
||
|
|
bool hasGo = false, hasTs = false;
|
||
|
|
for (auto& b : bps) {
|
||
|
|
if (b.language == "Go") { hasGo = true; C(b.line == 42, "go line"); }
|
||
|
|
if (b.language == "TypeScript") { hasTs = true; C(b.line == 17, "ts line"); }
|
||
|
|
}
|
||
|
|
C(hasGo && hasTs, "both languages present");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t2(){
|
||
|
|
T(breakpointsForLanguage);
|
||
|
|
ws::ASTNodeBreakpointMapper m;
|
||
|
|
m.setBreakpoint("HandleRequest","Go", "main.go", 42);
|
||
|
|
m.setBreakpoint("HandleRequest","TypeScript", "api.ts", 17);
|
||
|
|
m.setBreakpoint("HandleHealth", "Go", "main.go", 80);
|
||
|
|
auto goBps = m.breakpointsForLanguage("Go");
|
||
|
|
C(goBps.size() == 2, "two Go breakpoints");
|
||
|
|
auto tsBps = m.breakpointsForLanguage("TypeScript");
|
||
|
|
C(tsBps.size() == 1 && tsBps[0].astNodeId == "HandleRequest", "one TS bp");
|
||
|
|
C(m.breakpointsForLanguage("Rust").empty(), "no Rust bps");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t3(){
|
||
|
|
T(removeBreakpoint_removes_one_language);
|
||
|
|
ws::ASTNodeBreakpointMapper m;
|
||
|
|
m.setBreakpoint("HandleRequest","Go", "main.go", 42);
|
||
|
|
m.setBreakpoint("HandleRequest","TypeScript", "api.ts", 17);
|
||
|
|
m.removeBreakpoint("HandleRequest","Go");
|
||
|
|
auto bps = m.getBreakpoints("HandleRequest");
|
||
|
|
C(bps.size() == 1, "one remaining");
|
||
|
|
C(bps[0].language == "TypeScript", "TypeScript remains");
|
||
|
|
// removing non-existent: no crash
|
||
|
|
m.removeBreakpoint("HandleRequest","Rust");
|
||
|
|
C(m.getBreakpoints("HandleRequest").size() == 1, "still one");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t4(){
|
||
|
|
T(activateAll_deactivateAll_hitCount);
|
||
|
|
ws::ASTNodeBreakpointMapper m;
|
||
|
|
m.setBreakpoint("HandleRequest","Go", "main.go", 42);
|
||
|
|
m.setBreakpoint("HandleRequest","TypeScript", "api.ts", 17);
|
||
|
|
C(m.hitCount("HandleRequest") == 2, "two active initially");
|
||
|
|
m.deactivateAll("HandleRequest");
|
||
|
|
C(m.hitCount("HandleRequest") == 0, "zero after deactivate");
|
||
|
|
m.activateAll("HandleRequest");
|
||
|
|
C(m.hitCount("HandleRequest") == 2, "two after reactivate");
|
||
|
|
// hitCount for unknown node
|
||
|
|
C(m.hitCount("Unknown") == 0, "unknown node hitCount 0");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t5(){
|
||
|
|
T(clear_empties_everything);
|
||
|
|
ws::ASTNodeBreakpointMapper m;
|
||
|
|
m.setBreakpoint("A","Go", "a.go", 1);
|
||
|
|
m.setBreakpoint("B","Rust","b.rs", 2);
|
||
|
|
m.clear();
|
||
|
|
C(m.getBreakpoints("A").empty(), "A cleared");
|
||
|
|
C(m.getBreakpoints("B").empty(), "B cleared");
|
||
|
|
C(m.hitCount("A") == 0, "hitCount 0 after clear");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(){
|
||
|
|
std::cout << "Step 1930: ASTNodeBreakpointMapper\n";
|
||
|
|
t1(); t2(); t3(); t4(); t5();
|
||
|
|
std::cout << "\n" << p << "/" << (p+f) << " passed\n";
|
||
|
|
return f > 0 ? 1 : 0;
|
||
|
|
}
|