1 | "use strict";
|
2 |
|
3 | var Util = require("../lib/boilerplate.util");
|
4 |
|
5 |
|
6 | describe('Module boilerplate.util', function() {
|
7 | describe('Function generateCode()', function() {
|
8 | [
|
9 | [["a"], "a"],
|
10 | [["a",["b","c"],"d"], "a\n b\n c\nd"],
|
11 | [["a",["b",["c"]],"d"], "a\n b\n c\nd"],
|
12 | [["a"], "a", ' ', ''],
|
13 | [["a",["b","c"],"d"], "a\n b\n c\nd", ' ', ''],
|
14 | [["a",["b",["c"]],"d"], "a\n b\n c\nd", ' ', '']
|
15 | ].forEach(function (item) {
|
16 | var input = item[0];
|
17 | var expected = item[1];
|
18 | var indentIncrement = item[2];
|
19 | var currentIndent = item[3];
|
20 | it('should work for "' + JSON.stringify(input) + '"', function(){
|
21 | var output = Util.generateCode( input, indentIncrement, currentIndent );
|
22 | if( output !== expected ) {
|
23 | fail("\nExpected:\n" + expected + "\nBut found:\n" + output );
|
24 | }
|
25 | });
|
26 | });
|
27 | });
|
28 |
|
29 | describe('Function isJavascriptIdentifier()', function() {
|
30 | ["foo", "bar", "$", "_", "jedi26", "jedi_26", "Crum$ble"].forEach(function (name) {
|
31 | it( `"${name}" should return true`, function() {
|
32 | expect( Util.isJavascriptIdentifier( name ) ).toBe( true );
|
33 | });
|
34 | });
|
35 | ["!foo", "", "bar.", "garçon", "2hip"].forEach(function (name) {
|
36 | it( `"${name}" should return false`, function() {
|
37 | expect( Util.isJavascriptIdentifier( name ) ).toBe( false );
|
38 | });
|
39 | });
|
40 | });
|
41 |
|
42 | describe('Function att()', function() {
|
43 | [
|
44 | ["toto", ".toto"],
|
45 | ["foo-bar", "[\"foo-bar\"]"],
|
46 | [27, "[27]"]
|
47 | ].forEach(function (testCase) {
|
48 | var inp = testCase[0];
|
49 | var exp = testCase[1];
|
50 | it(`att("${inp}") should return "${exp}"`, function() {
|
51 | expect( Util.att( inp ) ).toBe( exp );
|
52 | });
|
53 | });
|
54 | });
|
55 |
|
56 | describe('Function isSpecial()', function() {
|
57 | [
|
58 | {toto: 666, 0: "a"},
|
59 | {toto: 666, "0": "a"},
|
60 | {0: "yop"}
|
61 | ].forEach(function (obj) {
|
62 | it('should return `true` for ' + JSON.stringify(obj), function(){
|
63 | expect( Util.isSpecial( obj ) ).toBe( true );
|
64 | });
|
65 | });
|
66 |
|
67 | [
|
68 | [{toto: 666, 0: "a"}, 'a'],
|
69 | [{toto: 666, "0": "a"}, 'A'],
|
70 | [{0: "yop"}, 'yop'],
|
71 | [{0: "yop"}, 'YOP'],
|
72 | [{0: "yop"}, 'yoP']
|
73 | ].forEach(function (item) {
|
74 | var obj = item[0];
|
75 | var expectedName = item[1];
|
76 | it('should return `true` when expectedName passed, for ' + JSON.stringify(obj), function(){
|
77 | expect( Util.isSpecial( obj, expectedName ) ).toBe( true );
|
78 | });
|
79 | });
|
80 |
|
81 | [
|
82 | {toto: 666, "1": "a"},
|
83 | {toto: 666},
|
84 | {bill: {0: "yop"}}
|
85 | ].forEach(function (obj) {
|
86 | it('should return `false` for ' + JSON.stringify(obj), function(){
|
87 | expect( Util.isSpecial( obj ) ).toBe( false );
|
88 | });
|
89 | });
|
90 | });
|
91 |
|
92 | describe('Function cap()', function() {
|
93 | [
|
94 | [666, 666],
|
95 | [[666, "q"]],
|
96 | ["h", "H"],
|
97 | ["W", "W"],
|
98 | ["", ""],
|
99 | ["paRis", "Paris"],
|
100 | ["paris", "Paris"]
|
101 | ].forEach(function (item) {
|
102 | var input = item[0];
|
103 | var expected = item[1];
|
104 | if( typeof expected === 'undefined' ) expected = input;
|
105 | it('"' + input + '" should return "' + expected + "'", function(){
|
106 | expect( Util.cap( input ) ).toBe( expected );
|
107 | });
|
108 | });
|
109 | });
|
110 |
|
111 | describe('Function camel()', function() {
|
112 | [
|
113 | ["John", "john"],
|
114 | ["super-bad-guy", "superBadGuy"],
|
115 | ["SUPER-bad-guy", "superBadGuy"],
|
116 | ["super-BAD-guy", "superBadGuy"],
|
117 | ["Super-bad-guy", "superBadGuy"],
|
118 | ["suPEr-bad-guy", "superBadGuy"],
|
119 | ["", ""]
|
120 | ].forEach(function (item) {
|
121 | var input = item[0];
|
122 | var expected = item[1];
|
123 | if( typeof expected === 'undefined' ) expected = input;
|
124 | it('"' + input + '" should return "' + expected + "'", function(){
|
125 | expect( Util.camel( input ) ).toBe( expected );
|
126 | });
|
127 | });
|
128 | });
|
129 | });
|