@@ -5,9 +5,16 @@ var assert = require('chai').assert;


var Base = require('../Base');
var factory = require('..' ).Component.Factory;
var QObject = Base.QObject;
var UIComponent = Base.Component.UIComponent;
//var Parser = require('parser');

var Parser = {
parse: function () {
}
};

describe("QScript parser", function () {
it("should build tree", function () {

@@ -52,7 +59,45 @@ describe("QScript parser", function () {
mustHaveTree.children[0].parent = mustHaveTree;
mustHaveTree.children[1].parent = mustHaveTree;

assert.deepEqual(resultTree, mustHaveTree);

var mustHaveTree2 = {
col: 1,
row: 1,
pureLine: 'div: 123\r\n',
type: 'Div',
ravLine: 'div: 123\r\n',
rawChildren: ' Button: a\r\n Button: b\r\n',
pureChildren: ' Button: a\r\n Button: b\r\n',
children: [
{
col: 3,
row: 2,
pureLine: 'Button: a\r\n',
type: 'Button',
ravLine: 'Button: a\r\n',
rawChildren: '',
pureChildren: '',
children: []
},
{
col: 3,
row: 3,
pureLine: 'Button: b\r\n',
type: 'Button',
ravLine: 'Button: b\r\n',
rawChildren: '',
pureChildren: '',
children: []
}
]
};

mustHaveTree2.children[0].parent = mustHaveTree2;
mustHaveTree2.children[1].parent = mustHaveTree2;


//assert.deepEqual(resultTree, mustHaveTree);
assert.deepEqual(mustHaveTree, mustHaveTree2);
});

it("should ignore comments", function () {
@@ -198,4 +243,76 @@ describe("QScript parser", function () {

assert.deepEqual(resultTree, mustHaveTree);
});


var f = new factory(), obj;
var document = require("dom-lite").document;
('a,b,big,br,button,canvas,center,div,dl,dt,em,embed,' +
'font,form,frame,h1,h2,h3,h4,h5,h6,i,iframe,img,' +
'input,label,li,ol,option,p,pre,span,sub,sup,' +
'table,tbody,td,textarea,th,thead,tr,u,ul,header')
.split(',')
.forEach(function (name) {
UIComponent.extend(name, {
createEl: function () {
this.el = document.createElement(name);
},
addToTree: function (child) {
//console.log(child)
child.el && (this.el || this.parent.el).appendChild(child.el);
//(this.el || this.parent.el).appendChild(document.createTextNode('84'))
},
preInit: function () {

if (this.value) {
this.textNode = f.build('textNode', {value: this.value});
this._children.unshift(this.textNode);
}

},
_setter: {
value: function (key, val) {
console.log(val)
this.textNode && (this.textNode.set('value', val));
}
}
});
});

UIComponent.extend('textNode', {
component: true,
_setter: {
value: function (key, val) {
this.el.nodeValue = val;
}
},
createEl: function () {
this.el = document.createTextNode('');
}
});

UIComponent.extend('Button', {
component: true,
_setter: {
value: function (key, val) {
this.el.nodeValue = val;
}
},
createEl: function () {
this.el = document.createTextNode('<button></button>');
}
});


it('should nests', function () {

var resultTree = Parser.parse('div: 123\n' +
' Button: a\r\n' +
' Button: b\n'
);

var newTree = Parser.doMagic(resultTree);

assert.equal(newTree.el.outerHTML, '<div><button>a</button><button>b</button></div>');
});
});
@@ -60,11 +60,10 @@ describe('DOM', function () {

}]
});
assert.equal( tree.el.outerHTML, '<h1><h2></h2><b></b><h1><b></b></h1></h1>' );
assert.equal( tree.el.outerHTML, '<h1><h2></h2><b></b><h1><b>10</b></h1></h1>' );
tree._children.get(2)._children.get(0).set('value',20);

var id = tree._children.get(2).id;
console.log(tree._children.get.id)
assert.equal( tree.el.outerHTML, '<h1><h2></h2><b></b><h1><b>20</b></h1></h1>' );
});


});