@schukai/monster 1.22.0 → 1.26.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG +56 -0
- package/README.md +4 -4
- package/dist/modules/constants.js +2 -2
- package/dist/modules/constraints/abstract.js +1 -1
- package/dist/modules/constraints/abstractoperator.js +1 -1
- package/dist/modules/constraints/andoperator.js +1 -1
- package/dist/modules/constraints/invalid.js +1 -1
- package/dist/modules/constraints/isarray.js +1 -1
- package/dist/modules/constraints/isobject.js +1 -1
- package/dist/modules/constraints/namespace.js +1 -1
- package/dist/modules/constraints/oroperator.js +1 -1
- package/dist/modules/constraints/valid.js +1 -1
- package/dist/modules/data/buildmap.js +2 -2
- package/dist/modules/data/buildtree.js +2 -0
- package/dist/modules/data/datasource/namespace.js +1 -1
- package/dist/modules/data/datasource/restapi/writeerror.js +2 -0
- package/dist/modules/data/datasource/restapi.js +2 -2
- package/dist/modules/data/datasource/storage/localstorage.js +2 -2
- package/dist/modules/data/datasource/storage/namespace.js +1 -1
- package/dist/modules/data/datasource/storage/sessionstorage.js +2 -2
- package/dist/modules/data/datasource/storage.js +2 -2
- package/dist/modules/data/datasource.js +2 -2
- package/dist/modules/data/diff.js +2 -2
- package/dist/modules/data/extend.js +1 -1
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +2 -2
- package/dist/modules/data/pipe.js +1 -1
- package/dist/modules/data/transformer.js +2 -2
- package/dist/modules/dom/assembler.js +1 -1
- package/dist/modules/dom/attributes.js +1 -1
- package/dist/modules/dom/constants.js +2 -2
- package/dist/modules/dom/customcontrol.js +2 -2
- package/dist/modules/dom/customelement.js +2 -2
- package/dist/modules/dom/events.js +1 -1
- package/dist/modules/dom/focusmanager.js +2 -0
- package/dist/modules/dom/locale.js +1 -1
- package/dist/modules/dom/namespace.js +1 -1
- package/dist/modules/dom/resource/data.js +2 -0
- package/dist/modules/dom/resource/link/stylesheet.js +2 -0
- package/dist/modules/dom/resource/link.js +2 -0
- package/dist/modules/dom/resource/script.js +2 -0
- package/dist/modules/dom/resource.js +2 -0
- package/dist/modules/dom/resourcemanager.js +2 -0
- package/dist/modules/dom/template.js +1 -1
- package/dist/modules/dom/theme.js +1 -1
- package/dist/modules/dom/updater.js +2 -2
- package/dist/modules/dom/util.js +1 -1
- package/dist/modules/dom/worker/factory.js +2 -0
- package/dist/modules/i18n/formatter.js +2 -0
- package/dist/modules/i18n/locale.js +1 -1
- package/dist/modules/i18n/namespace.js +1 -1
- package/dist/modules/i18n/provider.js +1 -1
- package/dist/modules/i18n/providers/fetch.js +2 -2
- package/dist/modules/i18n/providers/namespace.js +1 -1
- package/dist/modules/i18n/translations.js +1 -1
- package/dist/modules/logging/handler/console.js +1 -1
- package/dist/modules/logging/handler/namespace.js +1 -1
- package/dist/modules/logging/handler.js +1 -1
- package/dist/modules/logging/logentry.js +1 -1
- package/dist/modules/logging/logger.js +1 -1
- package/dist/modules/logging/namespace.js +1 -1
- package/dist/modules/math/namespace.js +1 -1
- package/dist/modules/math/random.js +2 -2
- package/dist/modules/monster.js +1 -1
- package/dist/modules/namespace.js +1 -1
- package/dist/modules/text/formatter.js +2 -2
- package/dist/modules/text/namespace.js +1 -1
- package/dist/modules/types/base.js +1 -1
- package/dist/modules/types/basewithoptions.js +2 -2
- package/dist/modules/types/binary.js +1 -1
- package/dist/modules/types/dataurl.js +1 -1
- package/dist/modules/types/global.js +1 -1
- package/dist/modules/types/id.js +1 -1
- package/dist/modules/types/is.js +2 -2
- package/dist/modules/types/mediatype.js +1 -1
- package/dist/modules/types/namespace.js +1 -1
- package/dist/modules/types/node.js +2 -0
- package/dist/modules/types/nodelist.js +2 -0
- package/dist/modules/types/noderecursiveiterator.js +2 -0
- package/dist/modules/types/observer.js +1 -1
- package/dist/modules/types/observerlist.js +2 -2
- package/dist/modules/types/proxyobserver.js +2 -2
- package/dist/modules/types/queue.js +1 -1
- package/dist/modules/types/randomid.js +1 -1
- package/dist/modules/types/regex.js +2 -0
- package/dist/modules/types/stack.js +1 -1
- package/dist/modules/types/tokenlist.js +2 -2
- package/dist/modules/types/typeof.js +1 -1
- package/dist/modules/types/uniquequeue.js +1 -1
- package/dist/modules/types/uuid.js +2 -0
- package/dist/modules/types/validate.js +1 -1
- package/dist/modules/types/version.js +2 -2
- package/dist/modules/util/clone.js +2 -2
- package/dist/modules/util/comparator.js +2 -2
- package/dist/modules/util/freeze.js +1 -1
- package/dist/modules/util/namespace.js +1 -1
- package/dist/modules/util/processing.js +2 -2
- package/dist/modules/util/trimspaces.js +2 -0
- package/dist/monster.dev.js +1838 -792
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +13 -2
- package/source/constants.js +16 -7
- package/source/constraints/abstract.js +5 -0
- package/source/constraints/abstractoperator.js +5 -0
- package/source/constraints/andoperator.js +10 -5
- package/source/constraints/invalid.js +8 -3
- package/source/constraints/isarray.js +9 -4
- package/source/constraints/isobject.js +8 -3
- package/source/constraints/oroperator.js +10 -5
- package/source/constraints/valid.js +8 -3
- package/source/data/buildmap.js +27 -11
- package/source/data/buildtree.js +95 -0
- package/source/data/datasource/restapi/writeerror.js +49 -0
- package/source/data/datasource/restapi.js +95 -11
- package/source/data/datasource/storage/localstorage.js +15 -8
- package/source/data/datasource/storage/sessionstorage.js +16 -12
- package/source/data/datasource/storage.js +16 -7
- package/source/data/datasource.js +60 -16
- package/source/data/diff.js +8 -8
- package/source/data/extend.js +5 -5
- package/source/data/pathfinder.js +12 -6
- package/source/data/pipe.js +6 -5
- package/source/data/transformer.js +131 -24
- package/source/dom/assembler.js +2 -2
- package/source/dom/attributes.js +24 -24
- package/source/dom/constants.js +305 -12
- package/source/dom/customcontrol.js +40 -19
- package/source/dom/customelement.js +182 -102
- package/source/dom/events.js +6 -6
- package/source/dom/focusmanager.js +250 -0
- package/source/dom/locale.js +10 -5
- package/source/dom/resource/data.js +170 -0
- package/source/dom/resource/link/stylesheet.js +54 -0
- package/source/dom/resource/link.js +125 -0
- package/source/dom/resource/script.js +112 -0
- package/source/dom/resource.js +268 -0
- package/source/dom/resourcemanager.js +214 -0
- package/source/dom/template.js +40 -10
- package/source/dom/theme.js +3 -3
- package/source/dom/updater.js +115 -39
- package/source/dom/util.js +6 -6
- package/source/dom/worker/factory.js +134 -0
- package/source/i18n/formatter.js +140 -0
- package/source/i18n/locale.js +10 -8
- package/source/i18n/provider.js +4 -4
- package/source/i18n/providers/fetch.js +24 -14
- package/source/i18n/translations.js +20 -10
- package/source/logging/handler/console.js +2 -2
- package/source/logging/handler.js +2 -2
- package/source/logging/logentry.js +2 -2
- package/source/logging/logger.js +4 -4
- package/source/math/random.js +11 -5
- package/source/namespace.js +1 -1
- package/source/text/formatter.js +244 -27
- package/source/types/base.js +4 -4
- package/source/types/basewithoptions.js +10 -15
- package/source/types/binary.js +8 -8
- package/source/types/dataurl.js +6 -6
- package/source/types/global.js +9 -7
- package/source/types/id.js +6 -3
- package/source/types/is.js +103 -85
- package/source/types/mediatype.js +4 -4
- package/source/types/node.js +179 -0
- package/source/types/nodelist.js +125 -0
- package/source/types/noderecursiveiterator.js +126 -0
- package/source/types/observer.js +3 -3
- package/source/types/observerlist.js +3 -3
- package/source/types/proxyobserver.js +24 -7
- package/source/types/queue.js +6 -6
- package/source/types/randomid.js +2 -2
- package/source/types/regex.js +49 -0
- package/source/types/stack.js +2 -2
- package/source/types/tokenlist.js +8 -9
- package/source/types/typeof.js +3 -3
- package/source/types/uniquequeue.js +4 -4
- package/source/types/uuid.js +102 -0
- package/source/types/validate.js +20 -20
- package/source/types/version.js +6 -6
- package/source/util/clone.js +5 -6
- package/source/util/comparator.js +5 -5
- package/source/util/freeze.js +5 -5
- package/source/util/processing.js +33 -36
- package/source/util/trimspaces.js +85 -0
- package/test/cases/data/buildtree.js +149 -0
- package/test/cases/data/datasource/restapi.js +1 -1
- package/test/cases/data/datasource.js +4 -4
- package/test/cases/data/diff.js +4 -4
- package/test/cases/data/pathfinder.js +18 -9
- package/test/cases/data/pipe.js +26 -2
- package/test/cases/data/transformer.js +41 -10
- package/test/cases/dom/attributes.js +18 -14
- package/test/cases/dom/customcontrol.js +6 -5
- package/test/cases/dom/customelement.js +25 -26
- package/test/cases/dom/focusmanager.js +111 -0
- package/test/cases/dom/locale.js +1 -4
- package/test/cases/dom/resource/data.js +129 -0
- package/test/cases/dom/resource/link/stylesheet.js +101 -0
- package/test/cases/dom/resource/link.js +101 -0
- package/test/cases/dom/resource/script.js +115 -0
- package/test/cases/dom/resourcemanager.js +118 -0
- package/test/cases/dom/updater.js +42 -19
- package/test/cases/dom/worker/factory.js +63 -0
- package/test/cases/i18n/formatter.js +66 -0
- package/test/cases/monster.js +1 -1
- package/test/cases/text/formatter.js +71 -8
- package/test/cases/types/node.js +196 -0
- package/test/cases/types/nodelist.js +64 -0
- package/test/cases/types/noderecursiveiterator.js +54 -0
- package/test/cases/types/proxyobserver.js +55 -11
- package/test/cases/types/regex.js +32 -0
- package/test/cases/types/uuid.js +42 -0
- package/test/cases/util/freeze.js +30 -4
- package/test/cases/util/trimspaces.js +24 -0
- package/test/util/cleanupdom.js +48 -0
- package/test/util/jsdom.js +22 -9
- package/test/web/import.js +15 -0
- package/test/web/monster-dev.html +3 -3
- package/test/web/monster.html +2 -2
- package/test/web/test.html +3 -3
- package/test/web/tests.js +7 -7
@@ -0,0 +1,118 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
import {expect} from "chai"
|
4
|
+
|
5
|
+
import {ResourceManager} from "../../../source/dom/resourcemanager.js";
|
6
|
+
import {cleanupDOMFromTesting, initMutationObserverForTesting} from "../../util/cleanupdom.js";
|
7
|
+
import {initJSDOM} from "../../util/jsdom.js";
|
8
|
+
|
9
|
+
describe('ResourceManager', function () {
|
10
|
+
|
11
|
+
let fetchReference, returnStatus;
|
12
|
+
|
13
|
+
before(function (done) {
|
14
|
+
initJSDOM().then(() => {
|
15
|
+
done()
|
16
|
+
}).catch(e => done(e));
|
17
|
+
});
|
18
|
+
|
19
|
+
afterEach(() => {
|
20
|
+
global['fetch'] = fetchReference;
|
21
|
+
cleanupDOMFromTesting();
|
22
|
+
})
|
23
|
+
|
24
|
+
beforeEach(() => {
|
25
|
+
|
26
|
+
initMutationObserverForTesting()
|
27
|
+
|
28
|
+
returnStatus = 200;
|
29
|
+
fetchReference = global['fetch'];
|
30
|
+
global['fetch'] = function (url, options) {
|
31
|
+
|
32
|
+
if (!url) throw new Error('missing url')
|
33
|
+
|
34
|
+
return new Promise((resolve, reject) => {
|
35
|
+
resolve({
|
36
|
+
text: function () {
|
37
|
+
return JSON.stringify({
|
38
|
+
a: "test"
|
39
|
+
})
|
40
|
+
},
|
41
|
+
status: returnStatus
|
42
|
+
});
|
43
|
+
})
|
44
|
+
|
45
|
+
};
|
46
|
+
|
47
|
+
})
|
48
|
+
|
49
|
+
describe('new', function () {
|
50
|
+
it('new ResourceManager() should return ResourceManager object', function () {
|
51
|
+
let d = new ResourceManager();
|
52
|
+
expect(d).to.be.instanceOf(ResourceManager);
|
53
|
+
});
|
54
|
+
});
|
55
|
+
|
56
|
+
describe('load resources', function () {
|
57
|
+
|
58
|
+
let manager;
|
59
|
+
|
60
|
+
beforeEach(() => {
|
61
|
+
manager = new ResourceManager();
|
62
|
+
})
|
63
|
+
|
64
|
+
it('add script should instance of ResourceManager', function () {
|
65
|
+
expect(manager.addScript('/example.js')).to.be.instanceOf(ResourceManager);
|
66
|
+
});
|
67
|
+
|
68
|
+
it('add style should instance of ResourceManager', function () {
|
69
|
+
expect(manager.addStylesheet('/style.js')).to.be.instanceOf(ResourceManager);
|
70
|
+
});
|
71
|
+
|
72
|
+
it('add data should instance of ResourceManager', function () {
|
73
|
+
expect(manager.addData('/data.json')).to.be.instanceOf(ResourceManager);
|
74
|
+
});
|
75
|
+
|
76
|
+
describe('connect resources', function () {
|
77
|
+
it('add script and connect should instance of ResourceManager', function () {
|
78
|
+
expect(manager.addScript('/example.js').connect()).to.be.instanceOf(ResourceManager);
|
79
|
+
});
|
80
|
+
|
81
|
+
it('add style and connect should instance of ResourceManager', function () {
|
82
|
+
expect(manager.addStylesheet('/style.js').connect()).to.be.instanceOf(ResourceManager);
|
83
|
+
});
|
84
|
+
|
85
|
+
it('add data and connect should instance of ResourceManager', function () {
|
86
|
+
expect(manager.addData('/data.json').connect()).to.be.instanceOf(ResourceManager);
|
87
|
+
});
|
88
|
+
})
|
89
|
+
|
90
|
+
|
91
|
+
describe('check availability resources', function () {
|
92
|
+
it('add script and check availability should return Promise', function () {
|
93
|
+
expect(manager.addScript('/example.js').available()).to.be.instanceOf(Promise);
|
94
|
+
});
|
95
|
+
|
96
|
+
it('add style and check availability should should return Promise', function () {
|
97
|
+
expect(manager.addStylesheet('/style.js').available()).to.be.instanceOf(Promise);
|
98
|
+
});
|
99
|
+
|
100
|
+
it('add data and check availability should should return Promise', function () {
|
101
|
+
expect(manager.addData('/data.json').available()).to.be.instanceOf(Promise);
|
102
|
+
});
|
103
|
+
})
|
104
|
+
|
105
|
+
describe('check availability example.json', function () {
|
106
|
+
it('add data and check content', function (done) {
|
107
|
+
manager.addData('https://example.com/example.json').connect().available().then(r => {
|
108
|
+
expect(document.querySelector('html').outerHTML).contains('>{"a":"test"}</script></head>');
|
109
|
+
done();
|
110
|
+
}).catch(e => done(e));
|
111
|
+
});
|
112
|
+
|
113
|
+
})
|
114
|
+
|
115
|
+
});
|
116
|
+
|
117
|
+
|
118
|
+
});
|
@@ -1,13 +1,12 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
+
import chai from "chai"
|
3
4
|
import {Updater} from "../../../source/dom/updater.js";
|
5
|
+
import {ID} from "../../../source/types/id.js";
|
4
6
|
import {Observer} from "../../../source/types/observer.js";
|
5
7
|
import {ProxyObserver} from "../../../source/types/proxyobserver.js";
|
6
|
-
|
7
|
-
|
8
|
-
import chai from "chai"
|
9
|
-
import {initJSDOM} from "../../util/jsdom.js";
|
10
8
|
import {chaiDom} from "../../util/chai-dom.js";
|
9
|
+
import {initJSDOM} from "../../util/jsdom.js";
|
11
10
|
|
12
11
|
let expect = chai.expect;
|
13
12
|
|
@@ -57,7 +56,7 @@ let html2 = `
|
|
57
56
|
<div id="test1">
|
58
57
|
<div data-monster-replace="path:text | tolower"> </div>
|
59
58
|
<div data-monster-replace="path:text | call:myformatter"> </div>
|
60
|
-
<div data-monster-replace="static:hello"></div>
|
59
|
+
<div data-monster-replace="static:hello\\ "></div>
|
61
60
|
</div>
|
62
61
|
`;
|
63
62
|
|
@@ -283,10 +282,10 @@ describe('DOM', function () {
|
|
283
282
|
if (e === undefined && expected.length === 0) done(new Error('to many calls'));
|
284
283
|
|
285
284
|
if (this.getSubject()['state'] !== e) done(new Error(this.getSubject()['state'] + ' should ' + e));
|
286
|
-
if (expected.length === 0) {
|
285
|
+
if (expected.length === 0) {
|
287
286
|
done();
|
288
287
|
} else {
|
289
|
-
|
288
|
+
|
290
289
|
setTimeout(() => {
|
291
290
|
form1.querySelector('[name=checkbox]').click();
|
292
291
|
}, 10)
|
@@ -501,21 +500,22 @@ describe('DOM', function () {
|
|
501
500
|
return a + 'yes!'
|
502
501
|
})
|
503
502
|
|
504
|
-
|
503
|
+
setTimeout(() => {
|
504
|
+
d.run().then(() => {
|
505
505
|
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
done();
|
512
|
-
}).catch(
|
513
|
-
e => {
|
514
|
-
done(new Error(e))
|
515
|
-
})
|
506
|
+
expect(typeof d).is.equal('object');
|
507
|
+
expect(element).contain.html('<div data-monster-replace="path:text | tolower">hallo</div>');
|
508
|
+
expect(element).contain.html('<div data-monster-replace="path:text | call:myformatter">HALLOyes!</div>');
|
509
|
+
expect(element).contain.html('<div data-monster-replace="static:hello\\ ">hello </div>');
|
516
510
|
|
511
|
+
return done();
|
512
|
+
}).catch(
|
513
|
+
e => {
|
514
|
+
done(new Error(e))
|
515
|
+
})
|
516
|
+
}, 100)
|
517
517
|
|
518
|
-
});
|
518
|
+
});
|
519
519
|
});
|
520
520
|
});
|
521
521
|
|
@@ -638,4 +638,27 @@ describe('DOM', function () {
|
|
638
638
|
});
|
639
639
|
});
|
640
640
|
|
641
|
+
|
642
|
+
describe('Get Attribute Pipe', function () {
|
643
|
+
let id, mocks;
|
644
|
+
beforeEach(() => {
|
645
|
+
mocks = document.getElementById('mocks');
|
646
|
+
id = new ID('monster');
|
647
|
+
mocks.innerHTML = ` <div id="` + id + `"
|
648
|
+
data-monster-replace="path:a | if:value:\\ "></div>`
|
649
|
+
})
|
650
|
+
|
651
|
+
afterEach(() => {
|
652
|
+
mocks.innerHTML = "";
|
653
|
+
})
|
654
|
+
|
655
|
+
it('should include space', function () {
|
656
|
+
const div = document.getElementById(id.toString())
|
657
|
+
|
658
|
+
const pipe = div.getAttribute('data-monster-replace');
|
659
|
+
expect(pipe.length).to.be.equal(20);
|
660
|
+
|
661
|
+
});
|
662
|
+
});
|
663
|
+
|
641
664
|
});
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import {expect} from "chai"
|
2
|
+
|
3
|
+
import {Factory} from "../../../../source/dom/worker/factory.js";
|
4
|
+
import {getGlobal} from "../../../../source/types/global.js";
|
5
|
+
import {initJSDOM, isNode} from "../../../util/jsdom.js";
|
6
|
+
|
7
|
+
const global = getGlobal();
|
8
|
+
|
9
|
+
describe('Worker', function () {
|
10
|
+
|
11
|
+
before(function (done) {
|
12
|
+
|
13
|
+
if (isNode()) {
|
14
|
+
Object.defineProperty(global['URL'], 'createObjectURL', {
|
15
|
+
writable: true,
|
16
|
+
value: () => {
|
17
|
+
return "/example.js"
|
18
|
+
}
|
19
|
+
})
|
20
|
+
|
21
|
+
global['Worker'] = class {
|
22
|
+
terminate() {
|
23
|
+
|
24
|
+
}
|
25
|
+
|
26
|
+
onerror() {
|
27
|
+
|
28
|
+
}
|
29
|
+
|
30
|
+
onmessage() {
|
31
|
+
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
let a = typeof global['Worker'];
|
36
|
+
let a1 = typeof Worker;
|
37
|
+
|
38
|
+
}
|
39
|
+
|
40
|
+
const jsdom = initJSDOM().then(() => {
|
41
|
+
done();
|
42
|
+
});
|
43
|
+
|
44
|
+
|
45
|
+
})
|
46
|
+
|
47
|
+
describe('Factory', function () {
|
48
|
+
|
49
|
+
it('create worker', function () {
|
50
|
+
|
51
|
+
const factory = new Factory();
|
52
|
+
const worker = factory.createFromScript('console.log("hello world");')
|
53
|
+
expect(worker).is.instanceof(Worker);
|
54
|
+
|
55
|
+
expect(factory.terminate(worker)).is.instanceof(Factory)
|
56
|
+
|
57
|
+
|
58
|
+
});
|
59
|
+
|
60
|
+
});
|
61
|
+
|
62
|
+
|
63
|
+
});
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import {expect} from "chai"
|
2
|
+
import {Formatter} from "../../../source/i18n/formatter.js";
|
3
|
+
import {Translations} from "../../../source/i18n/translations.js";
|
4
|
+
|
5
|
+
|
6
|
+
describe('Formatter', function () {
|
7
|
+
|
8
|
+
describe('example', function () {
|
9
|
+
|
10
|
+
it('should run with marker', function () {
|
11
|
+
|
12
|
+
const translations = new Translations('en')
|
13
|
+
.assignTranslations({
|
14
|
+
thekey: "${animal} has eaten the ${food}!"
|
15
|
+
});
|
16
|
+
|
17
|
+
const f = new Formatter({}, translations);
|
18
|
+
|
19
|
+
expect(f.format("i18n{thekey::animal=dog::food=cake}")).to.be.equal('dog has eaten the cake!');
|
20
|
+
// ↦ dog has eaten the cake!
|
21
|
+
|
22
|
+
});
|
23
|
+
|
24
|
+
it('should run without marker', function () {
|
25
|
+
|
26
|
+
const translations = new Translations('en')
|
27
|
+
.assignTranslations({
|
28
|
+
thekey: "${animal} has eaten the ${food}!"
|
29
|
+
});
|
30
|
+
|
31
|
+
// missing marker
|
32
|
+
expect(new Formatter({}, translations).format("thekey::animal=dog::food=cake")).to.be.equal('dog has eaten the cake!');
|
33
|
+
// ↦ dog has eaten the cake!
|
34
|
+
|
35
|
+
});
|
36
|
+
});
|
37
|
+
|
38
|
+
|
39
|
+
describe('format', function () {
|
40
|
+
|
41
|
+
[
|
42
|
+
['i18n{translationkey::a=3::b=5}', 'test is 3 and 5'],
|
43
|
+
|
44
|
+
].forEach(function (data) {
|
45
|
+
|
46
|
+
let a = data.shift()
|
47
|
+
let b = data.shift()
|
48
|
+
|
49
|
+
it('format ' + a + ' should ' + b, function () {
|
50
|
+
|
51
|
+
const translations = new Translations('de').assignTranslations({
|
52
|
+
translationkey: "test is ${a} and ${b}"
|
53
|
+
})
|
54
|
+
|
55
|
+
expect(
|
56
|
+
new Formatter({}, translations).format(a)
|
57
|
+
).to.equal(b)
|
58
|
+
});
|
59
|
+
});
|
60
|
+
|
61
|
+
|
62
|
+
})
|
63
|
+
|
64
|
+
|
65
|
+
})
|
66
|
+
;
|
package/test/cases/monster.js
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
import {expect} from "chai"
|
4
2
|
import {Formatter} from "../../../source/text/formatter.js";
|
5
3
|
|
@@ -57,10 +55,9 @@ describe('Formatter', function () {
|
|
57
55
|
it('format ' + a + ' with marker ' + b + ' and ' + c + ' should return ' + b, function () {
|
58
56
|
|
59
57
|
expect(
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
new Formatter({
|
59
|
+
a: "test"
|
60
|
+
}).setMarker(b, c).format(a)
|
64
61
|
).to.equal(d)
|
65
62
|
});
|
66
63
|
});
|
@@ -72,6 +69,7 @@ describe('Formatter', function () {
|
|
72
69
|
|
73
70
|
[
|
74
71
|
['${a | tojson}', "{\"b\":{\"c\":\"Hello\"},\"d\":\"World\",\"e\":1}"],
|
72
|
+
['click ${a.d} times', "click World times"],
|
75
73
|
[' ${a.b.c} ', ' Hello '],
|
76
74
|
[' ${a.b.c}', ' Hello'],
|
77
75
|
['${a.b.c} ', 'Hello '],
|
@@ -87,9 +85,8 @@ describe('Formatter', function () {
|
|
87
85
|
|
88
86
|
let a = data.shift()
|
89
87
|
let b = data.shift()
|
90
|
-
let c = data.shift()
|
91
88
|
|
92
|
-
it('format ' + a + ' should return ' +
|
89
|
+
it('format ' + a + ' should return ' + b, function () {
|
93
90
|
|
94
91
|
let obj = {
|
95
92
|
a: {
|
@@ -108,6 +105,72 @@ describe('Formatter', function () {
|
|
108
105
|
|
109
106
|
});
|
110
107
|
|
108
|
+
describe('Marker in marker', function () {
|
109
|
+
|
110
|
+
let text = '${mykey${subkey}}';
|
111
|
+
let expected = '1';
|
112
|
+
|
113
|
+
it('format ' + text + ' should ' + expected, function () {
|
114
|
+
|
115
|
+
let obj = {
|
116
|
+
mykey2: "1",
|
117
|
+
subkey: "2"
|
118
|
+
};
|
119
|
+
|
120
|
+
expect(new Formatter(obj).format(text)).is.equal(expected)
|
121
|
+
|
122
|
+
});
|
123
|
+
|
124
|
+
|
125
|
+
});
|
126
|
+
|
127
|
+
describe('setParameterChars()', function () {
|
128
|
+
|
129
|
+
it('setParameterChars() should return Instance', function () {
|
130
|
+
expect(new Formatter({}).setParameterChars('a', 'b')).is.instanceof(Formatter);
|
131
|
+
|
132
|
+
});
|
133
|
+
|
134
|
+
|
135
|
+
});
|
136
|
+
|
137
|
+
|
138
|
+
describe('with callbacks', function () {
|
139
|
+
|
140
|
+
it('add callback', function () {
|
141
|
+
const formatter = new Formatter({
|
142
|
+
x: '1'
|
143
|
+
}, {
|
144
|
+
callbacks: {
|
145
|
+
my: (value) => {
|
146
|
+
return "!" + value + "!"
|
147
|
+
}
|
148
|
+
}
|
149
|
+
});
|
150
|
+
|
151
|
+
expect(formatter.format('${x | call:my}')).is.equal('!1!');
|
152
|
+
|
153
|
+
});
|
154
|
+
|
155
|
+
|
156
|
+
});
|
157
|
+
|
158
|
+
describe('Marker in marker with parameter', function () {
|
159
|
+
|
160
|
+
let text = '${mykey::mykey=${subkey}}';
|
161
|
+
let expected = '2';
|
162
|
+
|
163
|
+
it('format ' + text + ' should ' + expected, function () {
|
164
|
+
|
165
|
+
let obj = {
|
166
|
+
subkey: "2"
|
167
|
+
};
|
168
|
+
|
169
|
+
expect(new Formatter(obj).format(text)).is.equal(expected)
|
170
|
+
|
171
|
+
});
|
172
|
+
});
|
173
|
+
|
111
174
|
describe('exceptions', function () {
|
112
175
|
|
113
176
|
[
|
@@ -0,0 +1,196 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
import {expect} from "chai"
|
4
|
+
import {Node} from "../../../source/types/node.js";
|
5
|
+
import {NodeList} from "../../../source/types/nodelist.js";
|
6
|
+
import {NodeRecursiveIterator} from "../../../source/types/noderecursiveiterator.js";
|
7
|
+
|
8
|
+
describe('NodeList', function () {
|
9
|
+
describe('#constructor', function () {
|
10
|
+
it('should create an empty NodeList', function () {
|
11
|
+
let nodeList = new NodeList();
|
12
|
+
|
13
|
+
expect(nodeList.size).to.equal(0);
|
14
|
+
});
|
15
|
+
|
16
|
+
it('should create a NodeList from an array', function () {
|
17
|
+
let nodeList = new NodeList([
|
18
|
+
new Node('div'),
|
19
|
+
new Node('div'),
|
20
|
+
new Node('div')
|
21
|
+
]);
|
22
|
+
|
23
|
+
expect(nodeList.size).to.equal(3);
|
24
|
+
});
|
25
|
+
|
26
|
+
it('should create a NodeList from a NodeList', function () {
|
27
|
+
let nodeList = new NodeList([
|
28
|
+
new Node('div'),
|
29
|
+
new Node('div'),
|
30
|
+
new Node('div')
|
31
|
+
]);
|
32
|
+
|
33
|
+
let nodeList2 = new NodeList(nodeList);
|
34
|
+
|
35
|
+
expect(nodeList2.size).to.equal(3);
|
36
|
+
});
|
37
|
+
});
|
38
|
+
|
39
|
+
it('create NodeList', function () {
|
40
|
+
expect(new NodeList()).is.instanceof(NodeList);
|
41
|
+
})
|
42
|
+
|
43
|
+
it('add Node', function () {
|
44
|
+
expect(new NodeList().add(new Node())).to.be.instanceof(NodeList);
|
45
|
+
})
|
46
|
+
|
47
|
+
it('remove Node', function () {
|
48
|
+
expect(new NodeList().remove(new Node())).to.be.instanceof(NodeList);
|
49
|
+
})
|
50
|
+
|
51
|
+
it('has unknown Node', function () {
|
52
|
+
expect(new NodeList().has(new Node)).to.be.false;
|
53
|
+
})
|
54
|
+
|
55
|
+
it('has added Node', function () {
|
56
|
+
const n = new Node;
|
57
|
+
expect(new NodeList().add(n).has(n)).to.be.true;
|
58
|
+
})
|
59
|
+
|
60
|
+
it('throw exception', function () {
|
61
|
+
expect(() => new NodeList().add(1)).to.throw(Error);
|
62
|
+
})
|
63
|
+
|
64
|
+
it('check level', function () {
|
65
|
+
|
66
|
+
const root = new Node('root');
|
67
|
+
|
68
|
+
const n1 = new Node('n1');
|
69
|
+
const n2 = new Node('n2');
|
70
|
+
const n3 = new Node('n3');
|
71
|
+
const n4 = new Node('n4');
|
72
|
+
|
73
|
+
const n11 = new Node('n11');
|
74
|
+
const n12 = new Node('n12');
|
75
|
+
const n13 = new Node('n13');
|
76
|
+
|
77
|
+
const n21 = new Node('n21');
|
78
|
+
const n22 = new Node('n22');
|
79
|
+
const n23 = new Node('n23');
|
80
|
+
|
81
|
+
const n41 = new Node('n41');
|
82
|
+
const n42 = new Node('n42');
|
83
|
+
|
84
|
+
const n411 = new Node('n411');
|
85
|
+
const n412 = new Node('n412');
|
86
|
+
const n413 = new Node('n413');
|
87
|
+
|
88
|
+
const n4121 = new Node('n4121');
|
89
|
+
|
90
|
+
root.appendChild(n1).appendChild(n2).appendChild(n3).appendChild(n4);
|
91
|
+
n1.appendChild(n11).appendChild(n12).appendChild(n13);
|
92
|
+
n2.appendChild(n21).appendChild(n22).appendChild(n23);
|
93
|
+
n4.appendChild(n41).appendChild(n42);
|
94
|
+
n41.appendChild(n411).appendChild(n412).appendChild(n413);
|
95
|
+
n412.appendChild(n4121);
|
96
|
+
|
97
|
+
let iterator = new NodeRecursiveIterator(root);
|
98
|
+
|
99
|
+
let result = [];
|
100
|
+
for (const n of iterator) {
|
101
|
+
expect(n).to.be.an.instanceof(Node);
|
102
|
+
result.push(n.value + ":" + n.level);
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
expect(result).to.deep.equal([
|
107
|
+
'root:0',
|
108
|
+
'n1:1',
|
109
|
+
'n11:2',
|
110
|
+
'n12:2',
|
111
|
+
'n13:2',
|
112
|
+
'n2:1',
|
113
|
+
'n21:2',
|
114
|
+
'n22:2',
|
115
|
+
'n23:2',
|
116
|
+
'n3:1',
|
117
|
+
'n4:1',
|
118
|
+
'n41:2',
|
119
|
+
'n411:3',
|
120
|
+
'n412:3',
|
121
|
+
'n4121:4',
|
122
|
+
'n413:3',
|
123
|
+
'n42:2'
|
124
|
+
|
125
|
+
]);
|
126
|
+
|
127
|
+
n4121.appendChild(new Node('n41211'));
|
128
|
+
|
129
|
+
iterator = new NodeRecursiveIterator(root);
|
130
|
+
result = [];
|
131
|
+
for (const n of iterator) {
|
132
|
+
expect(n).to.be.an.instanceof(Node);
|
133
|
+
result.push(n.value + ":" + n.level);
|
134
|
+
}
|
135
|
+
|
136
|
+
expect(result).to.deep.equal([
|
137
|
+
'root:0',
|
138
|
+
'n1:1',
|
139
|
+
'n11:2',
|
140
|
+
'n12:2',
|
141
|
+
'n13:2',
|
142
|
+
'n2:1',
|
143
|
+
'n21:2',
|
144
|
+
'n22:2',
|
145
|
+
'n23:2',
|
146
|
+
'n3:1',
|
147
|
+
'n4:1',
|
148
|
+
'n41:2',
|
149
|
+
'n411:3',
|
150
|
+
'n412:3',
|
151
|
+
'n4121:4',
|
152
|
+
'n41211:5',
|
153
|
+
'n413:3',
|
154
|
+
'n42:2'
|
155
|
+
|
156
|
+
]);
|
157
|
+
|
158
|
+
|
159
|
+
const bb = new Node('bb') // big bang
|
160
|
+
|
161
|
+
bb.appendChild(root);
|
162
|
+
iterator = new NodeRecursiveIterator(bb);
|
163
|
+
|
164
|
+
result = [];
|
165
|
+
for (const n of iterator) {
|
166
|
+
expect(n).to.be.an.instanceof(Node);
|
167
|
+
result.push(n.value + ":" + n.level);
|
168
|
+
}
|
169
|
+
|
170
|
+
expect(result).to.deep.equal([
|
171
|
+
'bb:0',
|
172
|
+
'root:1',
|
173
|
+
'n1:2',
|
174
|
+
'n11:3',
|
175
|
+
'n12:3',
|
176
|
+
'n13:3',
|
177
|
+
'n2:2',
|
178
|
+
'n21:3',
|
179
|
+
'n22:3',
|
180
|
+
'n23:3',
|
181
|
+
'n3:2',
|
182
|
+
'n4:2',
|
183
|
+
'n41:3',
|
184
|
+
'n411:4',
|
185
|
+
'n412:4',
|
186
|
+
'n4121:5',
|
187
|
+
'n41211:6',
|
188
|
+
'n413:4',
|
189
|
+
'n42:3'
|
190
|
+
|
191
|
+
]);
|
192
|
+
|
193
|
+
})
|
194
|
+
|
195
|
+
|
196
|
+
});
|