forked from ajaxorg/ace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.js
143 lines (122 loc) · 5.36 KB
/
config_test.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"use strict";
var config = require("./config");
var assert = require("./test/assertions");
var {defaultEnglishMessages} = require("./lib/default_english_messages");
module.exports = {
tearDown: function() {
config.setMessages(defaultEnglishMessages);
},
"test: path resolution" : function(done) {
config.set("packaged", true);
var url = config.moduleUrl("kr_theme", "theme");
assert.equal(url, "theme-kr_theme.js");
config.set("basePath", "a/b");
url = config.moduleUrl("m/theme", "theme");
assert.equal(url, "a/b/theme-m.js");
url = config.moduleUrl("m/theme", "ext");
assert.equal(url, "a/b/ext-theme.js");
config.set("workerPath", "c/");
url = config.moduleUrl("foo/1", "worker");
assert.equal(url, "c/worker-1.js");
config.setModuleUrl("foo/1", "a/b1.js");
url = config.moduleUrl("foo/1", "theme");
assert.equal(url, "a/b1.js");
url = config.moduleUrl("snippets/js");
assert.equal(url, "a/b/snippets/js.js");
config.setModuleUrl("snippets/js", "_.js");
url = config.moduleUrl("snippets/js");
assert.equal(url, "_.js");
url = config.moduleUrl("ace/ext/textarea");
assert.equal(url, "a/b/ext-textarea.js");
config.set("packaged", false);
/* global Promise*/
var callback = () => Promise.resolve("success");
config.setModuleLoader("ace/test-module", callback);
assert.equal(config.dynamicModules["ace/test-module"], callback);
config.loadModule("ace/test-module", (module) => {
assert.equal(module, "success");
done();
});
},
"test: nls": function() {
var nls = config.nls;
config.setMessages({
foo: "hello world of $1",
test_key: "hello world for test key"
});
assert.equal(nls("untranslated_key","bar $1"), "bar $1");
assert.equal(nls("untranslated_key", "bar"), "bar");
assert.equal(nls("untranslated_key_but_translated_default_string", "foo"), "hello world of $1");
assert.equal(nls("untranslated_key_but_translated_default_string", "foo", {1: "goo"}), "hello world of goo");
assert.equal(nls("untranslated_key", "$0B is $1$$", [0.11, 22]), "0.11B is 22$");
assert.equal(nls("untranslated_key_but_translated_default_string", "foo", {1: "goo"}), "hello world of goo");
assert.equal(nls("test_key", "this text should not appear"), "hello world for test key");
},
"test: nls setting nlsPlaceholders": function() {
var nls = config.nls;
// Should default to using dollar signs
config.setMessages({
test_with_curly_brackets: "hello world $0 of {0} and $1 to the {1} degree"
});
assert.equal(nls("test_with_curly_brackets", "hello world $0 of {1} and $1 to the {1} degree", ["bar", "third"]), "hello world bar of {0} and third to the {1} degree");
config.setMessages({
test_with_curly_brackets: "hello world $0 of {0} and $1 to the {1} degree"
}, {placeholders: "curlyBrackets"});
assert.equal(nls("test_with_curly_brackets", "hello world $0 of {1} and $1 to the {1} degree", ["bar", "third"]), "hello world $0 of bar and $1 to the third degree");
config.setMessages({
test_with_curly_brackets: "hello world $0 of {0} and $1 to the {1} degree"
}, {placeholders: "dollarSigns"});
assert.equal(nls("test_with_curly_brackets", "hello world $0 of {1} and $1 to the {1} degree", ["bar", "third"]), "hello world bar of {0} and third to the {1} degree");
},
"test: define options" : function() {
var o = {};
config.defineOptions(o, "test_object", {
opt1: {
set: function(val) {
this.x = val;
},
value: 7
},
initialValue: {
set: function(val) {
this.x = val;
},
initialValue: 8
},
opt2: {
get: function(val) {
return this.x;
}
},
forwarded: "model"
});
o.model = {};
config.defineOptions(o.model, "model", {
forwarded: {value: 1}
});
config.resetOptions(o);
config.resetOptions(o.model);
assert.equal(o.getOption("opt1"), 7);
assert.equal(o.getOption("opt2"), 7);
o.setOption("opt1", 8);
assert.equal(o.getOption("opt1"), 8);
assert.equal(o.getOption("opt2"), 8);
assert.equal(o.getOption("forwarded"), 1);
assert.equal(o.getOption("new"), undefined);
o.setOption("new", 0);
assert.equal(o.getOption("new"), undefined);
assert.equal(o.getOption("initialValue"), 8);
o.setOption("initialValue", 7);
assert.equal(o.getOption("opt2"), 7);
config.setDefaultValues("test_object", {
opt1: 1,
forwarded: 2
});
config.resetOptions(o);
assert.equal(o.getOption("opt1"), 1);
assert.equal(o.getOption("forwarded"), 2);
}
};
if (typeof module !== "undefined" && module === require.main) {
require("asyncjs").test.testcase(module.exports).exec();
}