Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for testing functions with target #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion liquid-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Executable liquid-server
snap-core >= 0.9 && < 0.11,
snap-server >= 0.9 && < 0.11,
aeson,
hashable < 1.2,
hashable,
unordered-containers,
time,
process,
Expand Down
1 change: 1 addition & 0 deletions resources/custom/liquidhaskell/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
, "modeFile" : "mode-haskell.js"
, "tmpDir" : ".liquid"
, "port" : 8090
, "srcTester" : "target"
}
1 change: 1 addition & 0 deletions resources/custom/nanojs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
, "themeFile" : "theme-xcode.js"
, "modeFile" : "mode-javascript.js"
, "tmpDir" : ""
, "srcTester" : ""
}
2 changes: 2 additions & 0 deletions resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ <h1>{{demoTitle}}</h1>
<div class="input-prepend input-append">
<button class="btn btn-info" type="button" ng-show="isUnknown" ng-click="verifySource()">Re</button>
<button class="btn btn-info" type="button" ng-show="isUnknown" ng-click="verifySource()">Check</button>
<button class="btn btn-info" type="button" ng-show="isUnknown" ng-click="testSource()">Test</button>
<input class="input-large" id="binder" type="search" ng-show="isUnknown" placeholder="binder to check">
</div>

<button class="btn" type="button" ng-show="isChecking" ng-click="verifySource()">Verifying...</button>
Expand Down
138 changes: 84 additions & 54 deletions resources/static/js/liquid.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ function getDemo(name){
return res;
}

function getDemos(ty){
function getDemos(ty){
var a = [];
for (var k in allDemos) {
if (allDemos[k].type == ty)
for (var k in allDemos) {
if (allDemos[k].type == ty)
a.push(getDemo(k));
};
return a;
Expand All @@ -32,7 +32,7 @@ function getCategories(){
function tx(c){return {type: c.type, name: c.name, demos: getDemos(c.type)}};
return allCategories.map(tx);
}


/*******************************************************************************/
/************** Setting Up Editor **********************************************/
Expand Down Expand Up @@ -62,7 +62,7 @@ function toggleEditorSize(x){
if (x.isFullScreen){
ht = 600;
};
$("#program-pane").height(ht);
$("#program-pane").height(ht);
$("#program").height(ht-60);
}

Expand All @@ -73,12 +73,12 @@ function toggleEditorSize(x){
/*******************************************************************************/

function errorRange(err){

var row0 = err.start.line - 1;
var col0 = err.start.column - 1;
var row1 = err.stop.line - 1;
var col1 = err.stop.column - 1;

if (row0 == row1 && col0 == col1){
return new Range(row0, col0, row0, col0 + 1);
} else {
Expand Down Expand Up @@ -109,7 +109,7 @@ function setErrors(editor, errs){
// Add Error Markers
errorMarkers.forEach(function(m){ editor.session.removeMarker(m); });
errorMarkers = errs.map(function(e){ return errorMarker(editor, e);});

// Add Gutter Annotations
editor.session.clearAnnotations();
var annotations = errs.map(errorAceAnnot);
Expand All @@ -121,18 +121,18 @@ function setErrors(editor, errs){
/************** URLS ***********************************************************/
/*******************************************************************************/

function isPrefix(p, q) {
return (p == q.slice(0, p.length))
function isPrefix(p, q) {
return (p == q.slice(0, p.length))
}

function getQueryURL(){
return 'query';
function getQueryURL(){
return 'query';
}

function getSrcURL(file){
function getSrcURL(file){
if (file.match("/")){
return file;
} else {
} else {
return ('demos/' + file);
}
}
Expand All @@ -143,24 +143,31 @@ function getSrcURL(file){
/************** Queries ********************************************************/
/*******************************************************************************/

function getCheckQuery($scope){
function getCheckQuery($scope){
return { type : "check",
program : getSourceCode()
program : getSourceCode()
};
}

function getRecheckQuery($scope){
var p = "";
if ($scope.filePath) p = $scope.filePath;

return { type : "recheck",
program : getSourceCode(),
return { type : "recheck",
program : getSourceCode(),
path : p
};
}

function getTestQuery($scope){
return { type : "test",
program : getSourceCode(),
binder : getBinder()
};
}

function getLoadQuery($scope){
return { type : "load",
return { type : "load",
path : $scope.localFilePath
};
}
Expand Down Expand Up @@ -213,15 +220,19 @@ function setStatusResult($scope, data){

function setSourceCode($scope, srcName, srcText){
clearStatus($scope);
$scope.filePath = null;
$scope.filePath = null;
$scope.sourceFileName = srcName.split("/").pop(); // drop path prefix
progEditor.getSession().setValue(srcText);
progEditor.getSession().setValue(srcText);
}

function getSourceCode(){
return progEditor.getSession().getValue();
}

function getBinder(){
return document.getElementById("binder").value;
}

/*******************************************************************************/
/************** Loading Files **************************************************/
/*******************************************************************************/
Expand All @@ -240,10 +251,10 @@ function fileText(file, k){
function loadLocalFile($scope, file){
if (window.File && window.FileList && window.FileReader && file) {
if (file.type.match('text')) {
fileText(file, function(srcText){
setSourceCode($scope, file.name, srcText);
fileText(file, function(srcText){
setSourceCode($scope, file.name, srcText);
});
} else {
} else {
alert("Can only load text files.");
}
} else {
Expand All @@ -256,18 +267,18 @@ function loadLocalFile($scope, file){
/** Extracting JSON Results ****************************************************/
/*******************************************************************************/

function getResult(d) {
function getResult(d) {
var res = "crash";
if (d) {
res = d.status;
res = d.status;
}
return res;
}

function getWarns(d){
function getWarns(d){
var ws = [];
if (d && d.errors){
var ws = d.errors.map(function(x){
var ws = d.errors.map(function(x){
return x.message;
});
}
Expand All @@ -290,7 +301,7 @@ var debugZ = null;
function LiquidDemoCtrl($scope, $http, $location) {

// Start in non-fullscreen
$scope.isFullScreen = false;
$scope.isFullScreen = false;
$scope.embiggen = "FullScreen";
$scope.demoTitle = demoTitle;
$scope.demoSubtitle = demoSubtitle;
Expand All @@ -310,54 +321,54 @@ function LiquidDemoCtrl($scope, $http, $location) {
};

// LOAD a file from disk (only when isLocalServer)
$scope.loadFromLocalPath = function(){
$scope.loadFromLocalPath = function(){
var srcName = $scope.localFilePath;
if (srcName){
// alert('so you want to load' + $scope.localFilePath);
// alert('so you want to load' + $scope.localFilePath);
$http.post(getQueryURL(), getLoadQuery($scope))
.success(function(data, status){
debugData = data;
if (data.program) {
if (data.program) {
setSourceCode($scope, srcName, data.program);
} else if (data.error) {
alert("Load Error " + data.error);
alert("Load Error " + data.error);
} else {
alert("Horrors: Load Failed! " + srcName);
alert("Horrors: Load Failed! " + srcName);
}
})
.error(function(data, status){
alert("Load Error: No response for " + srcName);
alert("Load Error: No response for " + srcName);
});
}
};

// SAVE a file to disk (only when isLocalServer)
$scope.saveToLocalPath = function(){
$scope.saveToLocalPath = function(){
var srcName = $scope.localFilePath;
//alert('so you want to save ' + $scope.localFilePath);
//alert('so you want to save ' + $scope.localFilePath);
if (srcName) {
$http.post(getQueryURL(), getSaveQuery($scope))
.success(function(data, status){
debugData = data;
if (data.path){
alert("Saved.");
alert("Saved.");
} else {
alert("Save Unsuccessful: " + data);
}
})
.error(function(data, status){
alert("Save Failed: " + data);
alert("Save Failed: " + data);
});
}
};

// Clear Status when editor is changed
progEditor.on("change", function(e){
progEditor.on("change", function(e){
$scope.$apply(function(){
clearStatus($scope);
});
});


// Load a particular demo
$scope.loadSource = function(demo){
Expand All @@ -375,7 +386,7 @@ function LiquidDemoCtrl($scope, $http, $location) {
debugDemo = getDefaultDemo();
$scope.loadSource(debugDemo); //getDefaultDemo());

// Extract demo name from URL
// Extract demo name from URL
$scope.$watch('location.search()', function() {
// debugZ = ($location.search()).demo;
$scope.demoName = ($location.search()).demo;
Expand All @@ -386,12 +397,12 @@ function LiquidDemoCtrl($scope, $http, $location) {
$scope.loadSource(newDemo);
}, true);

// Update demo name in URL
// Update demo name in URL
$scope.changeTarget = function(demo) {
$location.search('demo', demo.file);
$scope.loadSource(demo);
};

// Change editor keybindings
$scope.keyBindingsNone = function (){ progEditor.setKeyboardHandler(null); };
$scope.keyBindingsVim = function (){ progEditor.setKeyboardHandler("ace/keyboard/vim"); };
Expand All @@ -405,44 +416,63 @@ function LiquidDemoCtrl($scope, $http, $location) {
debugData = data;
$scope.changeTarget({file : data.path});
} else {
alert("Permalink did not return link: " + data);
alert("Permalink did not return link: " + data);
}
})
.error(function(data, status){
alert("Permalink Failed: " + status);
alert("Permalink Failed: " + status);
});
};


// http://www.cleverweb.nl/javascript/a-simple-search-with-angularjs-and-php/
function verifyQuery(query){
function verifyQuery(query){
debugQuery = query;
setStatusChecking($scope);
$http.post(getQueryURL(), query)
.success(function(data, status) {
debugResp = debugResp + 1;
debugResp = debugResp + 1;
$scope.status = status;
debugData = data;
$scope.warns = getWarns(data);
$scope.warns = getWarns(data);
$scope.annotHtml = data.annotHtml;
$scope.result = setStatusResult($scope, data);

// This may be "null" if liquid crashed...
if (data) {
if (data) {
setAnnots(data.types);
setErrors(progEditor, data.errors);
};

})
.error(function(data, status) {
var msg = (data || "Request failed") + status;
alert(msg);
});
};


function testQuery(query){
debugQuery = query;
setStatusChecking($scope);
$http.post(getQueryURL(), query)
.success(function(data, status) {
debugResp = debugResp + 1;
$scope.status = status;
debugData = data;
$scope.result = setStatusResult($scope, data);
$scope.warns = [data.message];

})
.error(function(data, status) {
var msg = (data || "Request failed") + status;
alert(msg);
});
};

$scope.verifySource = function(){ verifyQuery(getCheckQuery($scope)); };
$scope.reVerifySource = function(){ verifyQuery(getRecheckQuery($scope)); };

$scope.testSource = function(){ testQuery(getTestQuery($scope)); };

}

/************************************************************************/
Expand Down
Loading