From b4a06eaf85de0404f367772b5ddd90047d019936 Mon Sep 17 00:00:00 2001 From: Masahiro Wakame Date: Tue, 26 Nov 2013 16:28:31 +0900 Subject: [PATCH] Add riotjs.d.ts and riotjs-render.d.ts --- README.md | 1 + riotjs/riotjs-render.d.ts | 10 ++ riotjs/riotjs-test.ts | 203 ++++++++++++++++++++++++++++++++++++++ riotjs/riotjs.d.ts | 12 +++ 4 files changed, 226 insertions(+) create mode 100644 riotjs/riotjs-render.d.ts create mode 100644 riotjs/riotjs-test.ts create mode 100644 riotjs/riotjs.d.ts diff --git a/README.md b/README.md index 84295923b..f696eab97 100755 --- a/README.md +++ b/README.md @@ -194,6 +194,7 @@ List of Definitions * [QUnit](http://qunitjs.com/) (by [Diullei Gomes](https://github.com/Diullei)) * [Raven.js](https://github.com/getsentry/raven-js) (by [Santi Albo](https://github.com/santialbo)) * [Rickshaw](http://code.shutterstock.com/rickshaw/) (by [Blake Niemyjski](https://github.com/niemyjski)) +* [Riot.js](https://github.com/moot/riotjs) (by [vvakame](https://github.com/vvakame)) * [Restify](https://github.com/mcavage/node-restify) (by [Bret Little](https://github.com/blittle)) * [Royalslider](http://dimsemenov.com/plugins/royal-slider/) (by [Christiaan Rakowski](https://github.com/csrakowski)) * [Rx.js](http://rx.codeplex.com/) (by [gsino](http://www.codeplex.com/site/users/view/gsino)) diff --git a/riotjs/riotjs-render.d.ts b/riotjs/riotjs-render.d.ts new file mode 100644 index 000000000..fe6cf84dc --- /dev/null +++ b/riotjs/riotjs-render.d.ts @@ -0,0 +1,10 @@ +// Type definitions for riot.js (ext/render.js) +// Project: https://github.com/moot/riotjs +// Definitions by: vvakame +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +interface JQueryStatic { + render(template?:string, data?:any):string; +} diff --git a/riotjs/riotjs-test.ts b/riotjs/riotjs-test.ts new file mode 100644 index 000000000..2dbd723fa --- /dev/null +++ b/riotjs/riotjs-test.ts @@ -0,0 +1,203 @@ +/// +/// + +function describe(msg:any, fn:Function) { + if (console.group) { + console.group(msg); + fn(); + console.groupEnd(); + } else { + console.info("---" + msg + "---"); + fn(); + } +} + +function it(msg:any, fn:Function) { + try { + fn(); + console.log(msg); + } catch (err) { + console.error(msg, err); + } +} + +interface RiotAssert { + (ok:any, msg?:any):void; + equal(value:any, expected:any):void; +} + +var assert:RiotAssert; + +/* +function assert(ok, msg) { + if (!ok) throw (msg || "fails"); +} + +assert.equal = function (value, expected) { + assert(value === expected, value + " != " + expected); +}; +*/ + +describe("Observable", function () { + + var el = $.observable({}), + total = 11, + count = 0; + + it("Single listener", function () { + + el.on("a", function (arg:any) { + assert.equal(arg, true) + count++; + }); + + el.trigger("a", true); + + }) + + it("Multiple listeners", function () { + + var counter = 0; + + el.on("b c d", function (e:any) { + if (++counter == 3) assert.equal(e, "d") + count++; + }) + + el.one("d", function (a:any) { + assert.equal(a, true) + count++; + }) + + el.trigger("b").trigger("c").trigger("d", true); + + }) + + it("One", function () { + + var counter = 0; + + el.one("g", function () { + assert.equal(++counter, 1); + count++; + }) + + el.trigger("g").trigger("g"); + }) + + it("One & on", function () { + + var counter = 0; + + el.one("y",function () { + count++; + counter++; + + }).on("y",function () { + count++; + counter++; + + }).trigger("y").trigger("y"); + + assert.equal(counter, 3); + + }) + + + it("Remove listeners", function () { + + var counter = 0; + + function r() { + assert.equal(++counter, 1); + count++; + } + + el.on("r", r).on("s", r).off("s", r).trigger("r").trigger("s"); + + }) + + it("Remove multiple listeners", function () { + + var counter = 0; + + function fn() { + counter++; + } + + el.on("a1 b1", fn).on("c1", fn).off("a1 b1").off("c1").trigger("a1").trigger("b1").trigger("c1"); + + assert.equal(counter, 0); + + }) + + + it("Multiple arguments", function () { + + el.on("j", function (a:any, b:any) { + assert.equal(a, 1); + assert.equal(b[0], 2); + count++; + }) + + el.trigger("j", 1, [2]); + + }) + + assert.equal(total, count) + +}); + +describe("$.render", function () { + + it("Single token", function () { + assert.equal($.render("x"), "x"); + assert.equal($.render("x", {}), "x"); + assert.equal($.render("{x}", { x: "x" }), "x"); + assert.equal($.render("{x}", { x: "z" }), "z"); + }); + + it("Multiple tokens", function () { + assert($.render("{x}{y}", { x: "x", y: "y" }) == "xy"); + }); + + it("Single quotes", function () { + assert.equal($.render("'x'"), "'x'"); + assert.equal($.render("\'x.\';"), "\'x.\';"); + }); + + it("Empty value", function () { + assert.equal($.render("{x}", { x: undefined }), ""); + assert.equal($.render("{x}", { x: null }), ""); + assert.equal($.render("{x}", { x: false }), "false"); + assert.equal($.render("{x}", { x: 0 }), "0"); + }); + + it("With spaces", function () { + assert.equal($.render("{ x }", { x: 'x' }), "x"); + assert.equal($.render("{x }", { x: 'x' }), "x"); + assert.equal($.render("{ x}", { x: 'x' }), "x"); + assert.equal($.render("{ x }", { x: 'x' }), "x"); + }); + + it("Empty template", function () { + assert($.render() === ""); + }) + + it("Nearby brackets", function () { + assert.equal($.render("{{x}", { x: 'x' }), "{x"); + assert.equal($.render("{x}}", { x: 'x' }), "x}"); + assert.equal($.render("{{x}}", { x: 'x' }), "{x}"); + }); + + it("