Skip to content

Commit ef6f5e7

Browse files
committed
gooo
1 parent 3af5f1e commit ef6f5e7

3 files changed

Lines changed: 62 additions & 35 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,29 @@ if (window.location.protocol === 'https:') {
7373
var RUBY_JSONP_ENDPOINT = 'http://cokapi.com:3000/exec_ruby_jsonp'; // for deployment
7474
}
7575

76+
77+
function langToBackendScript(lang) {
78+
var backend_script = null;
79+
if (lang == '2') {
80+
backend_script = python2_backend_script;
81+
} else if (lang == '3') {
82+
backend_script = python3_backend_script;
83+
} else if (lang == '2crazy') {
84+
backend_script = python2crazy_backend_script;
85+
} else if (lang == 'js') {
86+
backend_script = js_backend_script;
87+
} else if (lang == 'ts') {
88+
backend_script = ts_backend_script;
89+
} else if (lang == 'ruby') {
90+
backend_script = ruby_backend_script;
91+
} else if (lang == 'java') {
92+
backend_script = java_backend_script;
93+
}
94+
assert(backend_script);
95+
return backend_script;
96+
}
97+
98+
7699
var domain = "http://pythontutor.com/"; // for deployment
77100

78101

‎v3/js/opt-frontend.js‎

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -109,37 +109,7 @@ function TogetherjsCloseHandler() {
109109
}
110110
}
111111

112-
113-
function executeCode(forceStartingInstr, forceRawInputLst) {
114-
if (forceRawInputLst !== undefined) {
115-
rawInputLst = forceRawInputLst; // UGLY global across modules, FIXME
116-
}
117-
118-
var backend_script = null;
119-
if ($('#pythonVersionSelector').val() == '2') {
120-
backend_script = python2_backend_script;
121-
}
122-
else if ($('#pythonVersionSelector').val() == '3') {
123-
backend_script = python3_backend_script;
124-
}
125-
// experimental KRAZY MODE!!!
126-
else if ($('#pythonVersionSelector').val() == '2crazy') {
127-
backend_script = python2crazy_backend_script;
128-
}
129-
else if ($('#pythonVersionSelector').val() == 'js') {
130-
backend_script = js_backend_script;
131-
}
132-
else if ($('#pythonVersionSelector').val() == 'ts') {
133-
backend_script = ts_backend_script;
134-
}
135-
else if ($('#pythonVersionSelector').val() == 'ruby') {
136-
backend_script = ruby_backend_script;
137-
}
138-
else if ($('#pythonVersionSelector').val() == 'java') {
139-
backend_script = java_backend_script;
140-
}
141-
assert(backend_script);
142-
112+
function getBaseBackendOptionsObj() {
143113
var backendOptionsObj = {cumulative_mode: ($('#cumulativeModeSelector').val() == 'true'),
144114
heap_primitives: ($('#heapPrimitivesSelector').val() == 'true'),
145115
show_only_outputs: false,
@@ -151,10 +121,11 @@ function executeCode(forceStartingInstr, forceRawInputLst) {
151121
backendOptionsObj.survey = surveyObj;
152122
}
153123

154-
var startingInstruction = forceStartingInstr ? forceStartingInstr : 0;
124+
return backendOptionsObj;
125+
}
155126

156-
var frontendOptionsObj = {startingInstruction: startingInstruction,
157-
// tricky: selector 'true' and 'false' values are strings!
127+
function getBaseFrontendOptionsObj() {
128+
var frontendOptionsObj = {// tricky: selector 'true' and 'false' values are strings!
158129
disableHeapNesting: ($('#heapPrimitivesSelector').val() == 'true'),
159130
textualMemoryLabels: ($('#textualMemoryLabelsSelector').val() == 'true'),
160131
executeCodeWithRawInputFunc: executeCodeWithRawInput,
@@ -172,6 +143,21 @@ function executeCode(forceStartingInstr, forceRawInputLst) {
172143
pyCrazyMode: ($('#pythonVersionSelector').val() == '2crazy'),
173144
holisticMode: ($('#cumulativeModeSelector').val() == 'holistic')
174145
}
146+
return frontendOptionsObj;
147+
}
148+
149+
function executeCode(forceStartingInstr, forceRawInputLst) {
150+
if (forceRawInputLst !== undefined) {
151+
rawInputLst = forceRawInputLst; // UGLY global across modules, FIXME
152+
}
153+
154+
var backend_script = langToBackendScript($('#pythonVersionSelector').val());
155+
var backendOptionsObj = getBaseBackendOptionsObj();
156+
157+
var startingInstruction = forceStartingInstr ? forceStartingInstr : 0;
158+
159+
var frontendOptionsObj = getBaseFrontendOptionsObj();
160+
frontendOptionsObj.startingInstruction = startingInstruction;
175161

176162
executePythonCode(pyInputGetValue(),
177163
backend_script, backendOptionsObj,

‎v3/js/opt-testcases.js‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var testcasesPaneHtml = '\
3939
<thead>\
4040
<tr>\
4141
<td style="width: 310px">Tests</td>\
42-
<td><button id="runAllTestsButton" type="button">Run All</button></td>\
42+
<td><button id="runAllTestsButton" type="button">Run All Tests</button></td>\
4343
<td>Results</td>\
4444
<td></td>\
4545
<td></td>\
@@ -62,6 +62,8 @@ function initTestcasesPane(parentDivId) {
6262
curTestcaseId++;
6363
return false; // to prevent link from being followed
6464
});
65+
66+
$("#addNewTestCase").click(); // for testing
6567
}
6668

6769
function addTestcase(id) {
@@ -85,6 +87,22 @@ function addTestcase(id) {
8587
newTr.append(visualizeTd);
8688
newTr.append(deleteTd);
8789

90+
$('#runTestCase_' + id).click(function() {
91+
$(this).html("Running ...");
92+
$(this).attr('disabled', true);
93+
startExecutingCode();
94+
var userCod = pyInputGetValue();
95+
var testCod = ace.edit('testCaseEditor_' + id).getValue();
96+
// for reporting syntax errors separately for user and test code
97+
var userCodNumLines = userCod.split('\n').length;
98+
99+
var bufferCod = '\n\n# Test code:\n';
100+
var bufferCodNumLines = bufferCod.split('\n').length;
101+
102+
var combinedCod = userCod + bufferCod + testCod;
103+
console.log(combinedCod);
104+
});
105+
88106
$('#delTestCase_' + id).click(function() {
89107
var res = confirm("Press OK to delete this test.");
90108
if (res) {

0 commit comments

Comments
 (0)