From 8f85479f2de0ac196cd61eb24de64ddb575238ca Mon Sep 17 00:00:00 2001 From: Andrew Silluron Date: Wed, 12 Apr 2017 22:41:44 -0700 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=98contains=E2=80=99=20function.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/auth0/node-odata-parser/issues/45 --- src/odata.pegjs | 2 +- test/parser.specs.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/odata.pegjs b/src/odata.pegjs index af60680..a7a9741 100644 --- a/src/odata.pegjs +++ b/src/odata.pegjs @@ -285,7 +285,7 @@ filterExpr = return filterExprHelper(left, right); } -booleanFunctions2Args = "substringof" / "endswith" / "startswith" / "IsOf" +booleanFunctions2Args = "contains" / "substringof" / "endswith" / "startswith" / "IsOf" booleanFunc = f:booleanFunctions2Args "(" arg0:part "," WSP? arg1:part ")" { return { diff --git a/test/parser.specs.js b/test/parser.specs.js index 5720d29..ba3d95d 100644 --- a/test/parser.specs.js +++ b/test/parser.specs.js @@ -239,6 +239,21 @@ describe('odata.parser grammar', function () { assert.equal(ast.$filter.right.value, true); }); + it('should parse contains $filter', function () { + + var ast = parser.parse("$filter=contains('nginx', Data)"); + + assert.equal(ast.$filter.type, "functioncall"); + assert.equal(ast.$filter.func, "contains"); + + assert.equal(ast.$filter.args[0].type, "literal"); + assert.equal(ast.$filter.args[0].value, "nginx"); + + assert.equal(ast.$filter.args[1].type, "property"); + assert.equal(ast.$filter.args[1].name, "Data"); + + }); + it('should parse startswith $filter', function () { var ast = parser.parse("$filter=startswith('nginx', Data)");