-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathre.test.ts
30 lines (28 loc) · 1.17 KB
/
re.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { testSuite, expect } from "manten";
import { nrml, testCollection } from "../../../common";
export default testSuite(async ({ describe }) => {
describe("$re", ({ test }) => {
test("works", () => {
const collection = testCollection();
collection.insert([
{ ip: "192.168.0.1" },
{ ip: "192.168.0.254" },
{ ip: "19216801" }
]);
const ip = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
const found = nrml(collection.find({ ip: { $re: ip } }));
expect(found).toEqual([ { ip: "192.168.0.1" }, { ip: "192.168.0.254" } ]);
});
test("works with dot notation", () => {
const collection = testCollection();
collection.insert([
{ ip: { a: "192.168.0.1" } },
{ ip: { a: "192.168.0.254" } },
{ ip: { a: "19216801" } }
]);
const ip = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
const found = nrml(collection.find({ "ip.a": { $re: ip } }));
expect(found).toEqual([ { ip: { a: "192.168.0.1" } }, { ip: { a: "192.168.0.254" } } ]);
})
});
});