nadesiko3 3.2.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +107 -0
  3. package/bin/cnako3 +10 -0
  4. package/bin/cnako3.bat +11 -0
  5. package/bin/nako3server.bat +6 -0
  6. package/demo/ace_editor.html +90 -0
  7. package/demo/ace_editor_tabs.html +162 -0
  8. package/demo/basic.html +71 -0
  9. package/demo/browsers.html +128 -0
  10. package/demo/css/basic.css +3 -0
  11. package/demo/css/common.css +157 -0
  12. package/demo/css/editor.css +8 -0
  13. package/demo/css/flow.css +3 -0
  14. package/demo/css/index.css +3 -0
  15. package/demo/extlib/ace@1.4.12/ace.js +17 -0
  16. package/demo/extlib/ace@1.4.12/ext-code_lens.min.js +1 -0
  17. package/demo/extlib/ace@1.4.12/ext-language_tools.min.js +1 -0
  18. package/demo/extlib/ace@1.4.12/ext-options.min.js +1 -0
  19. package/demo/extlib/ace@1.4.12/ext-settings_menu.js +8 -0
  20. package/demo/extlib/ace@1.4.12/keybinding-vscode.js +8 -0
  21. package/demo/extlib/ace@1.4.12/theme-monokai.js +8 -0
  22. package/demo/extlib/ace@1.4.12/theme-xcode.js +8 -0
  23. package/demo/extlib/chart.js@3.2.1/chart.min.js +13 -0
  24. package/demo/extlib/pure-min.css +11 -0
  25. package/demo/flow.html +97 -0
  26. package/demo/graph.html +53 -0
  27. package/demo/image/nako.png +0 -0
  28. package/demo/image/nakopad-icon256.png +0 -0
  29. package/demo/image/turtle.fla +0 -0
  30. package/demo/image/turtle.png +0 -0
  31. package/demo/index.html +134 -0
  32. package/demo/js/common.js +17 -0
  33. package/demo/js/turtle3d_test.js +44 -0
  34. package/demo/js/turtle_test.js +44 -0
  35. package/demo/runscript.html +47 -0
  36. package/demo/runscript2.html +33 -0
  37. package/demo/turtle.html +58 -0
  38. package/demo/turtle2.html +141 -0
  39. package/demo/turtle3.html +278 -0
  40. package/demo/turtle3d.html +58 -0
  41. package/demo/turtle3d2.html +107 -0
  42. package/demo/version.html +24 -0
  43. package/doc/SETUP.md +172 -0
  44. package/doc/about.md +34 -0
  45. package/doc/browsers.md +60 -0
  46. package/doc/docgen.md +21 -0
  47. package/doc/editor.md +44 -0
  48. package/doc/files.md +37 -0
  49. package/doc/plugins.md +195 -0
  50. package/doc/release.md +78 -0
  51. package/doc/win32.md +57 -0
  52. package/package.json +196 -0
  53. package/release/_hash.txt +65 -0
  54. package/release/_script-tags.txt +13 -0
  55. package/release/command.json +1 -0
  56. package/release/command.json.js +1 -0
  57. package/release/command_cnako3.json +1 -0
  58. package/release/command_list.json +1 -0
  59. package/release/editor.js +2 -0
  60. package/release/editor.js.LICENSE.txt +32 -0
  61. package/release/josi.json +48 -0
  62. package/release/nako_gen_async.js +1 -0
  63. package/release/nako_gen_async.js.LICENSE.txt +595 -0
  64. package/release/plugin_caniuse.js +1 -0
  65. package/release/plugin_caniuse.js.LICENSE.txt +411 -0
  66. package/release/plugin_csv.js +1 -0
  67. package/release/plugin_csv.js.LICENSE.txt +367 -0
  68. package/release/plugin_datetime.js +1 -0
  69. package/release/plugin_datetime.js.LICENSE.txt +471 -0
  70. package/release/plugin_kansuji.js +1 -0
  71. package/release/plugin_kansuji.js.LICENSE.txt +491 -0
  72. package/release/plugin_markup.js +1 -0
  73. package/release/plugin_markup.js.LICENSE.txt +363 -0
  74. package/release/plugin_turtle.js +1 -0
  75. package/release/plugin_turtle.js.LICENSE.txt +435 -0
  76. package/release/plugin_webworker.js +1 -0
  77. package/release/plugin_webworker.js.LICENSE.txt +491 -0
  78. package/release/version.js +2 -0
  79. package/release/version.js.LICENSE.txt +32 -0
  80. package/release/wnako3.js +2 -0
  81. package/release/wnako3.js.LICENSE.txt +1 -0
  82. package/release/wnako3webworker.js +1 -0
  83. package/release/wnako3webworker.js.LICENSE.txt +847 -0
  84. package/release/yoyakugo.json +30 -0
  85. package/src/browsers.md +60 -0
  86. package/src/cnako3.js +466 -0
  87. package/src/commander_ja.js +154 -0
  88. package/src/enako3.js +69 -0
  89. package/src/era.json +22 -0
  90. package/src/index.js +5 -0
  91. package/src/nako3.js +836 -0
  92. package/src/nako3_assert.js +37 -0
  93. package/src/nako3editorfix.sfd +106 -0
  94. package/src/nako3editorfix.woff +0 -0
  95. package/src/nako3server.js +51 -0
  96. package/src/nako_colors.js +86 -0
  97. package/src/nako_errors.js +176 -0
  98. package/src/nako_gen.js +1459 -0
  99. package/src/nako_gen_async.js +1622 -0
  100. package/src/nako_global.js +113 -0
  101. package/src/nako_indent.js +480 -0
  102. package/src/nako_josi_list.js +46 -0
  103. package/src/nako_lex_rules.js +259 -0
  104. package/src/nako_lexer.js +576 -0
  105. package/src/nako_logger.js +138 -0
  106. package/src/nako_parser3.js +1768 -0
  107. package/src/nako_parser_base.js +265 -0
  108. package/src/nako_parser_const.js +37 -0
  109. package/src/nako_prepare.js +293 -0
  110. package/src/nako_reserved_words.js +35 -0
  111. package/src/nako_source_mapping.js +251 -0
  112. package/src/nako_test.js +37 -0
  113. package/src/nako_version.js +8 -0
  114. package/src/plugin_browser.js +191 -0
  115. package/src/plugin_browser_ajax.js +352 -0
  116. package/src/plugin_browser_audio.js +109 -0
  117. package/src/plugin_browser_canvas.js +462 -0
  118. package/src/plugin_browser_chart.js +296 -0
  119. package/src/plugin_browser_color.js +49 -0
  120. package/src/plugin_browser_crypto.js +26 -0
  121. package/src/plugin_browser_dialog.js +53 -0
  122. package/src/plugin_browser_dom_basic.js +322 -0
  123. package/src/plugin_browser_dom_event.js +193 -0
  124. package/src/plugin_browser_dom_parts.js +163 -0
  125. package/src/plugin_browser_geolocation.js +51 -0
  126. package/src/plugin_browser_hotkey.js +25 -0
  127. package/src/plugin_browser_html.js +59 -0
  128. package/src/plugin_browser_in_worker.js +44 -0
  129. package/src/plugin_browser_location.js +21 -0
  130. package/src/plugin_browser_speech.js +111 -0
  131. package/src/plugin_browser_storage.js +121 -0
  132. package/src/plugin_browser_system.js +12 -0
  133. package/src/plugin_browser_websocket.js +73 -0
  134. package/src/plugin_caniuse.js +24 -0
  135. package/src/plugin_csv.js +57 -0
  136. package/src/plugin_datetime.js +414 -0
  137. package/src/plugin_express.js +212 -0
  138. package/src/plugin_kansuji.js +224 -0
  139. package/src/plugin_keigo.js +55 -0
  140. package/src/plugin_markup.js +32 -0
  141. package/src/plugin_math.js +319 -0
  142. package/src/plugin_node.js +1018 -0
  143. package/src/plugin_promise.js +94 -0
  144. package/src/plugin_system.js +2109 -0
  145. package/src/plugin_test.js +38 -0
  146. package/src/plugin_turtle.js +646 -0
  147. package/src/plugin_webworker.js +334 -0
  148. package/src/plugin_weykturtle3d.js +1216 -0
  149. package/src/plugin_worker.js +92 -0
  150. package/src/repl.nako3 +63 -0
  151. package/src/turtle-elephant.png +0 -0
  152. package/src/turtle-panda.png +0 -0
  153. package/src/turtle64.png +0 -0
  154. package/src/wnako3.js +162 -0
  155. package/src/wnako3_editor.css +215 -0
  156. package/src/wnako3_editor.js +1645 -0
  157. package/src/wnako3_editor_marker_red.png +0 -0
  158. package/src/wnako3_editor_marker_red.xcf +0 -0
  159. package/src/wnako3_editor_marker_yellow.png +0 -0
  160. package/src/wnako3_editor_marker_yellow.xcf +0 -0
  161. package/src/wnako3webworker.js +70 -0
  162. package/test/ace_editor/karma.config.js +94 -0
  163. package/test/ace_editor/test/.babelrc.json +3 -0
  164. package/test/ace_editor/test/ace_editor_test.js +178 -0
  165. package/test/ace_editor/test/html/custom_context.html +140 -0
  166. package/test/async/async_basic_test.js +124 -0
  167. package/test/browser/karma.config.js +212 -0
  168. package/test/browser/test/.babelrc.json +3 -0
  169. package/test/browser/test/compare_util.js +50 -0
  170. package/test/browser/test/html/canvas_basic.html +1 -0
  171. package/test/browser/test/html/div_basic.html +2 -0
  172. package/test/browser/test/html/event_dom_form.html +4 -0
  173. package/test/browser/test/html/event_dom_scrolldiv.html +5 -0
  174. package/test/browser/test/image/canvas_test1.png +0 -0
  175. package/test/browser/test/image/canvas_test2.png +0 -0
  176. package/test/browser/test/image/canvas_test3.png +0 -0
  177. package/test/browser/test/image/canvas_test4.png +0 -0
  178. package/test/browser/test/image/canvas_test7.png +0 -0
  179. package/test/browser/test/image/canvas_test8.png +0 -0
  180. package/test/browser/test/image/canvas_test_blank.png +0 -0
  181. package/test/browser/test/image/elephant_kana.png +0 -0
  182. package/test/browser/test/image/panda_kana.png +0 -0
  183. package/test/browser/test/image/turtle_kana.png +0 -0
  184. package/test/browser/test/import_plugin_checker.js +24 -0
  185. package/test/browser/test/plugin_browser_test.js +52 -0
  186. package/test/browser/test/plugin_browser_test_ajax.js +123 -0
  187. package/test/browser/test/plugin_browser_test_color.js +18 -0
  188. package/test/browser/test/plugin_browser_test_dialog.js +72 -0
  189. package/test/browser/test/plugin_browser_test_dom_event.js +598 -0
  190. package/test/browser/test/plugin_browser_test_dom_parts.js +125 -0
  191. package/test/browser/test/plugin_browser_test_system.js +9 -0
  192. package/test/browser/test/plugin_turtle_test.js +817 -0
  193. package/test/browser/test/plugin_webworker_test.js +87 -0
  194. package/test/browser/test/require_test.js +71 -0
  195. package/test/bundled/karma.config.base.js +117 -0
  196. package/test/bundled/karma.config.js +86 -0
  197. package/test/bundled/test/.babelrc.json +3 -0
  198. package/test/bundled/test/bundled_test.js +69 -0
  199. package/test/bundled/test/html/custom_context.html +65 -0
  200. package/test/bundled/test/html/custom_debug.html +66 -0
  201. package/test/bundled/test4b.cmd +52 -0
  202. package/test/bundled/test_base/.babelrc.json +3 -0
  203. package/test/bundled/test_base/_checktool_test.js +25 -0
  204. package/test/bundled/test_base/basic_ajax_test.js +56 -0
  205. package/test/bundled/test_base/basic_async_test.js +18 -0
  206. package/test/bundled/test_base/basic_test.js +153 -0
  207. package/test/bundled/test_base/calc_test.js +132 -0
  208. package/test/bundled/test_base/css/browsers_box.css +114 -0
  209. package/test/bundled/test_base/html/custom_context.html +69 -0
  210. package/test/bundled/test_base/html/custom_debug.html +71 -0
  211. package/test/bundled/test_base/js/browsers_box.js +72 -0
  212. package/test/bundled/test_base/plugin_csv_test.js +37 -0
  213. package/test/bundled/test_base/plugin_datetime_test.js +115 -0
  214. package/test/bundled/test_base/plugin_kansuji_test.js +49 -0
  215. package/test/bundled/test_base/plugin_system_test.js +410 -0
  216. package/test/bundled/test_base/plugin_webworker_test.js +53 -0
  217. package/test/bundled/test_base/resources/ok.txt +1 -0
  218. package/test/bundled/test_base/test_utils.js +191 -0
  219. package/test/common/array_test.js +40 -0
  220. package/test/common/basic_test.js +317 -0
  221. package/test/common/calc_test.js +139 -0
  222. package/test/common/debug_test.js +16 -0
  223. package/test/common/error_test.js +16 -0
  224. package/test/common/flow_test.js +360 -0
  225. package/test/common/func_call.js +136 -0
  226. package/test/common/func_test.js +149 -0
  227. package/test/common/indent_test.js +362 -0
  228. package/test/common/lex_test.js +146 -0
  229. package/test/common/literal_test.js +72 -0
  230. package/test/common/nako_logger_test.js +26 -0
  231. package/test/common/plugin_browser_test.js +24 -0
  232. package/test/common/plugin_browser_ut_audio_test.js +88 -0
  233. package/test/common/plugin_browser_ut_color_test.js +21 -0
  234. package/test/common/plugin_browser_ut_dialog_test.js +100 -0
  235. package/test/common/plugin_browser_ut_html_test.js +13 -0
  236. package/test/common/plugin_browser_ut_system_test.js +10 -0
  237. package/test/common/plugin_csv_test.js +39 -0
  238. package/test/common/plugin_datetime_test.js +120 -0
  239. package/test/common/plugin_kansuji_test.js +59 -0
  240. package/test/common/plugin_promise_test.js +18 -0
  241. package/test/common/plugin_system_test.js +451 -0
  242. package/test/common/prepare_test.js +93 -0
  243. package/test/common/re_test.js +20 -0
  244. package/test/common/variable_scope_test.js +105 -0
  245. package/test/jsconfig.json +19 -0
  246. package/test/karma.config.js +91 -0
  247. package/test/node/add_test.nako3 +1 -0
  248. package/test/node/async_test.js +80 -0
  249. package/test/node/commander_ja_test.js +82 -0
  250. package/test/node/error_message_test.js +244 -0
  251. package/test/node/kai_test.nako3 +6 -0
  252. package/test/node/node_test.js +43 -0
  253. package/test/node/plugin_broken.js.txt +3 -0
  254. package/test/node/plugin_browser_ut_ajax_test.js +355 -0
  255. package/test/node/plugin_browser_ut_location_test.js +32 -0
  256. package/test/node/plugin_markup_test.js +44 -0
  257. package/test/node/plugin_math_test.js +42 -0
  258. package/test/node/plugin_node_test.js +93 -0
  259. package/test/node/plugin_test.js +16 -0
  260. package/test/node/relative_import_test_1.nako3 +1 -0
  261. package/test/node/relative_import_test_2.nako3 +2 -0
  262. package/test/node/require_nako3_test.js +59 -0
  263. package/test/node/requiretest.nako3 +4 -0
  264. package/test/node/requiretest_indirect.nako3 +1 -0
  265. package/test/node/requiretest_name.nako3 +5 -0
  266. package/test/node/runtime_error.nako3 +2 -0
  267. package/test/node/side_effects_test.js +106 -0
  268. package/test/node/sjis.txt +5 -0
  269. package/test/node/syntax_error.nako3 +2 -0
  270. package/test/node/wnako3_editor_test.js +360 -0
  271. package/tools/README.md +7 -0
  272. package/tools/nako3edit/html/edit.html +83 -0
  273. package/tools/nako3edit/html/edit_plugin.js +6 -0
  274. package/tools/nako3edit/html/files.html +49 -0
  275. package/tools/nako3edit/html/nako3edit.css +66 -0
  276. package/tools/nako3edit/index.nako3 +145 -0
  277. package/tools/nako3edit/run.js +12 -0
  278. package/tools/nako3server/html/edit.html +104 -0
  279. package/tools/nako3server/html/edit_plugin.js +6 -0
  280. package/tools/nako3server/html/files.html +53 -0
  281. package/tools/nako3server/html/nako3edit.css +66 -0
  282. package/tools/nako3server/index.nako3 +129 -0
  283. package/tools/nako3server/run.js +12 -0
@@ -0,0 +1,355 @@
1
+ const assert = require('assert').strict
2
+ const PluginBrowser = require('../../src/plugin_browser')
3
+ const { PluginUtHelper } = require('../../utils/plugin_ut_helper')
4
+ const fetchMock = require('fetch-mock')
5
+ const FormDataBase = require('form-data')
6
+ class FormData extends FormDataBase {
7
+ constructor () {
8
+ super()
9
+ this.param_list = new Map()
10
+ }
11
+
12
+ set (k, v) {
13
+ this.append(k, v)
14
+ this.param_list.set(k, v)
15
+ }
16
+
17
+ get (k) {
18
+ return this.param_list.get(k)
19
+ }
20
+ }
21
+ global.FormData = FormData
22
+
23
+ describe('plugin_browser_ajax', () => {
24
+ const cu = new PluginUtHelper(PluginBrowser)
25
+
26
+ const setupSys = () => {
27
+ const sys = {}
28
+ sys.__v0 = {}
29
+ sys.__v0['対象'] = ''
30
+ sys.__v0['AJAXオプション'] = ''
31
+ sys.__v0['AJAX:ONERROR'] = (e) => {
32
+ assert.fail('ajax error')
33
+ }
34
+ sys.__findVar = function (nameStr, def) {
35
+ if (typeof nameStr === 'function') { return nameStr }
36
+ if (PluginBrowser[nameStr]) { return PluginBrowser[nameStr].fn }
37
+ return def
38
+ }
39
+ sys.__exec = function (func, params) {
40
+ const f = sys.__findVar(func)
41
+ if (!f) { throw new Error('システム関数でエイリアスの指定ミス:' + func) }
42
+ return f.apply(this, params)
43
+ }
44
+ sys.resolveCount = 0
45
+ return sys
46
+ }
47
+
48
+ afterEach(() => {
49
+ fetchMock.reset()
50
+ })
51
+
52
+ it('AJAX送信時', async () => {
53
+ fetchMock.get(/^\/dummyutl$/, 'ajax result')
54
+
55
+ const sys = setupSys()
56
+ sys.__v0['AJAX:ONERROR'] = (e) => {
57
+ assert.equal(e.message, 'unknown error')
58
+ }
59
+
60
+ PluginBrowser['AJAX送信時'].fn.apply(this, [() => {
61
+ assert.equal(sys.__v0['対象'], 'ajax result')
62
+ }, '/dummyutl', sys])
63
+ })
64
+ it('GET送信時 - error', async () => {
65
+ fetchMock.get(/^\/reject$/, { throws: new Error('unknown error') })
66
+
67
+ const sys = setupSys()
68
+ sys.__v0.options = {
69
+ method: 'GET'
70
+ }
71
+ sys.__v0['AJAX:ONERROR'] = (e) => {
72
+ assert.equal(e.message, 'unknown error')
73
+ }
74
+
75
+ PluginBrowser['GET送信時'].fn.apply(this, [() => {
76
+ assert.fail('no exception')
77
+ }, '/reject', sys])
78
+ })
79
+
80
+ it('POSTデータ生成', () => {
81
+ const param = {
82
+ KEY: 'VALUE',
83
+ _X: 'XE^ZA',
84
+ SPACE: ' '
85
+ }
86
+
87
+ cu.cmpfn('POSTデータ生成', [param], 'KEY=VALUE&_X=XE%5EZA&SPACE=%20')
88
+ })
89
+
90
+ it('POST送信時', async () => {
91
+ fetchMock.post(
92
+ (url, opts) => {
93
+ return (
94
+ url === '/post' &&
95
+ opts.body === 'param1=data1%5E&param2=data2%5E%5E'
96
+ )
97
+ },
98
+ { body: 'post result' }
99
+ )
100
+
101
+ const sys = setupSys()
102
+
103
+ const param = {
104
+ param1: 'data1^',
105
+ param2: 'data2^^'
106
+ }
107
+
108
+ PluginBrowser['POST送信時'].fn.apply(this, [() => {
109
+ assert.equal(sys.__v0['対象'], 'post result')
110
+ }, '/post', param, sys])
111
+ })
112
+
113
+ it('POST送信時 - error', async () => {
114
+ fetchMock.post(/^\/postreject$/, { throws: new Error('unknown error') })
115
+
116
+ const sys = setupSys()
117
+ sys.__v0['AJAX:ONERROR'] = (e) => {
118
+ assert.equal(e.message, 'unknown error')
119
+ }
120
+
121
+ PluginBrowser['POST送信時'].fn.apply(this, [() => {
122
+ assert.fail('no exception')
123
+ }, '/postreject', {}, sys])
124
+ })
125
+
126
+ it('POSTフォーム送信時', async () => {
127
+ fetchMock.post(
128
+ (url, opts) => {
129
+ const fd = opts.body
130
+ return (
131
+ url === '/post' &&
132
+ fd.get('param1') === 'data1^' &&
133
+ fd.get('param2') === 'data2^^'
134
+ )
135
+ },
136
+ { body: 'post result' }
137
+ )
138
+
139
+ const sys = setupSys()
140
+
141
+ const param = {
142
+ param1: 'data1^',
143
+ param2: 'data2^^'
144
+ }
145
+ PluginBrowser['POSTフォーム送信時'].fn.apply(this, [() => {
146
+ assert.equal(sys.__v0['対象'], 'post result')
147
+ }, '/post', param, sys])
148
+ })
149
+
150
+ it('POSTフォーム送信時 - error', async () => {
151
+ fetchMock.post(/^\/postreject$/, { throws: new Error('unknown error') })
152
+
153
+ const sys = setupSys()
154
+ sys.__v0['AJAX:ONERROR'] = (e) => {
155
+ assert.equal(e.message, 'unknown error')
156
+ }
157
+
158
+ const param = {
159
+ param1: 'data1^',
160
+ param2: 'data2^^'
161
+ }
162
+ PluginBrowser['POSTフォーム送信時'].fn.apply(this, [() => {
163
+ assert.fail('no exception')
164
+ }, '/postreject', param, sys])
165
+ })
166
+
167
+ it('AJAX失敗時', () => {
168
+ const sys = setupSys()
169
+ const func = (e) => {
170
+ return e
171
+ }
172
+
173
+ PluginBrowser['AJAX失敗時'].fn.apply(this, [func, sys])
174
+ assert.equal(sys.__v0['AJAX:ONERROR'], func)
175
+ })
176
+
177
+ it('AJAXオプション設定', () => {
178
+ const sys = setupSys()
179
+ const param = {
180
+ KEY: 'VALUE'
181
+ }
182
+
183
+ PluginBrowser['AJAXオプション設定'].fn.apply(this, [param, sys])
184
+ assert.equal(sys.__v0['AJAXオプション'], param)
185
+ })
186
+
187
+ it('AJAX送信', async () => {
188
+ fetchMock.get(/^\/dummyutl$/, 'ajax result')
189
+ const sys = setupSys()
190
+ const promise = new Promise((resolve, reject) => {
191
+ sys.resolve = resolve
192
+ sys.reject = reject
193
+ PluginBrowser['AJAX送信'].fn.apply(this, ['/dummyutl', sys])
194
+ })
195
+ await promise
196
+ assert.equal(sys.__v0['対象'], 'ajax result')
197
+ })
198
+
199
+ it('AJAX送信 - error', async () => {
200
+ fetchMock.get(/^\/ajaxreject$/, { throws: new Error('unknown error') })
201
+
202
+ const sys = setupSys()
203
+ const promise = new Promise((resolve, reject) => {
204
+ sys.resolve = resolve
205
+ sys.reject = (err) => {
206
+ assert.equal(err, 'unknown error')
207
+ resolve()
208
+ }
209
+ PluginBrowser['AJAX送信'].fn.apply(this, ['/ajaxreject', sys])
210
+ })
211
+
212
+ await promise
213
+ })
214
+
215
+ it('HTTP取得 - error', async () => {
216
+ fetchMock.get(/^\/ajaxreject$/, { throws: new Error('unknown error') })
217
+
218
+ const sys = setupSys()
219
+ const promise = new Promise((resolve, reject) => {
220
+ sys.resolve = resolve
221
+ sys.reject = (err) => {
222
+ assert.equal(err, 'unknown error')
223
+ resolve()
224
+ }
225
+ PluginBrowser['HTTP取得'].fn.apply(this, ['/ajaxreject', sys])
226
+ })
227
+
228
+ await promise
229
+ })
230
+
231
+ it('AJAX送信 - error(without 逐次実行)', async () => {
232
+ fetchMock.get(/^\/ajaxreject$/, 'ajax result')
233
+
234
+ const sys = setupSys()
235
+ cu.cmpfnex('AJAX送信', ['/ajaxreject', sys], 'Error', '『AJAX送信』は『逐次実行』構文内で利用する必要があります。')
236
+ })
237
+
238
+ it('POST送信', async () => {
239
+ fetchMock.post(
240
+ (url, opts) => {
241
+ return (
242
+ url === '/post' &&
243
+ opts.body === 'param1=data1%5E&param2=data2%5E%5E'
244
+ )
245
+ },
246
+ { body: 'post result' }
247
+ )
248
+
249
+ const sys = setupSys()
250
+ const promise = new Promise((resolve, reject) => {
251
+ sys.resolve = resolve
252
+ sys.reject = reject
253
+
254
+ const param = {
255
+ param1: 'data1^',
256
+ param2: 'data2^^'
257
+ }
258
+
259
+ PluginBrowser['POST送信'].fn.apply(this, ['/post', param, sys])
260
+ })
261
+
262
+ await promise
263
+
264
+ assert.equal(sys.__v0['対象'], 'post result')
265
+ })
266
+
267
+ it('POST送信 - error', async () => {
268
+ fetchMock.post(/^\/ajaxreject$/, { throws: new Error('unknown error') })
269
+
270
+ const sys = setupSys()
271
+ const promise = new Promise((resolve, reject) => {
272
+ sys.resolve = resolve
273
+ sys.reject = (err) => {
274
+ assert.equal(err, 'unknown error')
275
+ resolve()
276
+ }
277
+ const param = {
278
+ param1: 'data1^',
279
+ param2: 'data2^^'
280
+ }
281
+ PluginBrowser['POST送信'].fn.apply(this, ['/ajaxreject', param, sys])
282
+ })
283
+
284
+ await promise
285
+ })
286
+
287
+ it('POST送信 - error(without 逐次実行)', async () => {
288
+ fetchMock.post(/^\/ajaxreject$/, 'ajax result')
289
+
290
+ const sys = setupSys()
291
+
292
+ cu.cmpfnex('POST送信', ['/ajaxreject', {}, sys], 'Error', '『POST送信』は『逐次実行』構文内で利用する必要があります。')
293
+ })
294
+
295
+ it('POSTフォーム送信', async () => {
296
+ fetchMock.post(
297
+ (url, opts) => {
298
+ const fd = opts.body
299
+ return (
300
+ url === '/post' &&
301
+ fd.get('param1') === 'data1^' &&
302
+ fd.get('param2') === 'data2^^'
303
+ )
304
+ },
305
+ { body: 'post result' }
306
+ )
307
+
308
+ const sys = setupSys()
309
+ const promise = new Promise((resolve, reject) => {
310
+ sys.resolve = resolve
311
+ sys.reject = (err) => {
312
+ assert.equal(err, 'unknown error')
313
+ resolve()
314
+ }
315
+
316
+ const param = {
317
+ param1: 'data1^',
318
+ param2: 'data2^^'
319
+ }
320
+
321
+ PluginBrowser['POSTフォーム送信'].fn.apply(this, ['/post', param, sys])
322
+ })
323
+
324
+ await promise
325
+
326
+ assert.equal(sys.__v0['対象'], 'post result')
327
+ })
328
+
329
+ it('POSTフォーム送信 - error', async () => {
330
+ fetchMock.post(/^\/ajaxreject$/, { throws: new Error('unknown error') })
331
+
332
+ const sys = setupSys()
333
+ const promise = new Promise((resolve, reject) => {
334
+ sys.resolve = resolve
335
+ sys.reject = (err) => {
336
+ assert.equal(err, 'unknown error')
337
+ resolve()
338
+ }
339
+ const param = {
340
+ param1: 'data1^',
341
+ param2: 'data2^^'
342
+ }
343
+ PluginBrowser['POSTフォーム送信'].fn.apply(this, ['/ajaxreject', param, sys])
344
+ })
345
+
346
+ await promise
347
+ })
348
+
349
+ it('POSTフォーム送信 - error(without 逐次実行)', async () => {
350
+ fetchMock.post(/^\/ajaxreject$/, 'ajax result')
351
+
352
+ const sys = setupSys()
353
+ cu.cmpfnex('POSTフォーム送信', ['/ajaxreject', {}, sys], 'Error', '『POSTフォーム送信』は『逐次実行』構文内で利用する必要があります。')
354
+ })
355
+ })
@@ -0,0 +1,32 @@
1
+ const td = require('testdouble')
2
+ const assert = require('assert').strict
3
+ const PluginBrowser = require('../../src/plugin_browser')
4
+
5
+ describe('plugin_browser_location', () => {
6
+ describe('location-url', () => {
7
+ const chkurl = (args, res) => {
8
+ global.window = {}
9
+ global.window.location = {}
10
+ global.window.location.href = ''
11
+ PluginBrowser['ブラウザ移動'].fn.apply(this, args)
12
+ assert.equal(global.window.location.href, res)
13
+ }
14
+ it('ブラウザ移動', () => {
15
+ chkurl(['http://url'], 'http://url')
16
+ })
17
+ })
18
+ describe('history-back', () => {
19
+ const chkback = (args, msg) => {
20
+ const fakeBack = td.func('back')
21
+ global.window = {}
22
+ global.window.history = {}
23
+ global.window.history.back = fakeBack
24
+ td.when(fakeBack(msg)).thenReturn(undefined)
25
+ PluginBrowser['ブラウザ戻'].fn.apply(this, args)
26
+ td.verify(fakeBack(td.matchers.anything()), { times: 1 })
27
+ }
28
+ it('ブラウザ戻', () => {
29
+ chkback([], -1)
30
+ })
31
+ })
32
+ })
@@ -0,0 +1,44 @@
1
+ const assert = require('assert')
2
+ const NakoCompiler = require('../../src/nako3')
3
+ const PluginMarkup = require('../../src/plugin_markup')
4
+ const CNako3 = require('../../src/cnako3')
5
+
6
+ describe('plugin_markup_test', () => {
7
+ const wnako = new NakoCompiler()
8
+ // wnako.logger.addListener('trace', ({ nodeConsole }) => { console.log(nodeConsole) })
9
+ wnako.addPluginFile('PluginMarkup', 'plugin_markup.js', PluginMarkup)
10
+
11
+ const cnako = new CNako3()
12
+ cnako.silent = true
13
+
14
+ const cmp = (code, res) => {
15
+ for (let nako of [cnako, wnako]) {
16
+ let c = code
17
+
18
+ if (nako === cnako) {
19
+ c = '!「plugin_markup.js」を取り込む。\n' + c
20
+ }
21
+
22
+ nako.logger.debug('code=' + code)
23
+
24
+ assert.strictEqual(nako.run(c).log, res)
25
+ }
26
+ }
27
+
28
+ // --- test ---
29
+ it('マークダウンHTML変換', () => {
30
+ cmp('「# test\n* 1234\n\t* ABCD」をマークダウンHTML変換して表示', '<h1 id="test">test</h1>\n<ul>\n<li>1234<ul>\n<li>ABCD</li>\n</ul>\n</li>\n</ul>')
31
+ })
32
+ it('HTML整形', () => {
33
+ cmp('「<h1>test</h1>\n\n<ul><li>1234<ul><li>ABCD</li></ul></li></ul>」をHTML整形して表示',
34
+ '<h1>test</h1>\n' +
35
+ '\n' +
36
+ '<ul>\n' +
37
+ ' <li>1234\n' +
38
+ ' <ul>\n' +
39
+ ' <li>ABCD</li>\n' +
40
+ ' </ul>\n' +
41
+ ' </li>\n' +
42
+ '</ul>')
43
+ })
44
+ })
@@ -0,0 +1,42 @@
1
+ const assert = require('assert')
2
+ const NakoCompiler = require('../../src/nako3')
3
+ const CNako3 = require('../../src/cnako3')
4
+
5
+ describe('plugin_math_test', () => {
6
+ const wnako = new NakoCompiler()
7
+
8
+ const cnako = new CNako3()
9
+ cnako.silent = true
10
+ // wnako.logger.addListener('trace', ({ nodeConsole }) => { console.log(nodeConsole) })
11
+
12
+ const cmp = (code, res) => {
13
+ for (let nako of [cnako, wnako]) {
14
+ let c = code
15
+ nako.logger.debug('code=' + code)
16
+ assert.strictEqual(nako.run(c).log, res)
17
+ }
18
+ }
19
+
20
+ // --- test ---
21
+ it('算術関数/SIGN', () => {
22
+ cmp('-5のSIGNを表示', '-1')
23
+ cmp('-5の符号を表示', '-1')
24
+ cmp('5の符号を表示', '1')
25
+ cmp('0の符号を表示', '0')
26
+ })
27
+ it('算術関数/FRAC', () => {
28
+ cmp('5.5のFRACを表示', '0.5')
29
+ cmp('5.5の小数部分を表示', '0.5')
30
+ cmp('3.14の整数部分を表示', '3')
31
+ cmp('-3.14の整数部分を表示', '-3')
32
+ })
33
+ it('ATAN2', () => {
34
+ cmp('90と15のATAN2を表示', '1.4056476493802699')
35
+ cmp('15と90のATAN2を表示', '0.16514867741462683')
36
+ })
37
+ it('座標角度計算 (#875)', () => {
38
+ cmp('[10,10]の座標角度計算して表示', '45')
39
+ cmp('[0,10]の座標角度計算して表示', '90')
40
+ cmp('[10,0]の座標角度計算して表示', '0')
41
+ })
42
+ })
@@ -0,0 +1,93 @@
1
+ const assert = require('assert')
2
+ const path = require('path')
3
+ const NakoCompiler = require('../../src/nako3')
4
+ const PluginNode = require('../../src/plugin_node')
5
+ const PluginCSV = require('../../src/plugin_csv')
6
+
7
+ const testFileMe = path.join(__dirname, 'plugin_node_test.js')
8
+
9
+ describe('plugin_node_test', () => {
10
+ const nako = new NakoCompiler()
11
+ // nako.logger.addListener('trace', ({ browserConsole }) => { console.log(...browserConsole) })
12
+ nako.addPluginFile('PluginNode', 'plugin_node.js', PluginNode)
13
+ nako.addPluginFile('PluginCSV', 'plugin_csv.js', PluginCSV)
14
+ const cmp = (code, res) => {
15
+ nako.logger.debug('code=' + code)
16
+ assert.strictEqual(nako.run(code).log, res)
17
+ }
18
+ const cmd = (code) => {
19
+ nako.logger.debug('code=' + code)
20
+ nako.run(code)
21
+ }
22
+ // --- test ---
23
+ it('表示', () => {
24
+ cmp('3を表示', '3')
25
+ cmp('1+2*3を表示', '7')
26
+ cmp('A=30;「--{A}--」を表示', '--30--')
27
+ })
28
+ it('存在1', () => {
29
+ cmp('「/xxx/xxx/xxx/xxx」が存在;もしそうならば;「NG」と表示。違えば「OK」と表示。', 'OK')
30
+ })
31
+ it('存在2', () => {
32
+ cmp('「' + testFileMe + '」が存在;もしそうならば;「OK」と表示。違えば「NG」と表示。', 'OK')
33
+ })
34
+ it('フォルダ存在', () => {
35
+ const dir = __dirname
36
+ cmp('「' + dir + '」が存在;もしそうならば;「OK」と表示。違えば「NG」と表示。', 'OK')
37
+ cmp('「' + dir + '/xxx」が存在;もしそうならば;「OK」と表示。違えば「NG」と表示。', 'NG')
38
+ })
39
+ it('ASSERT', () => {
40
+ cmd('3と3がASSERT等')
41
+ })
42
+ it('環境変数取得', () => {
43
+ const path = process.env['PATH']
44
+ cmp('「PATH」の環境変数取得して表示。', path)
45
+ })
46
+ it('圧縮解凍', () => {
47
+ let path7z = '7z'
48
+ if (process.platform === 'win32') {
49
+ path7z = path.join(__dirname, '../../bin/7z.exe')
50
+ }
51
+ cmp('FIN=「' + testFileMe + '」;' +
52
+ 'HOME=ホームディレクトリ取得;' +
53
+ 'TMP=HOME&"/.temp";' +
54
+ '「' + path7z + '」に圧縮解凍ツールパス変更;' +
55
+ 'もし、!(TMPが存在する)ならば、TMPのフォルダ作成。' +
56
+ 'FZIP=「{TMP}/test.zip」;\n' +
57
+ 'FINをFZIPへ圧縮。FZIPを「{TMP}/」に解凍。\n' +
58
+ 'S1=「{TMP}/plugin_node_test.js」を読む。\n' +
59
+ 'S2=FINを読む。\n' +
60
+ 'もし(S1=S2)ならば、"OK"と表示。\n', 'OK')
61
+ })
62
+ it('ファイルサイズ取得', () => {
63
+ cmp('「' + testFileMe + '」のファイルサイズ取得;もし、それが2000以上ならば;「OK」と表示。違えば「NG」と表示。', 'OK')
64
+ })
65
+ it('ファイル情報取得', () => {
66
+ cmp('「' + testFileMe + '」のファイル情報取得;もし、それ["size"]が2000以上ならば;「OK」と表示。違えば「NG」と表示。', 'OK')
67
+ })
68
+ it('クリップボード', () => {
69
+ try {
70
+ const rnd = 'a' + Math.random()
71
+ cmp('クリップボード="' + rnd + '";クリップボードを表示。', rnd)
72
+ } catch (err) {
73
+ // テストは必須ではない(Linuxコンソール環境に配慮)
74
+ }
75
+ })
76
+ it('文字エンコーディング', () => {
77
+ const sjisfile = path.join(__dirname, "sjis.txt")
78
+ cmp(`「${sjisfile}」をバイナリ読む。` +
79
+ 'SJIS取得。CSV取得してCに代入。C[2][1]を表示',
80
+ 'ホームセンター')
81
+ cmp(`「${sjisfile}」をバイナリ読む。` +
82
+ '「Shift_JIS」からエンコーディング取得。' +
83
+ 'CSV取得してCに代入。C[2][1]を表示',
84
+ 'ホームセンター')
85
+ })
86
+ it('ハッシュ値計算', () => {
87
+ cmp('「hello world」を「sha256」の「base64」でハッシュ値計算して表示。', 'uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=')
88
+ cmp('「hello world」を「sha256」の「hex」でハッシュ値計算して表示。', 'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9')
89
+ cmp('「some data to hash」を「sha256」の「hex」でハッシュ値計算して表示。', '6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50')
90
+ })
91
+ })
92
+
93
+
@@ -0,0 +1,16 @@
1
+ const assert = require('assert')
2
+ const CNako3 = require('../../src/cnako3')
3
+
4
+ describe('plugin_test', () => {
5
+ const nako = new CNako3()
6
+ // nako.logger.addListener('trace', ({ browserConsole }) => { console.log(...browserConsole) })
7
+ nako.silent = true
8
+ const cmp = (code, res) => {
9
+ nako.logger.debug('code=' + code)
10
+ const ret = nako.run(code)
11
+ assert.strictEqual(ret.log, res)
12
+ }
13
+ it('「取り込む」', () => {
14
+ cmp('!「nadesiko3-hoge」を取り込む。\n3と5をHOGE足して、表示。', '8')
15
+ })
16
+ })
@@ -0,0 +1 @@
1
+ 1を表示
@@ -0,0 +1,2 @@
1
+ !「./relative_import_test_1.nako3」を取り込む
2
+ 2を表示
@@ -0,0 +1,59 @@
1
+ const assert = require('assert')
2
+ const { NakoImportError } = require('../../src/nako_errors')
3
+ const CNako3 = require('../../src/cnako3')
4
+ const path = require('path')
5
+
6
+ describe('require_nako3_test', () => {
7
+ const nako = new CNako3()
8
+ // nako.logger.addListener('trace', ({ browserConsole }) => { console.log(...browserConsole) })
9
+ nako.silent = true
10
+ const cmp = (code, res) => {
11
+ nako.logger.debug('code=' + code)
12
+ const ret = nako.run(code, 'main.nako3')
13
+ assert.strictEqual(ret.log, res)
14
+ }
15
+ it('「ファイルを取り込む」', () => {
16
+ cmp('!「' + __dirname + '/requiretest.nako3」を取り込む。\n痕跡を表示。3と5を痕跡演算して、表示。', '5\n8')
17
+ })
18
+ it('CNakoの相対インポート', () => {
19
+ cmp('!「' + __dirname + '/relative_import_test_2.nako3」を取り込む。', '1\n2')
20
+ })
21
+ it('「回」が1回だけ分割されることを確認する', () => {
22
+ cmp('!「' + __dirname + '/kai_test.nako3」を取り込む', '')
23
+ })
24
+ it('.jsと.nako3を同時に読み込む - .jsが先の場合', () => {
25
+ const nako = new CNako3()
26
+ const code =
27
+ `!「plugin_csv」を取り込む。\n` +
28
+ `!「${__dirname}/requiretest.nako3」を取り込む。\n`
29
+ nako.loadDependencies(code, 'main.nako3', '')
30
+ nako.run(code, 'main.nako3') // エラーが飛ばないことを確認
31
+ })
32
+ it('.jsと.nako3を同時に読み込む - .nako3が先の場合', () => {
33
+ const nako = new CNako3()
34
+ const code =
35
+ `!「${__dirname}/requiretest.nako3」を取り込む。\n` +
36
+ `!「plugin_csv」を取り込む。\n`
37
+ nako.loadDependencies(code, 'main.nako3', '')
38
+ nako.run(code, 'main.nako3') // エラーが飛ばないことを確認
39
+ })
40
+ it('.jsファイルの投げたエラーを表示', () => {
41
+ const nako = new CNako3()
42
+ const code = `!「${__dirname}/plugin_broken.js.txt」を取り込む`
43
+ nako.loadDependencies(code, 'main.nako3', '')
44
+ assert.throws(
45
+ () => nako.run(code, 'main.nako3'),
46
+ (err) => {
47
+ assert(err instanceof NakoImportError)
48
+ assert(err.message.includes("テスト"))
49
+ assert.strictEqual(err.line, 0) // 1行目
50
+ assert.strictEqual(err.file, 'main.nako3')
51
+ return true
52
+ }
53
+ )
54
+ })
55
+ it('『プラグイン名』のテスト。(#956)', () => {
56
+ const fname = __dirname + path.sep + 'requiretest_name.nako3'
57
+ cmp('!「' + fname + '」を取り込む。リクエスト名前取得して表示。', fname)
58
+ })
59
+ })
@@ -0,0 +1,4 @@
1
+ 痕跡とは変数は5
2
+ ●(AとBを)痕跡演算とは
3
+   A+Bで戻る
4
+ ここまで
@@ -0,0 +1 @@
1
+ !「./requiretest.nako3」を取り込む
@@ -0,0 +1,5 @@
1
+ PLUG=プラグイン名
2
+
3
+ ●リクエスト名前取得とは
4
+   PLUGを戻す。
5
+ ここまで。
@@ -0,0 +1,2 @@
1
+
2
+ 1のエラー発生