MatchExpressionParser.js 19 KB

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