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
Binary file
Binary file
@@ -0,0 +1,70 @@
1
+ // @ts-nocheck
2
+ // nadesiko for web browser worker
3
+ // wwnako3.js
4
+ require('whatwg-fetch')
5
+
6
+ const NakoCompiler = require('./nako3')
7
+ const PluginBrowserInWorker = require('./plugin_browser_in_worker')
8
+ const PluginWorker = require('./plugin_worker')
9
+
10
+ class WebWorkerNakoCompiler extends NakoCompiler {
11
+ constructor () {
12
+ super()
13
+ this.__varslist[0]['ナデシコ種類'] = 'wwnako3'
14
+ this.__varslist[0]['PluginWorker:ondata'] = (data, event) => {
15
+ throw new Error('『NAKOワーカーデータ受信時』が呼ばれていません。')
16
+ }
17
+ }
18
+ }
19
+
20
+ // ブラウザワーカーなら navigator.nako3 になでしこを登録
21
+ // eslint-disable-next-line no-undef
22
+ if (typeof (navigator) === 'object' && self && self instanceof WorkerGlobalScope) {
23
+ /** @type {WebWorkerNakoCompiler} */
24
+ const nako3Compiler = navigator.nako3 = new WebWorkerNakoCompiler()
25
+ /** @type {WebWorkerNakoCompiler | import('./nako_global')} */
26
+ let nako3Global = nako3Compiler
27
+
28
+ nako3Compiler.addPluginObject('PluginBrowserInWorker', PluginBrowserInWorker)
29
+ nako3Compiler.addPluginObject('PluginWorker', PluginWorker)
30
+
31
+ nako3Compiler.logger.addListener('error', function (obj) {
32
+ self.postMessage({
33
+ type: 'error',
34
+ data: obj
35
+ })
36
+ }, false)
37
+
38
+ self.onmessage = (event) => {
39
+ const data = event.data || { type: '', data: '' }
40
+ const type = data.type || ''
41
+ const value = data.data || ''
42
+ switch (type) {
43
+ case 'reset':
44
+ nako3Compiler.reset()
45
+ break
46
+ case 'close':
47
+ self.close()
48
+ break
49
+ case 'run':
50
+ nako3Global = nako3Global.runEx(value, '_webworker.nako3', { resetEnv: false, resetLog: false })
51
+ break
52
+ case 'trans':
53
+ value.forEach(o => {
54
+ if (o.type === 'func') {
55
+ nako3Compiler.nako_func[o.name] = o.content.meta
56
+ nako3Compiler.funclist[o.name] = o.content.func
57
+ nako3Compiler.__varslist[1][o.name] = () => {}
58
+ } else if (o.type === 'val') {
59
+ nako3Compiler.__varslist[2][o.name] = o.content
60
+ }
61
+ })
62
+ break
63
+ case 'data':
64
+ if (nako3Global.__varslist[0]['PluginWorker:ondata']) {
65
+ nako3Global.__varslist[0]['PluginWorker:ondata'].apply(nako3Global, [value, event])
66
+ }
67
+ break
68
+ }
69
+ }
70
+ }
@@ -0,0 +1,94 @@
1
+ // @ts-nocheck
2
+ const path = require('path')
3
+
4
+ module.exports = function (config) {
5
+ config.set({
6
+ frameworks: ['mocha', 'webpack'],
7
+ files: [
8
+ 'test/*_test.js',
9
+ {
10
+ pattern: '../../release/*.js',
11
+ included: false,
12
+ served: true,
13
+ watched: false,
14
+ nocache: true
15
+ },
16
+ {
17
+ pattern: '../../src/*.css',
18
+ included: false,
19
+ served: true,
20
+ watched: false,
21
+ nocache: true
22
+ },
23
+ {
24
+ pattern: '../node/*.nako3',
25
+ included: false,
26
+ served: true,
27
+ watched: false,
28
+ nocache: true
29
+ }
30
+ ],
31
+ customContextFile: 'test/html/custom_context.html',
32
+ proxies: {
33
+ '/src/': '/absolute' + path.resolve('./src') + '/',
34
+ '/release/': '/absolute' + path.resolve('./release') + '/',
35
+ '/test/': '/absolute' + path.resolve('./test/node') + '/'
36
+ },
37
+ plugins: [
38
+ 'karma-firefox-launcher',
39
+ 'karma-mocha',
40
+ 'karma-mocha-reporter',
41
+ 'karma-webpack'
42
+ ],
43
+ customLaunchers: {
44
+ FirefoxCustom: {
45
+ base: 'Firefox',
46
+ prefs: {
47
+ 'dom.w3c_touch_events.enabled': 1,
48
+ 'dom.w3c_touch_events.legacy_apis.enabled': true
49
+ },
50
+ flags: ['-width', 400, '-height', 400]
51
+ },
52
+ FirefoxCustomHeadless: {
53
+ base: 'FirefoxHeadless',
54
+ prefs: {
55
+ 'dom.w3c_touch_events.enabled': 1,
56
+ 'dom.w3c_touch_events.legacy_apis.enabled': true
57
+ },
58
+ flags: ['-width', 400, '-height', 400]
59
+ }
60
+ },
61
+ preprocessors: {
62
+ 'test/*_test.js': ['webpack']
63
+ },
64
+ // webpackの設定
65
+ webpack: {
66
+ mode: 'development',
67
+ target: ['web', 'es5'],
68
+ resolve: {
69
+ mainFields: ['browser', 'main', 'module']
70
+ },
71
+ module: {
72
+ rules: [
73
+ {
74
+ test: /\.js$/,
75
+ exclude: /(node_modules|bower_components)/,
76
+ use: { loader: 'babel-loader' }
77
+ }
78
+ ]
79
+ }
80
+ },
81
+ reporters: ['mocha'],
82
+ // reporter options
83
+ mochaReporter: {
84
+ showDiff: true
85
+ },
86
+ port: 9876, // karma web server port
87
+ colors: true,
88
+ logLevel: config.LOG_INFO,
89
+ browsers: ['Firefox', 'FirefoxHeadless', 'FirefoxCustom', 'FirefoxCustomHeadless'],
90
+ autoWatch: false,
91
+ // singleRun: false, // Karma captures browsers, runs the tests and exits
92
+ concurrency: Infinity
93
+ })
94
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "sourceType": "module"
3
+ }
@@ -0,0 +1,178 @@
1
+ // @ts-nocheck
2
+ const assert = require('chai').assert
3
+
4
+ /** @type {(node: HTMLElement, f: (node: HTMLElement) => boolean) => HTMLElement | null} */
5
+ const findDOMElement = (node, f) => {
6
+ if (f(node)) { return node }
7
+ for (const child of node.children) {
8
+ const v = findDOMElement(child, f)
9
+ if (v) {
10
+ return v
11
+ }
12
+ }
13
+ return null
14
+ }
15
+
16
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
17
+
18
+ describe('ace editor test', () => {
19
+ before(function (done) {
20
+ this.timeout(100000)
21
+ // シンタックスハイライトが終わるまで少し時間がかかる。
22
+ const wait = () => {
23
+ if (window.ok) {
24
+ done()
25
+ return
26
+ }
27
+ setTimeout(() => { wait() }, 100)
28
+ }
29
+ wait()
30
+ })
31
+ describe('シンタックスハイライト', () => {
32
+ it('制御構文', () => {
33
+ // #editor1内の「もし」が .ace_keyword.ace_control でシンタックスハイライトされていることを確認する。
34
+ // innerTextが「も」で始まり、ace_keywordとace_controlクラスが付いているタグが存在すれば良い。
35
+ assert.notStrictEqual(
36
+ findDOMElement(
37
+ document.querySelector('#editor1'),
38
+ (node) =>
39
+ node.classList.contains('ace_keyword') &&
40
+ node.classList.contains('ace_control') &&
41
+ node.innerText.trim().startsWith('も')
42
+ ),
43
+ null
44
+ )
45
+ })
46
+ it('関数', () => {
47
+ // #editor1内の「表示」が関数として認識されていることを確認する。
48
+ assert.notStrictEqual(
49
+ findDOMElement(
50
+ document.querySelector('#editor1'),
51
+ (node) =>
52
+ node.classList.contains('ace_function') &&
53
+ node.innerText.trim().startsWith('表')
54
+ ),
55
+ null
56
+ )
57
+ })
58
+ it('範囲コメント', () => {
59
+ // #editor2内の「範囲コメント」がコメントとして認識されていることを確認する。
60
+ assert.notStrictEqual(
61
+ findDOMElement(
62
+ document.querySelector('#editor2'),
63
+ (node) =>
64
+ node.classList.contains('ace_comment') &&
65
+ node.innerText.trim().startsWith('範')
66
+ ),
67
+ null
68
+ )
69
+ })
70
+ it('エディタの値を変更したときにシンタックスハイライトが更新されることを確認', async function () {
71
+ this.timeout(5 * 1000) // このテストはタイムアウトのときのみエラーになる。
72
+
73
+ const { editor } = navigator.nako3.setupEditor('editor-input-test')
74
+
75
+ // "「」を表示" を打って、"「" が文字列として認識されることを確認
76
+ editor.setValue('「」を表示')
77
+ editor.session.selection.clearSelection()
78
+ while (findDOMElement(document.querySelector('#editor-input-test'), (node) => node.classList.contains('ace_string') && node.innerText.trim().startsWith('「')) === null) {
79
+ await sleep(100)
80
+ }
81
+
82
+ // "1を表示" を打って、1が数値として認識されることを確認
83
+ editor.setValue('1を表示'); await sleep(350)
84
+ editor.session.selection.clearSelection()
85
+ while (findDOMElement(document.querySelector('#editor-input-test'), (node) => node.classList.contains('ace_numeric') && node.innerText.trim().startsWith('1')) === null) {
86
+ await sleep(100)
87
+ }
88
+ })
89
+ it('外部ファイルで定義された関数', () => {
90
+ // 「痕跡演算」が関数として認識されることを確認
91
+ assert.notStrictEqual(
92
+ findDOMElement(
93
+ document.querySelector('#editor8'),
94
+ (node) =>
95
+ node.classList.contains('ace_function') &&
96
+ node.innerText.trim().startsWith('痕')
97
+ ),
98
+ null
99
+ )
100
+ })
101
+ })
102
+ describe('行の折りたたみ', () => {
103
+ it('存在する場合', () => {
104
+ // #editor2に折りたたみ用のボタンが生成されていることを確認する。
105
+ // 折りたたみ用のボタンのHTMLタグには .ace_fold-widget クラスが付いている。
106
+ assert.notStrictEqual(document.querySelector('#editor2 .ace_fold-widget'), null)
107
+ })
108
+ it('存在しない場合', () => {
109
+ // #editor3に折りたたみ用のボタンが生成されていないことを確認する。
110
+ assert.strictEqual(document.querySelector('#editor3 .ace_fold-widget'), null)
111
+ })
112
+ })
113
+ describe('コンパイルエラーの表示', () => {
114
+ it('存在する場合', () => {
115
+ // #editor4, 7 に赤線が引かれていることを確認する。
116
+ assert.notStrictEqual(document.querySelector('#editor4 .marker-red'), null)
117
+ assert.notStrictEqual(document.querySelector('#editor7 .marker-red'), null)
118
+ })
119
+ it('存在しない場合', () => {
120
+ // #editor1, 2, 3 に赤線が引かれていないことを確認する。
121
+ assert.strictEqual(document.querySelector('#editor1 .marker-red'), null)
122
+ assert.strictEqual(document.querySelector('#editor2 .marker-red'), null)
123
+ assert.strictEqual(document.querySelector('#editor3 .marker-red'), null)
124
+ })
125
+ it('setTimeout内から飛ぶエラーの表示', async function () {
126
+ this.timeout(5 * 1000)
127
+ while (document.querySelector('#editor10 .marker-red') === null) {
128
+ await sleep(100)
129
+ }
130
+ })
131
+ })
132
+ describe('コンパイラの警告の表示', () => {
133
+ it('存在する場合', () => {
134
+ assert.notStrictEqual(document.querySelector('#editor9 .marker-yellow'), null)
135
+ })
136
+ })
137
+ describe('出力のボックス', () => {
138
+ it('コンパイルエラーを表示する', () => {
139
+ assert.strictEqual(document.querySelector('#editor7-output').innerText.trim(), '[実行時エラー]main.nako3(2行目): エラー『1』が発生しました。')
140
+ assert.strictEqual(document.querySelector('#editor8-output').innerText.trim(), '')
141
+ // assert.strictEqual(document.querySelector('#editor9-output').innerText.trim(), '[警告]main.nako3(1行目): 変数『a』は定義されていません。\nundefined')
142
+ assert.strictEqual(document.querySelector('#editor9-output').innerText.trim(), '[警告]main.nako3(1行目): 変数『a』は定義されていません。\n[警告]main.nako3(1行目): 命令『表示』の引数にundefinedを渡しています。\nundefined')
143
+ assert.strictEqual(document.querySelector('#editor11-output').innerText.trim(), '[字句解析エラー]main.nako3(1行目): 展開あり文字列で値の埋め込み{...}が対応していません。')
144
+ })
145
+ it('プログラムの出力を表示する', () => {
146
+ assert.strictEqual(document.querySelector('#editor1-output').innerText.trim(), 'こんにちは')
147
+ })
148
+ })
149
+ describe('code lens', () => {
150
+ it('テストの定義の上に実行ボタンが表示される', () => {
151
+ assert.strictEqual(document.querySelectorAll('#editor12 .ace_codeLens').length, 2)
152
+ })
153
+ it('テストボタンをクリックするとcallbackが呼ばれる', () => {
154
+ assert.strictEqual(window.codeLensClicked, undefined)
155
+ // 1つ目のテスト定義のボタンを押して、「テスト:足す」のボタンが押されたことがcallbackで伝えられることを確認
156
+ document.querySelector('#editor12 .ace_codeLens a').dispatchEvent(new window.CustomEvent('click', { bubbles: true }))
157
+ assert.strictEqual(window.codeLensClicked, '足す')
158
+ })
159
+ })
160
+ describe('テストの実行', () => {
161
+ it('落ちる場合', async () => {
162
+ // 「足す」のテストが落ちることを確認する
163
+ const { promise, logger } = window.editor12.run({ method: 'test', testName: '足す' })
164
+ let log = ''
165
+ logger.addListener('stdout', ({ noColor }) => { log += noColor })
166
+ await promise
167
+ assert(log.includes('失敗 1件'))
168
+ })
169
+ it('通る場合', async () => {
170
+ // 「引く」のテストが通ることを確認する
171
+ const { promise, logger } = window.editor12.run({ method: 'test', testName: '引く' })
172
+ let log = ''
173
+ logger.addListener('stdout', ({ noColor }) => { log += noColor })
174
+ await promise
175
+ assert(log.includes('成功 1件'))
176
+ })
177
+ })
178
+ })
@@ -0,0 +1,140 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Nadesiko3 Editor</title>
8
+ <link rel="stylesheet" href="/src/wnako3_editor.css">
9
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js" integrity="sha512-GZ1RIgZaSc8rnco/8CXfRdCpDxRCphenIiZ2ztLy3XQfCbQUSCuk8IudvNHxkRA3oUg6q0qejgN/qqyG1duv5Q==" crossorigin="anonymous"></script>
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ext-language_tools.min.js" integrity="sha512-8qx1DL/2Wsrrij2TWX5UzvEaYOFVndR7BogdpOyF4ocMfnfkw28qt8ULkXD9Tef0bLvh3TpnSAljDC7uyniEuQ==" crossorigin="anonymous"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ext-options.min.js" integrity="sha512-oHR+WVzBiVZ6njlMVlDDLUIOLRDfUUfRQ55PfkZvgjwuvGqL4ohCTxaahJIxTmtya4jgyk0zmOxDMuLzbfqQDA==" crossorigin="anonymous"></script>
12
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ext-code_lens.min.js" integrity="sha512-gsDyyKTnOmSWRDzUbpYcPjzVsEyFGSWeWefzVKvbMULPR2ElIlKKsOtU3ycfybN9kncZXKLFSsUiG3cgJUbc/g==" crossorigin="anonymous"></script>
13
+ <script src="/release/wnako3.js"></script>
14
+ <script src="/release/version.js"></script>
15
+ <script src="/release/plugin_markup.js"></script>
16
+ <script src="/release/plugin_csv.js"></script>
17
+ <script src="/release/plugin_kansuji.js"></script>
18
+ <script src="/release/plugin_datetime.js"></script>
19
+ <script src="/release/plugin_turtle.js"></script>
20
+ <script src="/release/plugin_caniuse.js"></script>
21
+ <script src="/release/plugin_webworker.js"></script>
22
+
23
+ <!-- mochaを一番最後に読み込む必要がある -->
24
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/8.3.0/mocha.min.js" integrity="sha512-LA/TpBXau/JNubKzHQhdi5vGkRLyQjs1vpuk2W1nc8WNgf/pCqBplD8MzlzeKJQTZPvkEZi0HqBDfRC2EyLMXw==" crossorigin="anonymous"></script>
25
+ </head>
26
+ <body>
27
+ 単純な例
28
+ <div id="editor1" data-nako3-force-syntax-highlighting="true">もしはいならば
29
+ 「こんにちは」を表示
30
+ ここまで
31
+ </div>
32
+ <div id="editor1-output"></div>
33
+ インデント構文
34
+ <div id="editor2" data-nako3-force-syntax-highlighting="true">!インデント構文
35
+ Nを1から3まで繰り返す
36
+ Nを表示
37
+
38
+ 「1行目
39
+ 2行目」を表示
40
+
41
+ /*
42
+ 範囲コメント
43
+ */
44
+ </div>
45
+ 平らなプログラム
46
+ <div id="editor3" data-nako3-force-syntax-highlighting="true">
47
+ A=1
48
+ Aを表示
49
+ </div>
50
+ コンパイルエラーの表示
51
+ <div id="editor4" data-nako3-force-syntax-highlighting="true">
52
+ 「{」を表示
53
+ </div>
54
+ readonly
55
+ <div id="editor5" data-nako3-readonly="true" data-nako3-force-syntax-highlighting="true">1+2を表示</div>
56
+ コンパイルエラーの表示の無効化
57
+ <div id="editor6" data-nako3-disable-marker="true" data-nako3-force-syntax-highlighting="true">
58
+ 「{」を表示
59
+ </div>
60
+ 実行時エラーの表示
61
+ <div id="editor7" data-nako3-force-syntax-highlighting="true">「」を表示
62
+ 1のエラー発生
63
+ </div>
64
+ <div id="editor7-output"></div>
65
+ ソースコードの取り込み
66
+ <div id="editor8" data-nako3-force-syntax-highlighting="true">!「http://localhost:9876/test/requiretest.nako3」を取り込む
67
+ 1と2を痕跡演算する
68
+ </div>
69
+ <div id="editor8-output"></div>
70
+ 警告の表示
71
+ <div id="editor9" data-nako3-force-syntax-highlighting="true">aを表示</div>
72
+ <div id="editor9-output"></div>
73
+ setTimeoutで起きたエラーの表示
74
+ <div id="editor10" data-nako3-force-syntax-highlighting="true">0.01秒後には
75
+ 1のエラー発生
76
+ ここまで
77
+ </div>
78
+ 字句解析エラーの表示
79
+ <div id="editor11" data-nako3-force-syntax-highlighting="true">「{」
80
+ </div>
81
+ <div id="editor11-output"></div>
82
+ 文字入力のテスト用
83
+ <div id="editor-input-test"></div>
84
+ <div>
85
+ プログラムの実行
86
+ </div>
87
+ テストの定義にcode lensを表示する
88
+ <div id="editor12">●テスト:足すとは
89
+ 1のエラー発生
90
+ ここまで
91
+
92
+ ●テスト:引くとは
93
+ ここまで
94
+ </div>
95
+ <script>
96
+ const editor1 = navigator.nako3.setupEditor("editor1")
97
+ navigator.nako3.setupEditor("editor2")
98
+ navigator.nako3.setupEditor("editor3")
99
+ navigator.nako3.setupEditor("editor4")
100
+ navigator.nako3.setupEditor("editor5")
101
+ navigator.nako3.setupEditor("editor6")
102
+ const editor7 = navigator.nako3.setupEditor("editor7")
103
+ const editor8 = navigator.nako3.setupEditor("editor8")
104
+ const editor9 = navigator.nako3.setupEditor("editor9")
105
+ const editor10 = navigator.nako3.setupEditor("editor10")
106
+ const editor11 = navigator.nako3.setupEditor("editor11")
107
+ const editor12 = navigator.nako3.setupEditor("editor12")
108
+ window.editor12 = editor12
109
+ editor12.codeLensListeners.push({ name: 'test', callback: (testName) => { window.codeLensClicked = testName } })
110
+ // editor-input-test はテスト内で初期化する
111
+
112
+ // プログラムを実行する。順番に実行しないとloadDependenciesの間にloggerが別のエディタによって置き換えられてしまい、エラーを正しく表示できない。
113
+ const main = async () => {
114
+ await editor1.run({ outputContainer: document.getElementById("editor1-output") }).promise
115
+ await editor7.run({ preCode: 'A=1\n', outputContainer: document.getElementById("editor7-output") }).promise
116
+ await editor8.run({ outputContainer: document.getElementById("editor8-output")}).promise
117
+ await editor9.run({ outputContainer: document.getElementById("editor9-output")}).promise
118
+ await editor10.run({}).promise
119
+ await new Promise((resolve) => setTimeout(resolve, 500)) // editor10で実行時エラーが飛ぶまで待つ
120
+ await editor11.run({ outputContainer: document.getElementById("editor11-output")}).promise
121
+ window.ok = true
122
+ }
123
+ main().catch((err) => { console.error(err) })
124
+
125
+ </script>
126
+ <script src="context.js"></script>
127
+ <script type="text/javascript">
128
+ %CLIENT_CONFIG%
129
+ window.__karma__.setupContext(window);
130
+ %MAPPINGS%
131
+ </script>
132
+ %SCRIPTS%
133
+ <script type="module">
134
+ window.__karma__.loaded();
135
+ </script>
136
+ <script nomodule>
137
+ window.__karma__.loaded();
138
+ </script>
139
+ </body>
140
+ </html>
@@ -0,0 +1,124 @@
1
+ const assert = require('assert')
2
+ const NakoCompiler = require('../../src/nako3.js')
3
+ const NakoGenAsync = require('../../src/nako_gen_async.js')
4
+
5
+ describe('aysnc_basic_test', () => {
6
+ // @ts-ignore
7
+ const nako = new NakoCompiler()
8
+ nako.addCodeGenerator('非同期モード', NakoGenAsync)
9
+ const cmp = (/** @type {string} */code, /** @type {string} */res) => {
10
+ code = '!非同期モード\n' + code
11
+ nako.logger.debug('code=' + code)
12
+ assert.strictEqual(nako.run(code, '').log, res)
13
+ }
14
+ // --- test ---
15
+ it('print simple', () => {
16
+ cmp('3を表示', '3')
17
+ })
18
+ it('calc simple', () => {
19
+ cmp('3*2を表示', '6')
20
+ })
21
+ it('let simple', () => {
22
+ cmp('n=3;nを表示', '3')
23
+ cmp('n=3;m=8;n*mを表示', '24')
24
+ })
25
+ // 関数
26
+ it('js func simple c type', () => {
27
+ cmp('n=INT(3.14);nを表示', '3')
28
+ cmp('INT(3.14)を表示', '3')
29
+ })
30
+ it('js func replace', () => {
31
+ cmp('「a,b,c」の「,」を「:」へ置換。それを表示。', 'a:b:c')
32
+ })
33
+ it('js func replace 連文', () => {
34
+ cmp('「a,b,c」の「,」を「:」へ置換して表示。', 'a:b:c')
35
+ })
36
+ it('関数定義', () => {
37
+ cmp('●(AとBの)積算処理とは\nA*Bで戻る。。。3と5の積算処理を表示', '15')
38
+ cmp('●(AにBを)加算処理とは\nAにBを足す。。。3に5を加算処理して表示', '8')
39
+ })
40
+ it('無名関数定義', () => {
41
+ cmp('A=●(AとBの)\nA/Bで戻る。。。A(9,3)を表示', '3')
42
+ })
43
+ it('関数定義(再帰)', () => {
44
+ cmp('総数=0;●(Nの)再帰加算処理とは\nもしN<0ならば総数を戻す;総数=総数+N;(N-1)の再帰加算処理を戻す。。。10の再帰加算処理を表示', '55')
45
+ })
46
+ it('フィボナッチテスト(関数の再帰)', () => {
47
+ cmp(
48
+ '●FIB(N)とは\n' +
49
+ '  もしN<=2ならば、(N-1)で戻る\n' +
50
+ '  それ=FIB(N-1)+FIB(N-2)\n' +
51
+ 'ここまで。\n' +
52
+ 'FIB(15)を表示', '377')
53
+ })
54
+ // 条件分岐
55
+ it('もし', () => {
56
+ cmp('N=1;もしN=1ならば「OK」と表示。', 'OK')
57
+ cmp('N=2;もしN=1ならば「NG」と表示。違えば「OK」と表示', 'OK')
58
+ cmp('N=10;もしN>=5ならば「A」と表示。違えば「B」と表示', 'A')
59
+ cmp('N=1;もしN>=5ならば「A」と表示。違えば「B」と表示', 'B')
60
+ })
61
+ it('もし、複数行', () => {
62
+ cmp('N=1;もし、Nが3以上ならば\n"A"を表示\n違えば\n"B"を表示\n。。。', 'B')
63
+ })
64
+ it('もし、連続', () => {
65
+ cmp('N=1;もしN=1ならば「OK」と表示。', 'OK')
66
+ cmp('N=2;もしN=1ならば「1」と表示。違えばもしN=2ならば「2」と表示。違えばもしN=3ならば「3」と表示。違えば「その他」と表示。', '2')
67
+ cmp('N=4;もしN=1ならば「1」と表示。違えばもしN=2ならば「2」と表示。違えばもしN=3ならば「3」と表示。違えば「その他」と表示。', 'その他')
68
+ })
69
+ it('条件分岐', () => {
70
+ cmp('N=3;Nで条件分岐;1ならば"1"と表示💧2ならば"2"と表示💧3ならば"3"と表示💧違えば"*"と表示💧💧', '3')
71
+ cmp('N=55;Nで条件分岐;1ならば"1"と表示💧2ならば"2"と表示💧3ならば"3"と表示💧違えば"*"と表示💧💧', '*')
72
+ })
73
+ // JSON
74
+ it('JSON', () => {
75
+ cmp('N=[10,20,30];N[0]を表示', '10')
76
+ cmp('N={"mon":1,"tue":2,"wed":3};N["wed"]を表示', '3')
77
+ cmp('N={"mon":[1,2,3],"tue":[4,5,6]};N["mon"][2]を表示', '3')
78
+ })
79
+ // 繰り返し
80
+ it('繰り返し', () => {
81
+ cmp('C=0;Nを1から10まで繰り返す;C=C+N;ここまで;Cを表示;', '55')
82
+ cmp('C=0;10回,C=C+回数;Cを表示', '55')
83
+ cmp('C=0;N=10;Nが0以上の間;C=C+N;N=N-1;ここまで;Cを表示', '55')
84
+ cmp('C=0;N=[1,2,3,4,5,6,7,8,9,10];Nを反復;C=C+対象;ここまで;Cを表示', '55')
85
+ })
86
+ // 文字列の展開
87
+ it('文字列の展開', () => {
88
+ cmp('a=30;「abc{a}abc」を表示', 'abc30abc')
89
+ cmp('a=30;「abc{a}abc」を表示', 'abc30abc')
90
+ })
91
+ // 定数
92
+ it('システム定数', () => {
93
+ cmp('ナデシコエンジンを表示', 'nadesi.com/v3')
94
+ })
95
+ it('助詞の後に句読点', () => {
96
+ cmp('「こんにちは」と、表示。', 'こんにちは')
97
+ })
98
+ it('代入文', () => {
99
+ cmp('3000を値段に代入。値段を表示', '3000')
100
+ cmp('値段に3000を代入。値段を表示', '3000')
101
+ cmp('々=3000。々を表示', '3000')
102
+ cmp('々に3000を代入。々を表示', '3000')
103
+ })
104
+ it('連文後の代入文', () => {
105
+ cmp('「aabbcc」の「aa」を「」に置換してFに代入。Fを表示', 'bbcc')
106
+ cmp('「aabbcc」の「aa」を「」に置換して「bb」を「」に置換してFに代入。Fを表示', 'cc')
107
+ })
108
+ it('〜を〜に定める', () => {
109
+ cmp('Aを0.8に定めてAを表示', '0.8')
110
+ })
111
+ it('文字列 - &と改行', () => {
112
+ cmp('「aaa」& _\n「bbb」を表示。', 'aaabbb')
113
+ cmp('A= 1 + 1 + 1 + 1 + 1 + _\n1 + 1\nAを表示', '7')
114
+ cmp('A= 1 + 1 + 1 + 1 + 1 + _\r\n1 + 1 + 1\r\nAを表示', '8')
115
+ cmp('A= 1 + 1 + 1 + 1 + 1 + _ \r\n1 + 3 \r\nAを表示', '9')
116
+ cmp('A = 1 + _\n' +
117
+ ' 5 + _\n' +
118
+ ' 10\n' +
119
+ 'Aを表示。', '16')
120
+ })
121
+ it('名前に数字を持つ変数を使う', () => {
122
+ cmp('A1=30;B1=20;「{A1}{B1}」を表示。', '3020')
123
+ })
124
+ })