Skip to content

Commit

Permalink
automatically load sample names for the compiler tests
Browse files Browse the repository at this point in the history
Closes #75
  • Loading branch information
PK1A committed Feb 25, 2014
1 parent 917a580 commit dbe3402
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 33 deletions.
9 changes: 8 additions & 1 deletion public/test/compiler/errsamples/block.txt
Expand Up @@ -4,4 +4,11 @@
# /template

##### Errors:

[
{
"description": "Invalid expression",
"line": 2,
"column": 5,
"code": "foo bar"
}
]
13 changes: 6 additions & 7 deletions public/test/compiler/errtests.js
Expand Up @@ -20,11 +20,11 @@ describe('Template compilation errors: ', function () {
}
};

var samples = ["text1", "text2", "text3", "if1", "if2", "if3", "if4", "if5", "if6", "if7", "foreach1", "foreach2",
"foreach3", "element1", "element2", "element3", "element4", "element5", "element6", "element7", "element8",
"insert", "template1", "template2", "template3", "template4", "template5", "template6", "template7",
"jsexpression1", "jsexpression2", "component1", "component2", "voidelement"];
//samples=["voidelement"];
var samples = ut.getSampleNames(__dirname + "/errsamples").filter(function(name){
return name.substr(0, 5) != 'mixed';
});
//samples=["component2"];

for (var i = 0, sz = samples.length; sz > i; i++) {
// create one test for each sample
it('tests error sample ('+samples[i]+')', testFn.bind({
Expand Down Expand Up @@ -52,8 +52,7 @@ describe('Template compilation errors: ', function () {
it('tests mixed errors in template and JS script 2', function () {
var sample = ut.getErrorSampleContent("mixed2");
var r = compiler.compile(sample.template, "mixed2");

assert.equal(r.errors[0].line, 1, "error line 1");
assert.equal(r.errors[0].line, 1, "error line 1");
});

it('tests mixed errors in template and JS script 3', function () {
Expand Down
68 changes: 49 additions & 19 deletions public/test/compiler/samples/text4.txt
Expand Up @@ -8,47 +8,77 @@
{
"type": "template",
"name": "hello",
"args": [ "name"],
"mod": "",
"args": [
"name"
],
"content": [
{
"type": "text", "value": "Hello "
},{
{
"type": "text",
"value": "Hello "
},
{
"type": "expression",
"category": "objectref",
"bound": true,
"path": [ "name" ]
"name": "name",
"code": "name",
"category": "jsexpression",
"expType": "Variable",
"bound": true
},
{
"type": "text",
"value": "!",
}
]
],
"closed": true
},
{
"type": "plaintext",
"value": "\r\n"
}
]

##### Syntax Tree:

##### Syntax Tree:
[
{
"type": "template",
"name": "hello",
"args": ["name"],
"args": [
"name"
],
"export": false,
"content": [
{
"type": "textblock",
"content": [
{
"type": "text", "value": "Hello "
}, {
"type": "expression",
"category": "objectref",
"bound": true,
"path": [ "name" ]
}, {
"type": "text", "value": "!"
{
"type": "text",
"value": "Hello "
},
{
"type": "expression",
"category": "objectref",
"bound": true,
"path": [
"name"
]
},
{
"type": "text",
"value": "!"
}
]
}
]
},
{
"type": "plaintext",
"value": "\r\n"
}
]


##### Template Code
hello=[
n.$text({e1:[1,1,"name"]}, ["Hello ",1,"!"])
Expand Down
8 changes: 2 additions & 6 deletions public/test/compiler/tests.js
Expand Up @@ -87,12 +87,8 @@ describe('Block Parser: ', function () {
}
};

var samples = ["template1", "template2", "text1", "text2", "text3", "text5", "text6", "text7", "if1", "if2", "if3", "if4",
"comment", "foreach1", "foreach2", "foreach3", "element1", "element2", "element3", "element4", "element5",
"evthandler1", "evthandler2", "evthandler3", "component1", "component2", "component3", "component4",
"component5", "component6", "component7", "jsexpression1", "jsexpression2", "jsexpression3", "jsexpression4", "jsexpression5",
"class1", "class2", "class3", "class4", "insert1", "insert2", "log1", "log2", "voidelement"];
//samples=["voidelement"];
var samples = ut.getSampleNames(__dirname + "/samples");
//samples=["log2"];

for (var i = 0, sz = samples.length; sz > i; i++) {
// create one test for each sample
Expand Down
7 changes: 7 additions & 0 deletions public/test/compiler/utils/testutils.js
@@ -1,4 +1,5 @@
var fs = require("fs");
var path = require("path");

/**
* Return the template part of a template sample
Expand Down Expand Up @@ -27,6 +28,12 @@ exports.getSampleContent = function (sampleName) {
return res;
};

exports.getSampleNames = function (dir) {
return fs.readdirSync(dir).map(function(fileName){
return path.basename(fileName, '.txt');
});
};

/**
* Return the template part of a template sample
* @param {String} sampleName the sample name - e.g. "basic1"
Expand Down

0 comments on commit dbe3402

Please sign in to comment.