Skip to content

Commit 7318d29

Browse files
committed
booya
1 parent 5de666a commit 7318d29

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎v3/js/opt-frontend-common.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,14 @@ function parseQueryString() {
10051005
rawInputLst = [];
10061006
}
10071007

1008+
if (queryStrOptions.testCasesLst) {
1009+
$("#createTestsLink").hide();
1010+
initTestcasesPane('#testCasesPane');
1011+
queryStrOptions.testCasesLst.forEach(function(e) {
1012+
addTestcase(e);
1013+
});
1014+
}
1015+
10081016
// ugh tricky -- always start in edit mode by default, and then
10091017
// switch to display mode only after the code successfully executes
10101018
appMode = 'edit';
@@ -1019,6 +1027,7 @@ function parseQueryString() {
10191027
// parsing the URL query string hash
10201028
function getQueryStringOptions() {
10211029
var ril = $.bbq.getState('rawInputLstJSON');
1030+
var testCasesLstJSON = $.bbq.getState('testCasesJSON');
10221031
// note that any of these can be 'undefined'
10231032
return {preseededCode: $.bbq.getState('code'),
10241033
preseededCurInstr: Number($.bbq.getState('curInstr')),
@@ -1028,7 +1037,8 @@ function getQueryStringOptions() {
10281037
cumulative: $.bbq.getState('cumulative'),
10291038
heapPrimitives: $.bbq.getState('heapPrimitives'),
10301039
textReferences: $.bbq.getState('textReferences'),
1031-
rawInputLst: ril ? $.parseJSON(ril) : undefined
1040+
rawInputLst: ril ? $.parseJSON(ril) : undefined,
1041+
testCasesLst: testCasesLstJSON ? $.parseJSON(testCasesLstJSON) : undefined
10321042
};
10331043
}
10341044

‎v3/js/opt-testcases.js‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@ var testcasesPaneHtml = '\
5252
<a href="#" id="addNewTestCase">Add new test</a>\
5353
'
5454

55-
var curTestcaseId = 1;
56-
5755
function initTestcasesPane(parentDivId) {
56+
$(parentDivId).empty(); // just to be paranoid, empty this out
57+
// (and its event handlers, too, supposedly)
5858
$(parentDivId).html(testcasesPaneHtml);
5959

6060
$("#addNewTestCase").click(function() {
61-
addTestcase(curTestcaseId);
62-
curTestcaseId++;
61+
addTestcase();
6362
return false; // to prevent link from being followed
6463
});
6564

@@ -110,7 +109,12 @@ function vizTestFinishSuccessfulExecution() {
110109
doneRunningTest();
111110
}
112111

113-
function addTestcase(id) {
112+
113+
var curTestcaseId = 1;
114+
115+
function addTestcase(initialCod /* optional code to pre-seed this test */) {
116+
var id = curTestcaseId;
117+
curTestcaseId++; // nasty global
114118
var newTr = $('<tr/>').attr('id', 'testCaseRow_' + id);
115119
$("#testCasesTable tbody").append(newTr);
116120
var editorTd = $('<td/>');
@@ -143,6 +147,11 @@ function addTestcase(id) {
143147
te.setFontSize(10);
144148
//te.setReadOnly(true);
145149

150+
if (initialCod) {
151+
te.setValue(initialCod.rtrim() /* kill trailing spaces */,
152+
-1 /* do NOT select after setting text */);
153+
}
154+
146155
var s = te.getSession();
147156
s.setTabSize(2);
148157
s.setUseSoftTabs(true);

0 commit comments

Comments
 (0)