MatchExpressionParser.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. "use strict";
  2. var assert = require("assert"),
  3. MatchExpressionParser = require("../../../../lib/pipeline/matcher/MatchExpressionParser");
  4. module.exports = {
  5. "MatchExpressionParser": {
  6. "Should generate matchers that work with no operators": function (){
  7. var goodQ = {'x':2},badQ = {'x':3};
  8. var parser = new MatchExpressionParser();
  9. var res = parser.parse(goodQ);
  10. assert.strictEqual(res.code,'OK',res.description);
  11. assert.ok( res.result.matches(goodQ));
  12. assert.ok( ! res.result.matches(badQ));
  13. },
  14. "Should parse {x:5,y:{$gt:5, :$lt:8}}": function() {
  15. var q = {'x':5, 'y':{'$gt':5, '$lt':8}};
  16. var parser = new MatchExpressionParser();
  17. var res = parser.parse( q );
  18. assert.strictEqual(res.code,'OK',res.description);
  19. assert.ok( res.result.matches({'x':5, 'y':7}) );
  20. assert.ok( res.result.matches({'x':5, 'y':6}) );
  21. assert.ok( ! res.result.matches({'x':6, 'y':7}) );
  22. assert.ok( ! res.result.matches({'x':5, 'y':9}) );
  23. assert.ok( ! res.result.matches({'x':5, 'y':4}) );
  24. },
  25. "Should parse $isolated and $atomic appropriately": function() {
  26. var q1 = {'x':5, '$atomic': {'$gt':5, '$lt':8}},
  27. q2 = {'x':5, '$isolated':1},
  28. q3 = {'x':5, 'y':{'$isolated':1}};
  29. var parser = new MatchExpressionParser();
  30. var t = parser.parse(q1);
  31. assert.strictEqual(parser.parse(q1).code, 'OK');
  32. assert.strictEqual(parser.parse(q2).code, 'OK');
  33. assert.strictEqual(parser.parse(q3).code, 'BAD_VALUE');
  34. },
  35. "Should parse and match $size with an int": function() {
  36. var parser = new MatchExpressionParser();
  37. var q = {'x':{'$size':2}};
  38. var res = parser.parse(q);
  39. assert.strictEqual(res.code,'OK',res.description);
  40. assert.ok( ! res.result.matches({'x':1}) );
  41. assert.ok( res.result.matches({'x':[1,2]}) );
  42. assert.ok( ! res.result.matches({'x':[1]}) );
  43. assert.ok( ! res.result.matches({'x':[1,2,3]}) );
  44. },
  45. "Should parse and match $size with a string argument": function() {
  46. var parser = new MatchExpressionParser();
  47. var q = {'x':{'$size':'a'}};
  48. var res = parser.parse( q );
  49. assert.strictEqual(res.code,'OK',res.description);
  50. assert.ok( ! res.result.matches({'x':1}) );
  51. assert.ok( ! res.result.matches({'x':[1,2]}) );
  52. assert.ok( res.result.matches({'x':[]}) );
  53. assert.ok( ! res.result.matches({'x': [1]}) );
  54. },
  55. "Should parse and match $size with a float argument":function() {
  56. var parser = new MatchExpressionParser();
  57. var q = {'x': {'$size': 2.5}};
  58. var res = parser.parse( q );
  59. assert.strictEqual( res.code,'OK',res.description );
  60. assert.ok( ! res.result.matches({'x':1}) );
  61. assert.ok( ! res.result.matches({'x':[1,2]}) );
  62. assert.ok( ! res.result.matches({'x':[]}) );
  63. assert.ok( ! res.result.matches({'x':[1,2,3]}) );
  64. },
  65. "Should not accept null": function() {
  66. var parser = new MatchExpressionParser();
  67. var q = {'x':{'$size':null}};
  68. var res = parser.parse( q );
  69. assert.strictEqual( res.code, 'BAD_VALUE' );
  70. },
  71. "Should parse $elemMatch : {x:1,y:2}": function() {
  72. var parser = new MatchExpressionParser();
  73. var q = {'x':{'$elemMatch': {'x':1,'y':2}}};
  74. var res = parser.parse( q );
  75. assert.strictEqual( res.code,'OK',res.description );
  76. assert.ok( ! res.result.matches({'x':1}) );
  77. assert.ok( ! res.result.matches({'x':[1,2]}) );
  78. assert.ok( ! res.result.matches({'x':[{'x':1}]}) );
  79. assert.ok( res.result.matches({'x': [{'x':1,'y':2}]}) );
  80. },
  81. "Should parse and match $elemMatch: {$gt:5}": function() {
  82. var parser = new MatchExpressionParser();
  83. var q = {'x': {'$elemMatch': {'$gt':5}}};
  84. var res = parser.parse( q );
  85. assert.strictEqual( res.code,'OK',res.description );
  86. assert.ok( ! res.result.matches({'x':1}) );
  87. assert.ok( ! res.result.matches({'x':[4]}) );
  88. assert.ok( res.result.matches({'x':[6]}) );
  89. },
  90. "Should parse and match $all:[1,2]" : function() {
  91. var parser = new MatchExpressionParser();
  92. var q = {'x':{'$all':[1,2]}};
  93. var res = parser.parse( q );
  94. assert.strictEqual( res.code,'OK',res.description );
  95. assert.ok( ! res.result.matches({'x':1}) );
  96. assert.ok( ! res.result.matches({'x':[1]}) );
  97. assert.ok( ! res.result.matches({'x':[2]}) );
  98. assert.ok( res.result.matches({'x':[1,2]}) );
  99. assert.ok( res.result.matches({'x':[1,2,3]}) );
  100. assert.ok( ! res.result.matches({'x':[2,3]}) );
  101. },
  102. "Should not allow $all to have an element argument": function() {
  103. var parser = new MatchExpressionParser();
  104. var q = {'x': {'$all':1}};
  105. var res = parser.parse( q );
  106. assert.strictEqual( res.code, 'BAD_VALUE' );
  107. },
  108. "Should not allow large regex patterns": function () {
  109. var parser = new MatchExpressionParser();
  110. var q = {'x':{'$all':[new RegExp((new Array(50*1000+1)).join('z'))] }};
  111. var res = parser.parse( q );
  112. assert.strictEqual( res.code, 'BAD_VALUE' );
  113. },
  114. "Should parse and match some simple regex patterns": function() {
  115. var parser = new MatchExpressionParser();
  116. var a = /^a/;
  117. var b = /B/i;
  118. var q = {'a': {'$all': [ a , b ]}};
  119. var res = parser.parse( q );
  120. assert.strictEqual( res.code,'OK',res.description );
  121. assert.ok( ! res.result.matches({'a':'ax'}) );
  122. assert.ok( ! res.result.matches({'a':'qqb'}) );
  123. assert.ok( res.result.matches({'a':'ab'}) );
  124. },
  125. "Should parse and match some more simple regexes" : function(){
  126. var parser = new MatchExpressionParser();
  127. var a = /^a/;
  128. var b = /abc/;
  129. var q = {'a': {'$all': [a, b]}};
  130. var res = parser.parse( q );
  131. assert.strictEqual( res.code,'OK',res.description );
  132. assert.ok( ! res.result.matches({'a':'ax'}) );
  133. assert.ok( res.result.matches({'a':'abc'}) );
  134. },
  135. "Should properly handle x:{$all:[5]}": function() {
  136. var parser = new MatchExpressionParser();
  137. var q = {'x':{'$all':[5]}};
  138. var res = parser.parse( q );
  139. assert.strictEqual( res.code,'OK',res.description );
  140. assert.ok( res.result.matches({'x':5}) );
  141. assert.ok( res.result.matches({'x':[5]}) );
  142. assert.ok( ! res.result.matches({'x':4}) );
  143. assert.ok( ! res.result.matches({'x':[4]}) );
  144. },
  145. "Should handle a good $all $elemMatch query": function() {
  146. var parser = new MatchExpressionParser();
  147. var q = {'x':{'$all':[{'$elemMatch': {'x':1,'y':2}}]}};
  148. var res = parser.parse( q );
  149. assert.strictEqual( res.code,'OK',res.description );
  150. assert.ok( ! res.result.matches({'x':1}) );
  151. assert.ok( ! res.result.matches({'x':[1,2]}) );
  152. assert.ok( ! res.result.matches({'x':[{'x':1}]}) );
  153. assert.ok( res.result.matches({'x':[{'x':1,'y':2}]}) );
  154. },
  155. "Should properly not parse bad $all $elemMatch queries": function() {
  156. var parser = new MatchExpressionParser();
  157. var q = {'x':{'$all':[{'$elemMatch':{'x':1,'y':2}}, 5]}};
  158. var res = parser.parse( q );
  159. assert.strictEqual( res.code, 'BAD_VALUE' );
  160. q = {'x':{'$all':[5,{'$elemMatch':{'x':1,'y':2}}]}};
  161. res = parser.parse( q );
  162. assert.strictEqual( res.code, 'BAD_VALUE' );
  163. },
  164. "Should parse and match simple $eq": function () {
  165. var parser = new MatchExpressionParser();
  166. var q = {'x': {'$eq': 2}};
  167. var res = parser.parse( q );
  168. assert.strictEqual( res.code,'OK',res.description );
  169. assert.ok( ! res.result.matches({'x':1}) );
  170. assert.ok( res.result.matches({'x':2}) );
  171. assert.ok( ! res.result.matches({'x':3}) );
  172. },
  173. "Should parse and match simple $gt": function() {
  174. var parser = new MatchExpressionParser();
  175. var q = {'x': {'$gt':2}};
  176. var res = parser.parse( q );
  177. assert.strictEqual( res.code,'OK',res.description );
  178. assert.ok( ! res.result.matches({'x':2}) );
  179. assert.ok( res.result.matches({'x':3}) );
  180. },
  181. "Should parse and match a simple $lt": function () {
  182. var parser = new MatchExpressionParser();
  183. var q = {'x':{'$lt':2}};
  184. var res = parser.parse( q );
  185. assert.strictEqual( res.code,'OK',res.description );
  186. assert.ok( res.result.matches({'x':1}) );
  187. assert.ok( ! res.result.matches({'x':2}) );
  188. assert.ok( ! res.result.matches({'x':3}) );
  189. },
  190. "Should parse and match simple $gte": function() {
  191. var parser = new MatchExpressionParser();
  192. var q = {'x': {'$gte':2}};
  193. var res = parser.parse( q );
  194. assert.strictEqual( res.code,'OK',res.description );
  195. assert.ok( ! res.result.matches({'x':1}) );
  196. assert.ok( res.result.matches({'x':2}) );
  197. assert.ok( res.result.matches({'x':3}) );
  198. },
  199. "Should parse and matc simple $lte": function() {
  200. var parser = new MatchExpressionParser();
  201. var q = {'x': {'$lte':2}};
  202. var res = parser.parse( q );
  203. assert.strictEqual( res.code,'OK',res.description );
  204. assert.ok( res.result.matches({'x':1}) );
  205. assert.ok( res.result.matches({'x':2}) );
  206. assert.ok( ! res.result.matches({'x':3}) );
  207. },
  208. "Should parse and match simple $ne": function() {
  209. var parser = new MatchExpressionParser();
  210. var q = {'x': {'$ne':2}};
  211. var res = parser.parse( q );
  212. assert.strictEqual( res.code,'OK',res.description );
  213. assert.ok( res.result.matches({'x':1}) );
  214. assert.ok( ! res.result.matches({'x':2}) );
  215. assert.ok( res.result.matches({'x':3}) );
  216. },
  217. "Should parse simple $mod patterns":function(){
  218. var parser = new MatchExpressionParser();
  219. var q = {'x':{'$mod':[3,2]}};
  220. var res = parser.parse( q );
  221. assert.strictEqual( res.code,'OK',res.description );
  222. q = {'x':{'$mod':[3]}};
  223. res = parser.parse( q );
  224. assert.strictEqual( res.code, 'BAD_VALUE' );
  225. q = {'x':{'$mod':[3,2,4]}};
  226. res = parser.parse( q );
  227. assert.strictEqual( res.code, 'BAD_VALUE' );
  228. q = {'x':{'$mod':['q',2]}};
  229. res = parser.parse( q );
  230. assert.strictEqual( res.code, 'BAD_VALUE' );
  231. q = {'x':{'$mod':3}};
  232. res = parser.parse( q );
  233. assert.strictEqual( res.code, 'BAD_VALUE' );
  234. q = {'x':{'$mod':{'a':1,'b':2}}};
  235. res = parser.parse( q );
  236. assert.strictEqual( res.code, 'BAD_VALUE' );
  237. },
  238. "Should parse and match simple $mod": function() {
  239. var parser = new MatchExpressionParser();
  240. var q = {'x':{'$mod':[3,2]}};
  241. var res = parser.parse( q );
  242. assert.strictEqual( res.code,'OK',res.description );
  243. assert.ok( res.result.matches({'x':5}) );
  244. assert.ok( ! res.result.matches({'x':4}) );
  245. assert.ok( res.result.matches({'x':8}) );
  246. },
  247. "Should treat a second arg to $mod that is a string as a 0": function() {
  248. var parser = new MatchExpressionParser();
  249. var q = {'x':{'$mod':[2,'r']}};
  250. var res = parser.parse( q );
  251. assert.strictEqual( res.code,'OK',res.description );
  252. assert.ok( res.result.matches({'x':2}) );
  253. assert.ok( res.result.matches({'x':4}) );
  254. assert.ok( ! res.result.matches({'x':5}) );
  255. assert.ok( ! res.result.matches({'x':'a'}) );
  256. },
  257. "Should parse and match a simple $in": function() {
  258. var parser = new MatchExpressionParser();
  259. var q = {'x': {'$in':[2,3]}};
  260. var res = parser.parse( q );
  261. assert.strictEqual( res.code,'OK',res.description );
  262. assert.ok( ! res.result.matches({'x':1}) );
  263. assert.ok( res.result.matches({'x':2}) );
  264. assert.ok( res.result.matches({'x':3}) );
  265. },
  266. "Should not accept a scalar as an arg to $in" : function() {
  267. var parser = new MatchExpressionParser();
  268. var q = {'x':{'$in': 5}};
  269. var res = parser.parse( q );
  270. assert.strictEqual( res.code, 'BAD_VALUE' );
  271. },
  272. "Should not accept an $elemMatch as an arg to an $in": function () {
  273. var parser = new MatchExpressionParser();
  274. var q = {'x':{'$in':[{'$elemMatch': 1}]}};
  275. var res = parser.parse( q );
  276. assert.strictEqual( res.code, 'BAD_VALUE' );
  277. },
  278. "Should not parse regexes that are too long": function() {
  279. var parser = new MatchExpressionParser();
  280. var str = (new Array(50*1000+1).join('z'));
  281. var q = {'x': {'$in':[new RegExp(str)]}};
  282. var res = parser.parse( q );
  283. assert.strictEqual( res.code, 'BAD_VALUE' );
  284. q = {'x':{'$in': [{'$regex': str}]}};
  285. res = parser.parse( q );
  286. assert.strictEqual( res.code, 'BAD_VALUE' );
  287. },
  288. "Should parse and match $regex in an $in expression": function() {
  289. var parser = new MatchExpressionParser();
  290. var a = /^a/;
  291. var b = /B/i;
  292. var q = {'a': {'$in': [a,b,"2",4]}};
  293. var res = parser.parse( q );
  294. assert.strictEqual( res.code,'OK',res.description );
  295. assert.ok( res.result.matches({'a':'ax'}) );
  296. assert.ok( res.result.matches({'a':/^a/}) );
  297. assert.ok( res.result.matches({'a':'qqb'}) );
  298. assert.ok( res.result.matches({'a':/B/i}) );
  299. assert.ok( res.result.matches({'a':4}) );
  300. assert.ok( ! res.result.matches({'a':'l'}) );
  301. assert.ok( ! res.result.matches({'a':/B/}) );
  302. },
  303. "Should parse and match a simple $nin": function() {
  304. var parser = new MatchExpressionParser();
  305. var q = {'x': {'$nin': [2,3]}};
  306. var res = parser.parse( q );
  307. assert.strictEqual( res.code,'OK',res.description );
  308. assert.ok( res.result.matches({'x':1}) );
  309. assert.ok( ! res.result.matches({'x':2}) );
  310. assert.ok( ! res.result.matches({'x':3}) );
  311. },
  312. "Should not accept a scalar argument to $nin":function() {
  313. var parser = new MatchExpressionParser();
  314. var q = {'x':{$nin: 5}};
  315. var res = parser.parse( q );
  316. assert.strictEqual( res.code, 'BAD_VALUE' );
  317. },
  318. "Should properly handle /regex/i":function() {
  319. var parser = new MatchExpressionParser();
  320. var a = /abc/i;
  321. var q = {'x': a };
  322. var res = parser.parse( q );
  323. assert.strictEqual( res.code,'OK',res.description );
  324. assert.ok( res.result.matches({'x':'ABC'}) );
  325. assert.ok( res.result.matches({'x':'abc'}) );
  326. assert.ok( ! res.result.matches({'x':'AC'}) );
  327. },
  328. "Should properly handle $regex x $option i": function() {
  329. var parser = new MatchExpressionParser();
  330. var q = {'x': {'$regex': 'abc', '$options':'i'}};
  331. var res = parser.parse( q );
  332. assert.strictEqual( res.code,'OK',res.description );
  333. assert.ok( res.result.matches({'x':'abc'}) );
  334. assert.ok( res.result.matches({'x':'ABC'}) );
  335. assert.ok( ! res.result.matches({'x':'AC'}) );
  336. },
  337. "Should properly handle $option i $regex x": function () {
  338. var parser = new MatchExpressionParser();
  339. var q = {'x':{'$options': 'i', '$regex': 'abc'}};
  340. var res = parser.parse( q );
  341. assert.strictEqual( res.code,'OK',res.description );
  342. assert.ok( res.result.matches({'x':'abc'}) );
  343. assert.ok( res.result.matches({'x':'ABC'}) );
  344. assert.ok( ! res.result.matches({'x':'AC'}) );
  345. },
  346. "Should not accept $optionas":function() {
  347. var parser = new MatchExpressionParser();
  348. var q = {'x':{'$regex':'abc', '$optionas':'i'}};
  349. var res = parser.parse( q );
  350. assert.strictEqual( res.code, 'BAD_VALUE' );
  351. q = {'x':{'$optionas': 'i'}};
  352. res = parser.parse( q );
  353. assert.strictEqual( res.code, 'BAD_VALUE' );
  354. q = {'x':{'$options':'i'}};
  355. res = parser.parse( q );
  356. assert.strictEqual( res.code, 'BAD_VALUE' );
  357. },
  358. "Should parse and match $exist true": function () {
  359. var parser = new MatchExpressionParser();
  360. var q = {'x':{'$exists': true}};
  361. var res = parser.parse( q );
  362. assert.strictEqual( res.code,'OK',res.description );
  363. assert.ok( res.result.matches({'x':'abc'}) );
  364. assert.ok( ! res.result.matches({'y':'AC'}) );
  365. },
  366. "Should parse and match $exists false": function() {
  367. var parser = new MatchExpressionParser();
  368. var q = {'x':{'$exists':false}};
  369. var res = parser.parse( q );
  370. assert.strictEqual( res.code,'OK',res.description );
  371. assert.ok( ! res.result.matches({'x':'abc'}) );
  372. assert.ok( res.result.matches({'y':'AC'}) );
  373. },
  374. "Should parse and match String $type": function() {
  375. var parser = new MatchExpressionParser();
  376. var q = {'x':{'$type': 2 }};
  377. var res = parser.parse( q );
  378. assert.strictEqual( res.code,'OK',res.description );
  379. assert.ok( res.result.matches({'x': 'abc'}) );
  380. assert.ok( ! res.result.matches({'x': 2}) );
  381. },
  382. "Should parse and match Number $type":function() {
  383. var parser = new MatchExpressionParser();
  384. var q = {'x':{'$type':1}};
  385. var res = parser.parse( q );
  386. assert.strictEqual( res.code,'OK',res.description );
  387. assert.ok( res.result.matches({'x':2}) );
  388. assert.ok( ! res.result.matches({'x': 'f'}) );
  389. },
  390. "Should parse and match null $type" : function() {
  391. var parser = new MatchExpressionParser();
  392. var q = {'x':{'$type': 10}};
  393. var res = parser.parse( q );
  394. assert.strictEqual( res.code,'OK',res.description );
  395. assert.ok( ! res.result.matches({'x':{}}) );
  396. assert.ok( ! res.result.matches({'x':5}) );
  397. assert.ok( res.result.matches({'x':null}) );
  398. },
  399. "Should parse but not match a type beyond typemax in $type": function() {
  400. var parser = new MatchExpressionParser();
  401. var q = {'x':{'$type': 1000}};
  402. var res = parser.parse( q );
  403. assert.strictEqual( res.code,'OK',res.description );
  404. assert.ok( ! res.result.matches({'x':5}) );
  405. assert.ok( ! res.result.matches({'x':'abc'}) );
  406. },
  407. "Should not parse a $type: Object":function() {
  408. var parser = new MatchExpressionParser();
  409. var q = {'x':{'$type': {'x':1}}};
  410. var res = parser.parse( q );
  411. assert.strictEqual( res.code, 'BAD_VALUE' );
  412. },
  413. "Should parse and match a simple $or": function() {
  414. var parser = new MatchExpressionParser();
  415. var q = {'$or':[{'x':1},{'y':2}]};
  416. var res = parser.parse( q );
  417. assert.strictEqual( res.code,'OK',res.description );
  418. assert.ok( res.result.matches({'x':1}) );
  419. assert.ok( res.result.matches({'y':2}) );
  420. assert.ok( ! res.result.matches({'x':3}) );
  421. assert.ok( ! res.result.matches({'y':1}) );
  422. },
  423. "Should parse and match with nested $or s": function() {
  424. var parser = new MatchExpressionParser();
  425. var q = {'$or':[{'$or':[{'x':1},{'y':2}]}]};
  426. var res = parser.parse( q );
  427. assert.strictEqual( res.code,'OK',res.description );
  428. assert.ok( res.result.matches({'x':1}) );
  429. assert.ok( res.result.matches({'y':2}) );
  430. assert.ok( ! res.result.matches({'x':3}) );
  431. assert.ok( ! res.result.matches({'y':1}) );
  432. },
  433. "Should parse and match $and": function(){
  434. var parser = new MatchExpressionParser();
  435. var q = {'$and':[{'x':1},{'y':2}]};
  436. var res = parser.parse( q );
  437. assert.strictEqual( res.code,'OK',res.description );
  438. assert.ok( ! res.result.matches({'x':1}) );
  439. assert.ok( ! res.result.matches({'y':2}) );
  440. assert.ok( ! res.result.matches({'x':3}) );
  441. assert.ok( ! res.result.matches({'y':1}) );
  442. assert.ok( res.result.matches({'x':1, 'y':2}) );
  443. assert.ok( ! res.result.matches({'x':2, 'y':2}) );
  444. },
  445. "Should parse and match $nor": function() {
  446. var parser = new MatchExpressionParser();
  447. var q = {'$nor':[{'x':1},{'y':2}]};
  448. var res = parser.parse( q );
  449. assert.strictEqual( res.code,'OK',res.description );
  450. assert.ok( ! res.result.matches({'x':1}) );
  451. assert.ok( ! res.result.matches({'y':2}) );
  452. assert.ok( res.result.matches({'x':3}) );
  453. assert.ok( res.result.matches({'y':1}) );
  454. },
  455. "Should parse and match $not": function() {
  456. var parser = new MatchExpressionParser();
  457. var q = {'x':{'$not':{'$gt':5}}};
  458. var res = parser.parse( q );
  459. assert.strictEqual( res.code,'OK',res.description );
  460. assert.ok( res.result.matches({'x':2}) );
  461. assert.ok( ! res.result.matches({'x':8}) );
  462. },
  463. "Should parse $not $regex and match properly": function() {
  464. var parser = new MatchExpressionParser();
  465. var a = /abc/i;
  466. var q = {'x':{'$not': a}};
  467. var res = parser.parse( q );
  468. assert.strictEqual( res.code,'OK',res.description );
  469. assert.ok( ! res.result.matches({'x':'abc'}) );
  470. assert.ok( ! res.result.matches({'x':'ABC'}) );
  471. assert.ok( res.result.matches({'x':'AC'}) );
  472. }
  473. }
  474. };
  475. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);