From fabdc0472b6f2828e34f01a13fc3fa738f9eab5d Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 27 Aug 2015 18:25:03 +0200 Subject: Add testing functionality --- js/codeq/comms.js | 5 +++++ js/prolog.js | 30 +++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/codeq/comms.js b/js/codeq/comms.js index cff1015..c2ad715 100644 --- a/js/codeq/comms.js +++ b/js/codeq/comms.js @@ -121,6 +121,11 @@ return send('query', query); }, + sendTest: function commsSendTest (json) { + json['sid'] = codeq.sid; + return send('test', json); + }, + getProblem: function commsGetProblem (language, problem_group, problem) { return send('get_problem', { 'sid': codeq.sid, diff --git a/js/prolog.js b/js/prolog.js index e252393..c3e3da8 100644 --- a/js/prolog.js +++ b/js/prolog.js @@ -354,7 +354,35 @@ $('#btn_code_hint').on('click', function () { // handler.processServerHints([{id:'drop_down', start: 20, end: 26, choices:['ena', 'dva', 'tri']}]); }); + $('#btn_code_test').on('click', function () { + jqConsole.echo('?- test.'); + jqConsole.pause(); + var doc = editor.getDoc(); + codeq.comms.sendTest({ + 'program': editor.getDoc().getValue(), + 'problem_id': problem.id + }).then( + function testSuccess(data) { + jqConsole.resume(); + // TODO output to "hints" window once that is implemented + if (data.code === 0) { + t = data.terminal; + lines = t.messages; + for (i = 0; i < lines.length; i++) { + jqConsole.echo(lines[i]); + } + } + else { + jqConsole.error(data.message); + } + }, + tf = function testFailed (error) { + jqConsole.resume(); + jqConsole.exception(error); + } + ).done(); + }); return handler; }; -})(); \ No newline at end of file +})(); -- cgit v1.2.1