Permalink
Browse files

[chenjia] - add es6 test

  • Loading branch information...
1 parent 33e5698 commit 940c64d0b89763a5644ceb2c17bb2ae28950df54 @ariesjia committed Jan 30, 2016
Showing with 149 additions and 40 deletions.
  1. +10 −3 Gruntfile.js
  2. +1 −1 package.json
  3. +2 −2 test/expected/concatFile.js
  4. +33 −0 test/expected/es6.js
  5. +30 −0 test/fixtures/es6.tag
  6. +1 −1 test/fixtures/test.tag
  7. +37 −31 test/riot_test.js
  8. +2 −2 test/tmp/concatFile.js
  9. +33 −0 test/tmp/es6.js
View
@@ -37,8 +37,15 @@ module.exports = function (grunt) {
options: {
concat: true
},
- src: 'test/fixtures/*.tag',
+ src: ['test/fixtures/test.tag','test/fixtures/todo.tag'],
dest: 'test/tmp/concatFile.js'
+ },
+ es6: {
+ options: {
+ concat: true
+ },
+ src: 'test/fixtures/es6.tag',
+ dest: 'test/tmp/es6.js'
}
},
@@ -53,9 +60,9 @@ module.exports = function (grunt) {
// Whenever the "test" task is run, first clean the "tmp" dir, then run this
// plugin's task(s), then test the result.
- grunt.registerTask('test', ['clean', 'riot:compile', 'nodeunit']);
+ grunt.registerTask('test', ['clean', 'riot', 'nodeunit']);
- grunt.registerTask('compile', ['riot:compile']);
+ grunt.registerTask('compile', ['riot']);
// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test', 'clean']);
View
@@ -1,6 +1,6 @@
{
"name": "grunt-riot",
- "version": "0.1.5",
+ "version": "0.1.6",
"description": "riot custom tag compile grunt plugin.",
"repository": "https://github.com/ariesjia/grunt-riot",
"author": {
@@ -1,6 +1,6 @@
-riot.tag2('test', '<h3>{this is a test file}</h3>', '', '', function(opts) {
+riot.tag2('test', '<h3>this is a test file</h3>', '', '', function(opts) {
console.log('test')
-}, '{ }');
+});
riot.tag2('todo', '<h3>{opts.title}</h3><ul><li each="{items}"><label class="{completed: done}"><input type="checkbox" __checked="{done}" onclick="{parent.toggle}"> {title} </label></li></ul><form onsubmit="{add}"><input name="input" onkeyup="{edit}"><button __disabled="{!text}">Add #{items.length + 1}</button></form>', '', '', function(opts) {
this.disabled = true
View
@@ -0,0 +1,33 @@
+riot.tag2('test', '<h3>{text} {name} {point}</h3>', '', '', function(opts) {
+var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
+
+var text = "HELLO";
+
+var name = (function () {
+ return 'WORLD';
+})();
+
+var Point = (function () {
+ function Point(x, y) {
+ _classCallCheck(this, Point);
+
+ this.x = x;
+ this.y = y;
+ }
+
+ _createClass(Point, [{
+ key: 'toString',
+ value: function toString() {
+ return '(' + this.x + ', ' + this.y + ')';
+ }
+ }]);
+
+ return Point;
+})();
+
+this.text = text;
+this.name = name;
+this.point = new Point(1, 1).toString();
+}, '{ }');
View
@@ -0,0 +1,30 @@
+<test>
+
+ <h3>{text} {name} {point}</h3>
+
+ <script type="es6">
+
+ const text = "HELLO"
+
+ const name = ()=>{
+ return 'WORLD';
+ }();
+
+ class Point {
+ constructor(x, y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ toString() {
+ return '(' + this.x + ', ' + this.y + ')';
+ }
+ }
+
+ this.text = text;
+ this.name = name;
+ this.point = (new Point(1,1)).toString()
+
+ </script>
+
+</test>
@@ -1,6 +1,6 @@
<test>
- <h3>{ this is a test file }</h3>
+ <h3>this is a test file</h3>
<script>
console.log('test')
View
@@ -3,42 +3,48 @@
var grunt = require('grunt');
/*
- ======== A Handy Little Nodeunit Reference ========
- https://github.com/caolan/nodeunit
+ ======== A Handy Little Nodeunit Reference ========
+ https://github.com/caolan/nodeunit
- Test methods:
- test.expect(numAssertions)
- test.done()
- Test assertions:
- test.ok(value, [message])
- test.equal(actual, expected, [message])
- test.notEqual(actual, expected, [message])
- test.deepEqual(actual, expected, [message])
- test.notDeepEqual(actual, expected, [message])
- test.strictEqual(actual, expected, [message])
- test.notStrictEqual(actual, expected, [message])
- test.throws(block, [error], [message])
- test.doesNotThrow(block, [error], [message])
- test.ifError(value)
-*/
+ Test methods:
+ test.expect(numAssertions)
+ test.done()
+ Test assertions:
+ test.ok(value, [message])
+ test.equal(actual, expected, [message])
+ test.notEqual(actual, expected, [message])
+ test.deepEqual(actual, expected, [message])
+ test.notDeepEqual(actual, expected, [message])
+ test.strictEqual(actual, expected, [message])
+ test.notStrictEqual(actual, expected, [message])
+ test.throws(block, [error], [message])
+ test.doesNotThrow(block, [error], [message])
+ test.ifError(value)
+ */
-var cleanCode = function (str){
- return str.replace(/\ +/g,"")
- .replace(/[ ]/g,"")
- .replace(/[\r\n\t]/g,"");
+var cleanCode = function (str) {
+ return str.replace(/\ +/g, "")
+ .replace(/[ ]/g, "")
+ .replace(/[\r\n\t]/g, "");
};
exports.riot = {
- setUp: function (done) {
- // setup here if necessary
- done();
- },
- compile: function (test) {
- var actual = grunt.file.read('test/tmp/concatFile.js');
- var expected = grunt.file.read('test/expected/concatFile.js');
- test.equal(cleanCode(actual),cleanCode(expected));
- test.done();
- }
+ setUp: function (done) {
+ // setup here if necessary
+ done();
+ },
+ compile: function (test) {
+ var actual = grunt.file.read('test/tmp/concatFile.js');
+ var expected = grunt.file.read('test/expected/concatFile.js');
+ test.equal(cleanCode(actual), cleanCode(expected));
+ test.done();
+ },
+ es6: function (test) {
+ var actual = grunt.file.read('test/tmp/es6.js');
+ var expected = grunt.file.read('test/expected/es6.js');
+ test.equal(cleanCode(actual), cleanCode(expected));
+ test.done();
+ }
};
@@ -1,6 +1,6 @@
-riot.tag2('test', '<h3>{this is a test file}</h3>', '', '', function(opts) {
+riot.tag2('test', '<h3>this is a test file</h3>', '', '', function(opts) {
console.log('test')
-}, '{ }');
+});
riot.tag2('todo', '<h3>{opts.title}</h3><ul><li each="{items}"><label class="{completed: done}"><input type="checkbox" __checked="{done}" onclick="{parent.toggle}"> {title} </label></li></ul><form onsubmit="{add}"><input name="input" onkeyup="{edit}"><button __disabled="{!text}">Add #{items.length + 1}</button></form>', '', '', function(opts) {
this.disabled = true
View
@@ -0,0 +1,33 @@
+riot.tag2('test', '<h3>{text} {name} {point}</h3>', '', '', function(opts) {
+var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
+
+var text = "HELLO";
+
+var name = (function () {
+ return 'WORLD';
+})();
+
+var Point = (function () {
+ function Point(x, y) {
+ _classCallCheck(this, Point);
+
+ this.x = x;
+ this.y = y;
+ }
+
+ _createClass(Point, [{
+ key: 'toString',
+ value: function toString() {
+ return '(' + this.x + ', ' + this.y + ')';
+ }
+ }]);
+
+ return Point;
+})();
+
+this.text = text;
+this.name = name;
+this.point = new Point(1, 1).toString();
+}, '{ }');

0 comments on commit 940c64d

Please sign in to comment.