-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add eslint. and pass test files, karma confand grunt through it
- Loading branch information
Showing
13 changed files
with
444 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"root": true, | ||
"extends": "standard", | ||
"env": { | ||
"es6": false, | ||
"node": true, | ||
"amd": true, | ||
"browser": true | ||
}, | ||
"globals": { | ||
"expect": true, | ||
"getData": true | ||
}, | ||
"rules": { | ||
"new-cap": ["error", { "newIsCapExceptions": ["jSmart"] }] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"root": true, | ||
"extends": "../.eslintrc.json", | ||
"env": { | ||
"mocha": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,62 @@ | ||
define(['jSmart', 'text!./templates/var.tpl', 'text!./output/var.tpl'], function(jSmart, smartyTpl, outputTpl) { | ||
jSmart.prototype.registerPlugin( | ||
'function', | ||
'sayHello', | ||
function (params, data) { | ||
var s = 'Hello '; | ||
s += params.to; | ||
return s; | ||
} | ||
); | ||
|
||
describe("Test Syntax", function() { | ||
|
||
it("test plain text", function() { | ||
var t = new jSmart('Hello world'); | ||
expect(t.fetch()).toBe('Hello world'); | ||
}); | ||
|
||
it("test variable", function() { | ||
var t = new jSmart('Hello {$name}, how are you?'); | ||
expect(t.fetch({name: 'world'})).toBe('Hello world, how are you?'); | ||
}); | ||
|
||
it("test array/object variable", function() { | ||
// Objects. | ||
var t = new jSmart('1. Hello {$user.name.first}, how are you?'); | ||
expect(t.fetch({user: {name: { first: 'Uma'}}})).toBe('1. Hello Uma, how are you?'); | ||
|
||
// Arrays. | ||
var t = new jSmart("2. Hello {$user['name']['first']}, how are you?"); | ||
expect(t.fetch({user: {name: { first: 'Uma'}}})).toBe('2. Hello Uma, how are you?'); | ||
|
||
// Objects. | ||
var t = new jSmart("3. Hello {$user->name->first}, how are you?"); | ||
expect(t.fetch({user: {name: { first: 'Uma'}}})).toBe('3. Hello Uma, how are you?'); | ||
}); | ||
|
||
it("test comment", function() { | ||
var t = new jSmart('Testing {*comments yo *}, does it work?'); | ||
expect(t.fetch()).toBe('Testing , does it work?'); | ||
}); | ||
|
||
it("test assigning variable", function() { | ||
var t = new jSmart("{$foo = 'bar'} print foo {$foo}"); | ||
expect(t.fetch()).toBe(' print foo bar'); | ||
}); | ||
|
||
it("test double quotes strings", function() { | ||
var t = new jSmart('{$foo="bar"} {$bar = "value of foo is \'$foo\'"} {$bar}'); | ||
expect(t.fetch()).toBe(" value of foo is 'bar'"); | ||
|
||
// back tick test. | ||
var t = new jSmart('{$foo = "`$person.name.first` has `$person[\'favorite gadget\']`"} {$foo}'); | ||
expect(t.fetch({person: {name: {first: 'Umakant'}, 'favorite gadget': 'ipad'}})).toBe(" Umakant has ipad"); | ||
}); | ||
|
||
it("test complex template", function() { | ||
// Insert complex statements in the template and test them. | ||
var t = new jSmart(smartyTpl); | ||
expect(t.fetch(getData())).toBe(outputTpl); | ||
}); | ||
}); | ||
}); | ||
define(['jSmart', 'text!./templates/var.tpl', 'text!./output/var.tpl'], function (jSmart, smartyTpl, outputTpl) { | ||
jSmart.prototype.registerPlugin( | ||
'function', | ||
'sayHello', | ||
function (params, data) { | ||
var s = 'Hello ' | ||
s += params.to | ||
return s | ||
} | ||
) | ||
|
||
describe('Test Syntax', function () { | ||
it('test plain text', function () { | ||
var t = new jSmart('Hello world') | ||
expect(t.fetch()).toBe('Hello world') | ||
}) | ||
|
||
it('test variable', function () { | ||
var t = new jSmart('Hello {$name}, how are you?') | ||
expect(t.fetch({name: 'world'})).toBe('Hello world, how are you?') | ||
}) | ||
|
||
it('test array/object variable', function () { | ||
// Objects. | ||
var t = new jSmart('1. Hello {$user.name.first}, how are you?') | ||
expect(t.fetch({user: {name: {first: 'Uma'}}})).toBe('1. Hello Uma, how are you?') | ||
|
||
// Arrays. | ||
t = new jSmart("2. Hello {$user['name']['first']}, how are you?") | ||
expect(t.fetch({user: {name: {first: 'Uma'}}})).toBe('2. Hello Uma, how are you?') | ||
|
||
// Objects. | ||
t = new jSmart('3. Hello {$user->name->first}, how are you?') | ||
expect(t.fetch({user: {name: {first: 'Uma'}}})).toBe('3. Hello Uma, how are you?') | ||
}) | ||
|
||
it('test comment', function () { | ||
var t = new jSmart('Testing {*comments yo *}, does it work?') | ||
expect(t.fetch()).toBe('Testing , does it work?') | ||
}) | ||
|
||
it('test assigning variable', function () { | ||
var t = new jSmart("{$foo = 'bar'} print foo {$foo}") | ||
expect(t.fetch()).toBe(' print foo bar') | ||
}) | ||
|
||
it('test double quotes strings', function () { | ||
var t = new jSmart('{$foo="bar"} {$bar = "value of foo is \'$foo\'"} {$bar}') | ||
expect(t.fetch()).toBe(" value of foo is 'bar'") | ||
|
||
// back tick test. | ||
t = new jSmart('{$foo = "`$person.name.first` has `$person[\'favorite gadget\']`"} {$foo}') | ||
expect(t.fetch({person: {name: {first: 'Umakant'}, 'favorite gadget': 'ipad'}})).toBe(' Umakant has ipad') | ||
}) | ||
|
||
it('test complex template', function () { | ||
// Insert complex statements in the template and test them. | ||
var t = new jSmart(smartyTpl) | ||
expect(t.fetch(getData())).toBe(outputTpl) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.