f6008d52f91f566ea37566b70f8ca35d4a44f89c
[platform/framework/web/crosswalk-tizen.git] /
1 /*
2   Copyright (C) 2014 Yusuke Suzuki <utatane.tea@gmail.com>
3
4   Redistribution and use in source and binary forms, with or without
5   modification, are permitted provided that the following conditions are met:
6
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above copyright
10       notice, this list of conditions and the following disclaimer in the
11       documentation and/or other materials provided with the distribution.
12
13   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16   ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
17   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24 /*global require describe it*/
25 /*jslint node:true */
26 'use strict';
27
28 var fs = require('fs'),
29     path = require('path'),
30     root = path.join(path.dirname(fs.realpathSync(__filename)), '..'),
31     doctrine = require(root);
32 require('should');
33
34 describe('strict parse', function () {
35     // https://github.com/Constellation/doctrine/issues/21
36     it('unbalanced braces', function () {
37         (function () {
38             doctrine.parse(
39                 [
40                     "/**",
41                     " * @param {const",
42                     " */"
43                 ].join('\n'), { unwrap: true, strict: true });
44         }).should.throw('Braces are not balanced');
45
46         (function () {
47             doctrine.parse(
48                 [
49                     "/**",
50                     " * @param {const",
51                     " */"
52                 ].join('\n'), { unwrap: true });
53         }).should.not.throw();
54
55         (function () {
56             doctrine.parse(
57                 [
58                     "/**",
59                     " * Description",
60                     " * @param {string name Param description",
61                     " * @param {int} foo Bar",
62                     " */"
63                 ].join('\n'), { unwrap: true, strict: true });
64         }).should.throw('Braces are not balanced');
65
66         (function () {
67             doctrine.parse(
68                 [
69                     "/**",
70                     " * Description",
71                     " * @param {string name Param description",
72                     " * @param {int} foo Bar",
73                     " */"
74                 ].join('\n'), { unwrap: true });
75         }).should.not.throw();
76
77         (function () {
78             doctrine.parse(
79                 [
80                     "/**",
81                     " * Description",
82                     " * @returns {int",
83                     " */"
84                 ].join('\n'), { unwrap: true, strict: true });
85         }).should.throw('Braces are not balanced');
86
87         (function () {
88             doctrine.parse(
89                 [
90                     "/**",
91                     " * Description",
92                     " * @returns {int",
93                     " */"
94                 ].join('\n'), { unwrap: true });
95         }).should.not.throw();
96     });
97
98     // https://github.com/Constellation/doctrine/issues/21
99     it('incorrect tag starting with @@', function () {
100         (function () {
101             doctrine.parse(
102                 [
103                     "/**",
104                     " * @@version",
105                     " */"
106                 ].join('\n'), { unwrap: true, strict: true });
107         }).should.throw('Missing or invalid title');
108
109         (function () {
110             doctrine.parse(
111                 [
112                     "/**",
113                     " * @@version",
114                     " */"
115                 ].join('\n'), { unwrap: true });
116         }).should.not.throw();
117
118         (function () {
119             doctrine.parse(
120                 [
121                     "/**",
122                     " * Description",
123                     " * @@param {string} name Param description",
124                     " */"
125                 ].join('\n'), { unwrap: true, strict: true });
126         }).should.throw('Missing or invalid title');
127
128         (function () {
129             doctrine.parse(
130                 [
131                     "/**",
132                     " * Description",
133                     " * @@param {string} name Param description",
134                     " */"
135                 ].join('\n'), { unwrap: true });
136         }).should.not.throw();
137
138         (function () {
139             doctrine.parse(
140                 [
141                     "/**",
142                     " * Description",
143                     " * @kind ng",
144                     " */"
145                 ].join('\n'), { unwrap: true, strict: true });
146         }).should.throw('Invalid kind name \'ng\'');
147
148         (function () {
149             doctrine.parse(
150                 [
151                     "/**",
152                     " * Description",
153                     " * @variation Animation",
154                     " */"
155                 ].join('\n'), { unwrap: true, strict: true });
156         }).should.throw('Invalid variation \'Animation\'');
157
158         (function () {
159             doctrine.parse(
160                 [
161                     "/**",
162                     " * Description",
163                     " * @access ng",
164                     " */"
165                 ].join('\n'), { unwrap: true, strict: true });
166         }).should.throw('Invalid access name \'ng\'');
167     });
168 });