1 | import match from 'MATCH/match';
|
2 | const expect = require('chai').expect;
|
3 |
|
4 |
|
5 |
|
6 | let params = {
|
7 | pid: 'false',
|
8 | name: 1,
|
9 | id: '2',
|
10 | city: 1,
|
11 | district: '1.56'
|
12 | };
|
13 | let data = match.parse(params, {
|
14 | pid: '(boolean)$${{pid}}',
|
15 | Pid: '(Boolean)$${{pid}}',
|
16 | name: '(Boolean)$${{name}}',
|
17 | id: '(int)$${{id}}',
|
18 | city: '(string)$${{city}}',
|
19 | dis: '(float)$${{district}}'
|
20 | });
|
21 | expect(data).to.be.eql({
|
22 | pid: false,
|
23 | Pid: true,
|
24 | name: true,
|
25 | id: 2,
|
26 | city: '1',
|
27 | dis: 1.56
|
28 | });
|
29 |
|
30 | data = match.parse([params], {
|
31 | pid: '(boolean)${0.pid}',
|
32 | Pid: '(Boolean)${0.pid}',
|
33 | name: '(Boolean)${0.name}',
|
34 | id: '(int)${0.id}',
|
35 | id2: '(Int)${0.pid}',
|
36 | id3: '(Int)${0.name}',
|
37 | id4: '(Int)${0.district}',
|
38 | city: '(string)${0.city}',
|
39 | dis: '(float)${0.district}'
|
40 | });
|
41 | expect(data).to.be.eql({
|
42 | pid: false,
|
43 | Pid: true,
|
44 | name: true,
|
45 | id: 2,
|
46 | id2: 0,
|
47 | id3: 1,
|
48 | id4: 1,
|
49 | city: '1',
|
50 | dis: 1.56
|
51 | });
|
52 |
|
53 | params = [
|
54 | {
|
55 | id: 1,
|
56 | type: 2
|
57 | },
|
58 | {
|
59 | id: 2
|
60 | }
|
61 | ];
|
62 | data = match.parse(params, [{
|
63 | id: '(string)$${{id}}',
|
64 | title: 'string',
|
65 | type: "$${{type}} || 'abc'"
|
66 | }]);
|
67 | expect(data).to.be.eql([
|
68 | {
|
69 | id: '1',
|
70 | title: 'string',
|
71 | type: 2
|
72 | },
|
73 | {
|
74 | id: '2',
|
75 | title: 'string',
|
76 | type: 'abc'
|
77 | }
|
78 | ]);
|