PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/node_modules/log4js/test/vows/levels-test.js

https://gitlab.com/alekhya484/example-project
JavaScript | 464 lines | 461 code | 3 blank | 0 comment | 0 complexity | 8ba99a22053c2dbe132119166ac983f6 MD5 | raw file
  1. "use strict";
  2. var vows = require('vows')
  3. , assert = require('assert')
  4. , levels = require('../../lib/levels');
  5. function assertThat(level) {
  6. function assertForEach(assertion, test, otherLevels) {
  7. otherLevels.forEach(function(other) {
  8. assertion.call(assert, test.call(level, other));
  9. });
  10. }
  11. return {
  12. isLessThanOrEqualTo: function(levels) {
  13. assertForEach(assert.isTrue, level.isLessThanOrEqualTo, levels);
  14. },
  15. isNotLessThanOrEqualTo: function(levels) {
  16. assertForEach(assert.isFalse, level.isLessThanOrEqualTo, levels);
  17. },
  18. isGreaterThanOrEqualTo: function(levels) {
  19. assertForEach(assert.isTrue, level.isGreaterThanOrEqualTo, levels);
  20. },
  21. isNotGreaterThanOrEqualTo: function(levels) {
  22. assertForEach(assert.isFalse, level.isGreaterThanOrEqualTo, levels);
  23. },
  24. isEqualTo: function(levels) {
  25. assertForEach(assert.isTrue, level.isEqualTo, levels);
  26. },
  27. isNotEqualTo: function(levels) {
  28. assertForEach(assert.isFalse, level.isEqualTo, levels);
  29. }
  30. };
  31. }
  32. vows.describe('levels').addBatch({
  33. 'values': {
  34. topic: levels,
  35. 'should define some levels': function(levels) {
  36. assert.isNotNull(levels.ALL);
  37. assert.isNotNull(levels.TRACE);
  38. assert.isNotNull(levels.DEBUG);
  39. assert.isNotNull(levels.INFO);
  40. assert.isNotNull(levels.WARN);
  41. assert.isNotNull(levels.ERROR);
  42. assert.isNotNull(levels.FATAL);
  43. assert.isNotNull(levels.MARK);
  44. assert.isNotNull(levels.OFF);
  45. },
  46. 'ALL': {
  47. topic: levels.ALL,
  48. 'should be less than the other levels': function(all) {
  49. assertThat(all).isLessThanOrEqualTo(
  50. [
  51. levels.ALL,
  52. levels.TRACE,
  53. levels.DEBUG,
  54. levels.INFO,
  55. levels.WARN,
  56. levels.ERROR,
  57. levels.FATAL,
  58. levels.MARK,
  59. levels.OFF
  60. ]
  61. );
  62. },
  63. 'should be greater than no levels': function(all) {
  64. assertThat(all).isNotGreaterThanOrEqualTo(
  65. [
  66. levels.TRACE,
  67. levels.DEBUG,
  68. levels.INFO,
  69. levels.WARN,
  70. levels.ERROR,
  71. levels.FATAL,
  72. levels.MARK,
  73. levels.OFF
  74. ]
  75. );
  76. },
  77. 'should only be equal to ALL': function(all) {
  78. assertThat(all).isEqualTo([levels.toLevel("ALL")]);
  79. assertThat(all).isNotEqualTo(
  80. [
  81. levels.TRACE,
  82. levels.DEBUG,
  83. levels.INFO,
  84. levels.WARN,
  85. levels.ERROR,
  86. levels.FATAL,
  87. levels.MARK,
  88. levels.OFF
  89. ]
  90. );
  91. }
  92. },
  93. 'TRACE': {
  94. topic: levels.TRACE,
  95. 'should be less than DEBUG': function(trace) {
  96. assertThat(trace).isLessThanOrEqualTo(
  97. [
  98. levels.DEBUG,
  99. levels.INFO,
  100. levels.WARN,
  101. levels.ERROR,
  102. levels.FATAL,
  103. levels.MARK,
  104. levels.OFF
  105. ]
  106. );
  107. assertThat(trace).isNotLessThanOrEqualTo([levels.ALL]);
  108. },
  109. 'should be greater than ALL': function(trace) {
  110. assertThat(trace).isGreaterThanOrEqualTo([levels.ALL, levels.TRACE]);
  111. assertThat(trace).isNotGreaterThanOrEqualTo(
  112. [
  113. levels.DEBUG,
  114. levels.INFO,
  115. levels.WARN,
  116. levels.ERROR,
  117. levels.FATAL,
  118. levels.MARK,
  119. levels.OFF
  120. ]
  121. );
  122. },
  123. 'should only be equal to TRACE': function(trace) {
  124. assertThat(trace).isEqualTo([levels.toLevel("TRACE")]);
  125. assertThat(trace).isNotEqualTo(
  126. [
  127. levels.ALL,
  128. levels.DEBUG,
  129. levels.INFO,
  130. levels.WARN,
  131. levels.ERROR,
  132. levels.FATAL,
  133. levels.MARK,
  134. levels.OFF
  135. ]
  136. );
  137. }
  138. },
  139. 'DEBUG': {
  140. topic: levels.DEBUG,
  141. 'should be less than INFO': function(debug) {
  142. assertThat(debug).isLessThanOrEqualTo(
  143. [
  144. levels.INFO,
  145. levels.WARN,
  146. levels.ERROR,
  147. levels.FATAL,
  148. levels.MARK,
  149. levels.OFF
  150. ]
  151. );
  152. assertThat(debug).isNotLessThanOrEqualTo([levels.ALL, levels.TRACE]);
  153. },
  154. 'should be greater than TRACE': function(debug) {
  155. assertThat(debug).isGreaterThanOrEqualTo([levels.ALL, levels.TRACE]);
  156. assertThat(debug).isNotGreaterThanOrEqualTo(
  157. [
  158. levels.INFO,
  159. levels.WARN,
  160. levels.ERROR,
  161. levels.FATAL,
  162. levels.MARK,
  163. levels.OFF
  164. ]
  165. );
  166. },
  167. 'should only be equal to DEBUG': function(trace) {
  168. assertThat(trace).isEqualTo([levels.toLevel("DEBUG")]);
  169. assertThat(trace).isNotEqualTo(
  170. [
  171. levels.ALL,
  172. levels.TRACE,
  173. levels.INFO,
  174. levels.WARN,
  175. levels.ERROR,
  176. levels.FATAL,
  177. levels.MARK,
  178. levels.OFF
  179. ]
  180. );
  181. }
  182. },
  183. 'INFO': {
  184. topic: levels.INFO,
  185. 'should be less than WARN': function(info) {
  186. assertThat(info).isLessThanOrEqualTo([
  187. levels.WARN,
  188. levels.ERROR,
  189. levels.FATAL,
  190. levels.MARK,
  191. levels.OFF
  192. ]);
  193. assertThat(info).isNotLessThanOrEqualTo([levels.ALL, levels.TRACE, levels.DEBUG]);
  194. },
  195. 'should be greater than DEBUG': function(info) {
  196. assertThat(info).isGreaterThanOrEqualTo([levels.ALL, levels.TRACE, levels.DEBUG]);
  197. assertThat(info).isNotGreaterThanOrEqualTo([
  198. levels.WARN,
  199. levels.ERROR,
  200. levels.FATAL,
  201. levels.MARK,
  202. levels.OFF
  203. ]);
  204. },
  205. 'should only be equal to INFO': function(trace) {
  206. assertThat(trace).isEqualTo([levels.toLevel("INFO")]);
  207. assertThat(trace).isNotEqualTo([
  208. levels.ALL,
  209. levels.TRACE,
  210. levels.DEBUG,
  211. levels.WARN,
  212. levels.ERROR,
  213. levels.FATAL,
  214. levels.MARK,
  215. levels.OFF
  216. ]);
  217. }
  218. },
  219. 'WARN': {
  220. topic: levels.WARN,
  221. 'should be less than ERROR': function(warn) {
  222. assertThat(warn).isLessThanOrEqualTo([levels.ERROR, levels.FATAL, levels.MARK, levels.OFF]);
  223. assertThat(warn).isNotLessThanOrEqualTo([
  224. levels.ALL,
  225. levels.TRACE,
  226. levels.DEBUG,
  227. levels.INFO
  228. ]);
  229. },
  230. 'should be greater than INFO': function(warn) {
  231. assertThat(warn).isGreaterThanOrEqualTo([
  232. levels.ALL,
  233. levels.TRACE,
  234. levels.DEBUG,
  235. levels.INFO
  236. ]);
  237. assertThat(warn).isNotGreaterThanOrEqualTo([
  238. levels.ERROR, levels.FATAL, levels.MARK, levels.OFF
  239. ]);
  240. },
  241. 'should only be equal to WARN': function(trace) {
  242. assertThat(trace).isEqualTo([levels.toLevel("WARN")]);
  243. assertThat(trace).isNotEqualTo([
  244. levels.ALL,
  245. levels.TRACE,
  246. levels.DEBUG,
  247. levels.INFO,
  248. levels.ERROR,
  249. levels.FATAL,
  250. levels.OFF
  251. ]);
  252. }
  253. },
  254. 'ERROR': {
  255. topic: levels.ERROR,
  256. 'should be less than FATAL': function(error) {
  257. assertThat(error).isLessThanOrEqualTo([levels.FATAL, levels.MARK, levels.OFF]);
  258. assertThat(error).isNotLessThanOrEqualTo([
  259. levels.ALL,
  260. levels.TRACE,
  261. levels.DEBUG,
  262. levels.INFO,
  263. levels.WARN
  264. ]);
  265. },
  266. 'should be greater than WARN': function(error) {
  267. assertThat(error).isGreaterThanOrEqualTo([
  268. levels.ALL,
  269. levels.TRACE,
  270. levels.DEBUG,
  271. levels.INFO,
  272. levels.WARN
  273. ]);
  274. assertThat(error).isNotGreaterThanOrEqualTo([levels.FATAL, levels.MARK, levels.OFF]);
  275. },
  276. 'should only be equal to ERROR': function(trace) {
  277. assertThat(trace).isEqualTo([levels.toLevel("ERROR")]);
  278. assertThat(trace).isNotEqualTo([
  279. levels.ALL,
  280. levels.TRACE,
  281. levels.DEBUG,
  282. levels.INFO,
  283. levels.WARN,
  284. levels.FATAL,
  285. levels.MARK,
  286. levels.OFF
  287. ]);
  288. }
  289. },
  290. 'FATAL': {
  291. topic: levels.FATAL,
  292. 'should be less than OFF': function(fatal) {
  293. assertThat(fatal).isLessThanOrEqualTo([levels.MARK, levels.OFF]);
  294. assertThat(fatal).isNotLessThanOrEqualTo([
  295. levels.ALL,
  296. levels.TRACE,
  297. levels.DEBUG,
  298. levels.INFO,
  299. levels.WARN,
  300. levels.ERROR
  301. ]);
  302. },
  303. 'should be greater than ERROR': function(fatal) {
  304. assertThat(fatal).isGreaterThanOrEqualTo([
  305. levels.ALL,
  306. levels.TRACE,
  307. levels.DEBUG,
  308. levels.INFO,
  309. levels.WARN,
  310. levels.ERROR
  311. ]);
  312. assertThat(fatal).isNotGreaterThanOrEqualTo([levels.MARK, levels.OFF]);
  313. },
  314. 'should only be equal to FATAL': function(fatal) {
  315. assertThat(fatal).isEqualTo([levels.toLevel("FATAL")]);
  316. assertThat(fatal).isNotEqualTo([
  317. levels.ALL,
  318. levels.TRACE,
  319. levels.DEBUG,
  320. levels.INFO,
  321. levels.WARN,
  322. levels.ERROR,
  323. levels.MARK,
  324. levels.OFF
  325. ]);
  326. }
  327. },
  328. 'MARK': {
  329. topic: levels.MARK,
  330. 'should be less than OFF': function(mark) {
  331. assertThat(mark).isLessThanOrEqualTo([levels.OFF]);
  332. assertThat(mark).isNotLessThanOrEqualTo([
  333. levels.ALL,
  334. levels.TRACE,
  335. levels.DEBUG,
  336. levels.INFO,
  337. levels.WARN,
  338. levels.FATAL,
  339. levels.ERROR
  340. ]);
  341. },
  342. 'should be greater than FATAL': function(mark) {
  343. assertThat(mark).isGreaterThanOrEqualTo([
  344. levels.ALL,
  345. levels.TRACE,
  346. levels.DEBUG,
  347. levels.INFO,
  348. levels.WARN,
  349. levels.ERROR,
  350. levels.FATAL
  351. ]);
  352. assertThat(mark).isNotGreaterThanOrEqualTo([levels.OFF]);
  353. },
  354. 'should only be equal to MARK': function(mark) {
  355. assertThat(mark).isEqualTo([levels.toLevel("MARK")]);
  356. assertThat(mark).isNotEqualTo([
  357. levels.ALL,
  358. levels.TRACE,
  359. levels.DEBUG,
  360. levels.INFO,
  361. levels.WARN,
  362. levels.ERROR,
  363. levels.FATAL,
  364. levels.OFF
  365. ]);
  366. }
  367. },
  368. 'OFF': {
  369. topic: levels.OFF,
  370. 'should not be less than anything': function(off) {
  371. assertThat(off).isNotLessThanOrEqualTo([
  372. levels.ALL,
  373. levels.TRACE,
  374. levels.DEBUG,
  375. levels.INFO,
  376. levels.WARN,
  377. levels.ERROR,
  378. levels.FATAL,
  379. levels.MARK
  380. ]);
  381. },
  382. 'should be greater than everything': function(off) {
  383. assertThat(off).isGreaterThanOrEqualTo([
  384. levels.ALL,
  385. levels.TRACE,
  386. levels.DEBUG,
  387. levels.INFO,
  388. levels.WARN,
  389. levels.ERROR,
  390. levels.FATAL,
  391. levels.MARK
  392. ]);
  393. },
  394. 'should only be equal to OFF': function(off) {
  395. assertThat(off).isEqualTo([levels.toLevel("OFF")]);
  396. assertThat(off).isNotEqualTo([
  397. levels.ALL,
  398. levels.TRACE,
  399. levels.DEBUG,
  400. levels.INFO,
  401. levels.WARN,
  402. levels.ERROR,
  403. levels.FATAL,
  404. levels.MARK
  405. ]);
  406. }
  407. }
  408. },
  409. 'isGreaterThanOrEqualTo': {
  410. topic: levels.INFO,
  411. 'should handle string arguments': function(info) {
  412. assertThat(info).isGreaterThanOrEqualTo(["all", "trace", "debug"]);
  413. assertThat(info).isNotGreaterThanOrEqualTo(['warn', 'ERROR', 'Fatal', 'MARK', 'off']);
  414. }
  415. },
  416. 'isLessThanOrEqualTo': {
  417. topic: levels.INFO,
  418. 'should handle string arguments': function(info) {
  419. assertThat(info).isNotLessThanOrEqualTo(["all", "trace", "debug"]);
  420. assertThat(info).isLessThanOrEqualTo(['warn', 'ERROR', 'Fatal', 'MARK', 'off']);
  421. }
  422. },
  423. 'isEqualTo': {
  424. topic: levels.INFO,
  425. 'should handle string arguments': function(info) {
  426. assertThat(info).isEqualTo(["info", "INFO", "iNfO"]);
  427. }
  428. },
  429. 'toLevel': {
  430. 'with lowercase argument': {
  431. topic: levels.toLevel("debug"),
  432. 'should take the string and return the corresponding level': function(level) {
  433. assert.equal(level, levels.DEBUG);
  434. }
  435. },
  436. 'with uppercase argument': {
  437. topic: levels.toLevel("DEBUG"),
  438. 'should take the string and return the corresponding level': function(level) {
  439. assert.equal(level, levels.DEBUG);
  440. }
  441. },
  442. 'with varying case': {
  443. topic: levels.toLevel("DeBuG"),
  444. 'should take the string and return the corresponding level': function(level) {
  445. assert.equal(level, levels.DEBUG);
  446. }
  447. },
  448. 'with unrecognised argument': {
  449. topic: levels.toLevel("cheese"),
  450. 'should return undefined': function(level) {
  451. assert.isUndefined(level);
  452. }
  453. },
  454. 'with unrecognised argument and default value': {
  455. topic: levels.toLevel("cheese", levels.DEBUG),
  456. 'should return default value': function(level) {
  457. assert.equal(level, levels.DEBUG);
  458. }
  459. }
  460. }
  461. }).export(module);