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

Commit

Permalink
Add closure testing scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
Bassem Dghaidi committed May 1, 2020
1 parent 31ed5f3 commit d9e4a9e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,44 @@ console.dir(result, {depth: null});
}
```

### 6. Match with closures (Success)

You can use closures for testing

```javascript
const match = require('@menadevs/objectron');

const payload = {
'type': 'message',
'text': 'text',
'int': 1,
'bool': true,
'float': 1.1,
'items': [1, 1, 1, 1],
}

const tester = {
'type': (val) => val === 'message',
'text': (val) => val.length == 4,
'int': (val) => val + 1 == 2,
'bool': (val) => !!!!!!!!val,
'float': (val) => val - 1.1 == 0,
'items': (val) => val.length == 4,
}

const result = match(payload, tester);

console.dir(result, {depth: null});

# Output
> {
match: true,
total: 0,
matches: { type: {}, text: {}, int: {}, bool: {}, float: {}, items: {} },
groups: {}
}
```

## Meta

- [@Link-](https://github.com/Link-)
Expand Down

0 comments on commit d9e4a9e

Please sign in to comment.