Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #12 from mena-devs/develop
Browse files Browse the repository at this point in the history
0.1.12
  • Loading branch information
Bassem Dghaidi authored May 12, 2020
2 parents 1b0b2e1 + 62a54d0 commit b481313
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const match = (payload, pattern, callback) => {
* with the result object
*/
if (value instanceof RegExp) {
const matcher = payload[key].match(value) || []
const matcher = value.exec(payload[key]) || []
if (matcher.length > 0) {
result.groups = { ...result.groups, ...matcher.groups }
currentNode[key] = payload[key]
Expand All @@ -49,7 +49,7 @@ const match = (payload, pattern, callback) => {
* Level N depth RegExp handling
*/
if (element instanceof RegExp) {
const matcher = payload[key][index].match(element) || []
const matcher = element.exec(payload[key][index]) || []
if (matcher.length > 0) {
result.groups = { ...result.groups, ...matcher.groups }
currentNode[key] = payload[key]
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@menadevs/objectron",
"version": "0.1.11",
"version": "0.1.12",
"description": "Compares a set of match rules contained with an object to determine if the latter conforms to the matching rules",
"main": "index.js",
"devDependencies": {
Expand Down
52 changes: 48 additions & 4 deletions test/test_objectron.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,42 @@ suite('Objectron Core Tests', () => {
assert.deepEqual(result, expected)
})

test('Match number type values against regex pattern', () => {
const payload = {
age: 15,
shoeSize: 44.5,
temperature: {
type: 'celcius',
degree: -20
}
};

const result = match(payload, {
age: /\d*/,
shoeSize: /(\d+\.?\d*|\d*\.?\d+)/,
temperature: {
degree: /\-\d*/
}
});

const expected = {
match: true,
total: 3,
matches: {
age: 15,
shoeSize: 44.5,
temperature: {
degree: -20
}
},
groups: {}
}


assert.isTrue(result.match);
assert.deepEqual(result, expected);
});

test('Callback fired on match', () => {
let called = false

Expand All @@ -414,7 +450,8 @@ suite('Objectron Core Tests', () => {
fields: [
{
type: 'plain_text',
text: 'going home?'
text: 'going home?',
rating: 5.5
},
{
type: 'markdown',
Expand All @@ -432,21 +469,28 @@ suite('Objectron Core Tests', () => {
fields: [
{
type: 'plain_text',
text: /(?<verb>\S+) (?<what>.+)?/
text: /(?<verb>\S+) (?<what>.+)?/,
rating: /(\d+\.?\d*|\d*\.?\d+)/
}
]
}
})

const expected = {
match: true,
total: 7,
total: 8,
matches: {
api: 13,
ids: [130, 45, 12],
components: {
type: 'section',
fields: [{ type: 'plain_text', text: 'going home?' }]
fields: [
{
type: 'plain_text',
text: 'going home?',
rating: 5.5
}
]
}
},
groups: { verb: 'going', what: 'home?' }
Expand Down

0 comments on commit b481313

Please sign in to comment.