1 | "use strict";
|
2 | var Xjs = require("./xjs.parser");
|
3 | var Util = require("../lib/boilerplate.util");
|
4 | var Parser = require("../lib/boilerplate.view.parser.constructor");
|
5 | require("../lib/boilerplate.view.parser.names")(Parser);
|
6 | require("../lib/boilerplate.view.parser.parseData")(Parser);
|
7 |
|
8 | describe('Module `boilerplate.view.parser.parseData`', function() {
|
9 | function check( usecase ) {
|
10 | var input = usecase.in;
|
11 | var expected = usecase.ex;
|
12 | it(`${JSON.stringify(input)} should give ${JSON.stringify(expected)}`, function() {
|
13 | var parser = new Parser();
|
14 | var result = parser.parseData( input );
|
15 | expect( result ).toEqual( expected );
|
16 | });
|
17 | }
|
18 |
|
19 | function checkDebug( usecase ) {
|
20 | var input = usecase.in;
|
21 | var expected = usecase.ex;
|
22 | var parser = new Parser();
|
23 | var result = parser.parseData( input );
|
24 | console.log("============================================================");
|
25 | console.log(JSON.stringify( input ));
|
26 | console.log("============================================================");
|
27 | console.log("Expected: ");
|
28 | console.log(JSON.stringify( expected, null, ' ' ));
|
29 | console.log("------------------------------------------------------------");
|
30 | console.log(Util.generateCode( expected ));
|
31 | console.log("============================================================");
|
32 | console.log("Got: ");
|
33 | console.log(JSON.stringify( result, null, ' ' ));
|
34 | console.log("------------------------------------------------------------");
|
35 | console.log(Util.generateCode( result ));
|
36 | }
|
37 |
|
38 | debugger;
|
39 |
|
40 |
|
41 | describe('{intl ...}', function() {
|
42 | [
|
43 | { in: {0: "intl", 1: "title"}, ex: "_(\"title\")" },
|
44 | { in: {0: "intl", 1: "button/title"}, ex: "this.$elements.button._(\"title\")" },
|
45 | { in: {0: "intl", 1: "foo-bar/title"}, ex: "this.$elements[\"foo-bar\"]._(\"title\")" }
|
46 | ].forEach( check );
|
47 | });
|
48 |
|
49 | describe('object', function() {
|
50 | [
|
51 |
|
52 | { in: {}, ex: ["{}"] },
|
53 | { in: {a:27}, ex: ["{a:27}"] },
|
54 | { in: {a:[27]}, ex: ["{a:[27]}"] },
|
55 | { in: {a:27, b:18}, ex: ["{", ["a:27,", "b:18", ], "}"] },
|
56 | { in: { bar: {$f: [{foo: "Foo", cor: []}]}, tor: 666}, ex: [
|
57 | "{",
|
58 | [
|
59 | "bar:{$f:[",
|
60 | [
|
61 | "{",
|
62 | [
|
63 | "foo:\"Foo\",",
|
64 | "cor:[]"
|
65 | ],
|
66 | "}"
|
67 | ],
|
68 | "]},",
|
69 | "tor:666"
|
70 | ],
|
71 | "}"
|
72 | ]
|
73 | },
|
74 | { in: {foo:[18,27],"6":666}, ex: [
|
75 | "{", [
|
76 | '"6":666,',
|
77 | "foo:[", [
|
78 | "18,",
|
79 | "27"],
|
80 | "]" ],
|
81 | "}"] },
|
82 | { in: [{}], ex: ["[{}]"] }
|
83 | ].forEach( check );
|
84 | });
|
85 |
|
86 | describe('array', function() {
|
87 | [
|
88 |
|
89 | { in: [], ex: ["[]"] },
|
90 | { in: [27], ex: ["[27]"] },
|
91 | { in: [18,27], ex: [
|
92 | "[", [
|
93 | "18,",
|
94 | "27"],
|
95 | "]"] },
|
96 | { in: [[[]]], ex: ["[[[]]]"] },
|
97 | { in: [[1], [2,3]], ex: [
|
98 | "[", [
|
99 | "[1],",
|
100 | "[", [
|
101 | "2,",
|
102 | "3" ],
|
103 | "]" ],
|
104 | "]" ] },
|
105 | { in: [[]], ex: ["[[]]"] }
|
106 | ].forEach( check );
|
107 | });
|
108 | });
|