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,105 @@
1
+ const NakoCompiler = require('../../src/nako3')
2
+ const assert = require('assert')
3
+
4
+ describe('variable_scope_test', () => {
5
+ const nako = new NakoCompiler()
6
+ const cmp = (code, res) => {
7
+ assert.strictEqual(nako.run(code).log, res)
8
+ }
9
+
10
+ it('関数内からグローバル変数へ代入', () => {
11
+ cmp(`
12
+ Aとは変数
13
+ ●Fとは
14
+ A=1
15
+ ここまで
16
+ F
17
+ Aを表示
18
+ `, `1`)
19
+ })
20
+ it('関数内からグローバル変数を参照', () => {
21
+ cmp(`
22
+ Aとは変数
23
+ ●Fとは
24
+ Aを表示
25
+ ここまで
26
+ A=1
27
+ F
28
+ `, `1`)
29
+ })
30
+ it('変数のshadowing', () => {
31
+ cmp(`
32
+ Aとは変数
33
+ A=2
34
+ ●Fとは
35
+ Aとは変数
36
+ A=1
37
+ Aを表示
38
+ ここまで
39
+ F
40
+ Aを表示
41
+ `, `1\n2`)
42
+ })
43
+ it('ネストした関数定義', () => {
44
+ // 関数内の関数定義は、関数外で定義されている場合と同じ扱いとする。
45
+ cmp(`
46
+ Aとは変数
47
+ A=3
48
+ ●Fとは
49
+ Aとは変数
50
+ ●Gとは
51
+ A=1
52
+ ここまで
53
+ ここまで
54
+ G
55
+ Aを表示
56
+ `, '1')
57
+ })
58
+ it('JavaScriptで使えない変数名の使用 - グローバル変数の場合', () => {
59
+ cmp(`
60
+ if=10
61
+ ifを表示
62
+ `, '10')
63
+ })
64
+ it('JavaScriptで使えない変数名の使用 - ローカル変数の場合', () => {
65
+ cmp(`
66
+ ●function
67
+ var=10
68
+ varを表示
69
+ ここまで
70
+ function
71
+ `, '10')
72
+ })
73
+ it('JavaScriptで使えない変数名の使用 - 関数からグローバル変数を参照する場合', () => {
74
+ cmp(`
75
+ var=10
76
+ ●function
77
+ varを表示
78
+ ここまで
79
+ function
80
+ `, '10')
81
+ })
82
+ it('JavaScriptで使えない変数名の使用 - 変数のshadowing', () => {
83
+ cmp(`
84
+ var=10
85
+ ●function
86
+ varsとは変数
87
+ vars=1
88
+ ここまで
89
+ function
90
+ varを表示
91
+ `, '10')
92
+ })
93
+ it('関数内から「ナデシコする」を呼ぶ', () => {
94
+ cmp(`\
95
+ A=1
96
+ ●Fとは
97
+ B=2
98
+ 「A=3;B=4」をナデシコする
99
+ Aを表示
100
+ Bを表示
101
+ ここまで
102
+ F
103
+ `, '3\n4')
104
+ })
105
+ })
@@ -0,0 +1,19 @@
1
+ {
2
+ "extends": "../jsconfig.json",
3
+ "compilerOptions": {
4
+ "paths": {
5
+ "assert/*": [
6
+ "../utils/assert.js/*"
7
+ ],
8
+ "root/*": [
9
+ "../*"
10
+ ],
11
+ "nako3/*": [
12
+ "../src/*"
13
+ ],
14
+ "utils/*" : [
15
+ "../utils/*"
16
+ ]
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,91 @@
1
+ const path = require('path')
2
+
3
+ module.exports = function(config) {
4
+ config.set({
5
+ basePath: '',
6
+ frameworks: ['mocha','webpack'],
7
+ files: [
8
+ 'common/*.js'
9
+ ],
10
+ plugins: [
11
+ 'karma-firefox-launcher',
12
+ 'karma-mocha',
13
+ 'karma-mocha-reporter',
14
+ 'karma-webpack'
15
+ ],
16
+ customLaunchers: {
17
+ FirefoxCustom: {
18
+ base: 'Firefox',
19
+ prefs: {
20
+ 'dom.w3c_touch_events.enabled': 1,
21
+ 'dom.w3c_touch_events.legacy_apis.enabled': true
22
+ },
23
+ flags: [ '-width', 400, '-height', 400 ]
24
+ },
25
+ FirefoxCustomHeadless: {
26
+ base: 'FirefoxHeadless',
27
+ prefs: {
28
+ 'dom.w3c_touch_events.enabled': 1,
29
+ 'dom.w3c_touch_events.legacy_apis.enabled': true
30
+ },
31
+ flags: [ '-width', 400, '-height', 400 ]
32
+ }
33
+ },
34
+ preprocessors: {
35
+ 'common/*.js': ['webpack']
36
+ },
37
+ // webpackの設定
38
+ webpack: {
39
+ mode: "development",
40
+ target: ["web", "es5"],
41
+ module: {
42
+ rules: [
43
+ {
44
+ test: /\.js$/,
45
+ exclude: /(node_modules|bower_components)/,
46
+ use: { loader: 'babel-loader' }
47
+ }
48
+ ]
49
+ },
50
+ resolve: {
51
+ mainFields: ["browser", "main", "module"],
52
+ alias: {
53
+ "assert": path.resolve(__dirname, '../utils/assert.js'),
54
+ "root": path.join(__dirname, ".."),
55
+ "nako3": path.join(__dirname, '../src'),
56
+ "utils" : path.join(__dirname, '../utils')
57
+ }
58
+ }
59
+ },
60
+ reporters: ['mocha'],
61
+ // reporter options
62
+ mochaReporter: {
63
+ showDiff: true,
64
+ },
65
+ coverageReporter: {
66
+ dir: '../coverage/common',
67
+ subdir: function(browser) {
68
+ return browser.toLowerCase().split(/[ /-]/)[0];
69
+ },
70
+ reporters: [
71
+ { type: 'text' },
72
+ { type: 'text-summary' },
73
+ { type: 'lcov' },
74
+ { type: 'text', file: 'text.txt' },
75
+ { type: 'json', file: 'text.json' },
76
+ { type: 'text-summary', file: 'text-summary.txt' },
77
+ { type: 'lcovonly', file: 'report-lcovonly.txt' },
78
+ ],
79
+ instrumenterOptions: {
80
+ istanbul: { noCompact: true }
81
+ }
82
+ },
83
+ port: 9876, // karma web server port
84
+ colors: true,
85
+ logLevel: config.LOG_INFO,
86
+ browsers: ['Firefox', 'FirefoxHeadless', 'FirefoxCustom', 'FirefoxCustomHeadless' ],
87
+ autoWatch: false,
88
+ // singleRun: false, // Karma captures browsers, runs the tests and exits
89
+ concurrency: Infinity
90
+ })
91
+ }
@@ -0,0 +1 @@
1
+ 1+2を表示
@@ -0,0 +1,80 @@
1
+ const assert = require('assert')
2
+ const Nako3Assert = require('../../src/nako3_assert.js')
3
+
4
+ describe('async_test', () => {
5
+ const debug = false
6
+ const nako3 = new Nako3Assert()
7
+ nako3.debug = debug
8
+ const cmp = (code, exRes) => {
9
+ const result = nako3.run(code).log
10
+ assert.strictEqual(result, exRes)
11
+ }
12
+ const exe = (code) => {
13
+ nako3.run(code)
14
+ }
15
+
16
+ // assert test
17
+ it('アサート自体のテスト', () => {
18
+ exe('3と3でテスト。')
19
+ cmp('3を表示', '3')
20
+ })
21
+
22
+ // --- async ---
23
+ it('async_simple', (done) => {
24
+ global.done = done
25
+ exe(
26
+ '逐次実行\n' +
27
+ '先に、1と表示\n' +
28
+ '次に、2と表示\n' +
29
+ '次に、表示ログと「1\n2\n」でテスト。\n' +
30
+ '次に、「global.done()」をJS実行。' +
31
+ 'ここまで。\n'
32
+ )
33
+ })
34
+ it('async_multiple', (done) => {
35
+ global.done = done
36
+ exe(
37
+ '逐次実行\n' +
38
+ '先に\n' +
39
+ ' 1と表示\n' +
40
+ ' 2と表示\n' +
41
+ 'ここまで\n' +
42
+ '次に、3と表示\n' +
43
+ '次に、表示ログと「1\n2\n3\n」でテスト。\n' +
44
+ '次に、「global.done()」をJS実行。' +
45
+ 'ここまで。\n'
46
+ )
47
+ })
48
+ it('戻り値を使う', (done) => {
49
+ global.done = done
50
+ exe(
51
+ '逐次実行\n' +
52
+ '先に、それは30\n' +
53
+ '次に、それを表示\n' +
54
+ '次に、表示ログと「30\n」でテスト。\n' +
55
+ '次に、「global.done()」をJS実行。' +
56
+ 'ここまで。\n'
57
+ )
58
+ })
59
+ it('同期タイマー', (done) => {
60
+ global.done = done
61
+ exe(
62
+ '逐次実行\n' +
63
+ '先に、0.01秒待機\n' +
64
+ '次に、30を表示\n' +
65
+ '次に、表示ログと「30\n」でテスト。\n' +
66
+ '次に、「global.done()」をJS実行。\n' +
67
+ 'ここまで。\n'
68
+ )
69
+ })
70
+ it('連文 #373', (done) => {
71
+ global.done = done
72
+ exe(
73
+ '逐次実行\n' +
74
+ '先に、30に5を足して表示\n' +
75
+ '次に、表示ログと「35\n」でテスト。\n' +
76
+ '次に、「global.done()」をJS実行。\n' +
77
+ 'ここまで。\n'
78
+ )
79
+ })
80
+ })
@@ -0,0 +1,82 @@
1
+ const assert = require('assert')
2
+
3
+ describe('commnder_ja', () => {
4
+ it('version', () => {
5
+ const app = require('../../src/commander_ja.js')
6
+ const c1 = app
7
+ .version('1.1.1', '-v,--version')
8
+ .option('-a,--aaa')
9
+ .parseStr(['node.js', 'cnako3.js', '-v'])
10
+ assert.strictEqual(c1, '1.1.1')
11
+ const c2 = app
12
+ .version('1.2.3', '-v,--version')
13
+ .option('-a,--aaa')
14
+ .parseStr(['node.js', 'cnako3.js', '--version'])
15
+ assert.strictEqual(c2, '1.2.3')
16
+ })
17
+ it('help', () => {
18
+ const app = require('../../src/commander_ja.js')
19
+ app.version('1.2.3', '-v,--version')
20
+ .usage('[opt] test')
21
+ .option('-a,--aaa')
22
+ const help = app.getHelp()
23
+ const c1 = app.parseStr(['node.js', 'cnako3.js', '-h'])
24
+ assert.strictEqual(c1, help)
25
+ })
26
+ it('args no params', () => {
27
+ const app = require('../../src/commander_ja.js')
28
+ app.version('1.2.3', '-v,--version')
29
+ .title('hoge')
30
+ .usage('[opt] test')
31
+ .option('-a,--aaa')
32
+ app.parseStr(['node.js', 'cnako3.js', 'aaa', 'bbb'])
33
+ assert.strictEqual(app.args[0], 'aaa')
34
+ assert.strictEqual(app.args[1], 'bbb')
35
+ })
36
+ it('args has params1', () => {
37
+ const app = require('../../src/commander_ja.js')
38
+ app.version('1.2.3', '-v,--version')
39
+ .title('hoge')
40
+ .usage('[opt] test')
41
+ .option('-a,--aaa')
42
+ app.parseStr(['node.js', 'cnako3.js', '-a'])
43
+ assert.strictEqual(app.aaa, true)
44
+ })
45
+ it('args has params2', () => {
46
+ const app = require('../../src/commander_ja.js')
47
+ app.version('1.2.3', '-v,--version')
48
+ .title('hoge')
49
+ .usage('[opt] test')
50
+ .option('-a, --aaa')
51
+ app.parseStr(['node.js', 'cnako3.js', '-a', 'bbb'])
52
+ assert.strictEqual(app.aaa, true)
53
+ assert.strictEqual(app.args[0], 'bbb')
54
+ })
55
+ it('args has params3', () => {
56
+ const app = require('../../src/commander_ja.js')
57
+ app.version('1.2.3', '-v,--version')
58
+ .title('hoge')
59
+ .usage('[opt] test')
60
+ .option('-e, --eval [source]', 'eval source')
61
+ app.parseStr(['node.js', 'cnako3.js', '-e', 'hoge'])
62
+ assert.strictEqual(app.eval, 'hoge')
63
+ })
64
+ it('args has params4', () => {
65
+ const app = require('../../src/commander_ja.js')
66
+ app.version('1.2.3', '-v,--version')
67
+ .usage('[opt] test')
68
+ .option('-e, --eval [source]', 'eval source')
69
+ app.parseStr(['node.js', 'cnako3.js', '-e'])
70
+ assert.strictEqual(app.eval, '')
71
+ })
72
+ it('args has params5', () => {
73
+ const app = require('../../src/commander_ja.js')
74
+ app.version('1.2.3', '-v,--version')
75
+ .usage('[opt] test')
76
+ .option('-e, --eval [source]', 'eval source')
77
+ .option('-E, --Eval [source]', 'Eval source')
78
+ app.parseStr(['node.js', 'cnako3.js', '-E', '-e', '-d', 'hoge', 'fuga'])
79
+ assert.strictEqual(app.eval, 'hoge')
80
+ assert.strictEqual(app.Eval, 'fuga')
81
+ })
82
+ })
@@ -0,0 +1,244 @@
1
+ const assert = require('assert')
2
+ const path = require('path')
3
+ const CNako3 = require('../../src/cnako3')
4
+ const NakoCompiler = require('../../src/nako3')
5
+ const { NakoSyntaxError, NakoRuntimeError, NakoIndentError, NakoLexerError } = require('../../src/nako_errors')
6
+
7
+ describe('error_message', () => {
8
+ const nako = new NakoCompiler()
9
+ // nako.logger.addListener('trace', ({ browserConsole }) => { console.log(...browserConsole) })
10
+ /**
11
+ * エラーメッセージがresArrの全ての要素を含むことを確認する。
12
+ */
13
+ const cmp = (code, resArr, ErrorClass, _nako = nako) => {
14
+ _nako.logger.debug('code=' + code)
15
+ assert.throws(
16
+ () => _nako.run(code, path.join(__dirname, 'main.nako3')),
17
+ err => {
18
+ assert(err instanceof ErrorClass)
19
+ for (const res of resArr) {
20
+ if (!err.message.includes(res)) {
21
+ throw new Error(`${JSON.stringify(err.message)} が ${JSON.stringify(res)} を含みません。`)
22
+ }
23
+ }
24
+ return true
25
+ }
26
+ )
27
+ }
28
+
29
+ describe('字句解析エラー', () => {
30
+ it('エラー位置の取得', () => {
31
+ cmp(`\n「こんに{ちは」と表示する`, [
32
+ '2行目',
33
+ 'main.nako3',
34
+ ], NakoLexerError)
35
+ })
36
+ })
37
+
38
+ describe('構文エラー', () => {
39
+ it('比較', () => {
40
+ cmp('「こんにち」はを表示', [
41
+ '不完全な文です。',
42
+ '演算子『=』が解決していません。',
43
+ '演算子『=』は『文字列『こんにち』と単語『を表示』が等しいかどうかの比較』として使われています。',
44
+ 'main.nako3',
45
+ ], NakoSyntaxError)
46
+ })
47
+ it('単項演算子', () => {
48
+ cmp('!(はい + 1)', [
49
+ '不完全な文です。',
50
+ '演算子『not』が解決していません。',
51
+ '演算子『not』は『演算子『+』に演算子『not』を適用した式』として使われています。',
52
+ 'main.nako3',
53
+ ], NakoSyntaxError)
54
+ })
55
+ it('2項演算子', () => {
56
+ cmp('1 + 2', [
57
+ '不完全な文です。',
58
+ '演算子『+』が解決していません。',
59
+ '演算子『+』は『数値1と数値2に演算子『+』を適用した式』として使われています。',
60
+ 'main.nako3',
61
+ ], NakoSyntaxError)
62
+ })
63
+ it('変数のみの式', () => {
64
+ cmp('A', [
65
+ '不完全な文です。',
66
+ '単語『A』が解決していません。',
67
+ 'main.nako3',
68
+ ], NakoSyntaxError)
69
+ })
70
+ it('複数のノードが使われていない場合', () => {
71
+ cmp('あ「こんにちは」はは表示', [
72
+ '不完全な文です。',
73
+ '単語『あ』、演算子『=』が解決していません。',
74
+ '演算子『=』は『文字列『こんにちは』と単語『は表示』が等しいかどうかの比較』として使われています。',
75
+ 'main.nako3',
76
+ ], NakoSyntaxError)
77
+ })
78
+ it('関数の宣言でエラー', () => {
79
+ cmp('●30とは', [
80
+ '関数30の宣言でエラー。',
81
+ 'main.nako3',
82
+ ], NakoSyntaxError)
83
+ })
84
+ it('依存ファイルにエラーがある場合', () => {
85
+ cmp('!「./syntax_error.nako3」を取り込む\n1を表示', [
86
+ 'syntax_error.nako3',
87
+ '2行目',
88
+ ], NakoSyntaxError, new CNako3())
89
+ })
90
+ it('"_"がある場合', () => {
91
+ cmp(
92
+ `a = [ _\n` +
93
+ ` 1, 2, 3\n` +
94
+ `]\n` +
95
+ `「こんにちは」」と表示する`, [
96
+ '4行目',
97
+ 'main.nako3'
98
+ ], NakoLexerError
99
+ )
100
+ })
101
+ })
102
+ describe('実行時エラー', () => {
103
+ it('「エラー発生」の場合', () => {
104
+ cmp(
105
+ '「エラーメッセージ」のエラー発生', [
106
+ '1行目',
107
+ ], NakoRuntimeError)
108
+ })
109
+ it('依存ファイルでエラーが発生した場合', () => {
110
+ cmp('!「./runtime_error.nako3」を取り込む\n1を表示', [
111
+ 'runtime_error.nako3',
112
+ '2行目',
113
+ ], NakoRuntimeError, new CNako3())
114
+ })
115
+ it('エラー位置をプロパティから取得 - 単純な例', () => {
116
+ assert.throws(
117
+ () => nako.run('1を表示\n1のエラー発生', 'main.nako3'),
118
+ err => {
119
+ assert(err instanceof NakoRuntimeError)
120
+ assert.strictEqual(err.line, 1) // 2行目
121
+ assert.strictEqual(err.file, 'main.nako3')
122
+ return true
123
+ }
124
+ )
125
+ })
126
+ it('エラー位置をプロパティから取得 - 前後に文がある場合', () => {
127
+ assert.throws(
128
+ () => nako.run('1を表示\n1を表示。1のエラー発生。1を表示。', 'main.nako3'),
129
+ err => {
130
+ assert(err instanceof NakoRuntimeError)
131
+ assert.strictEqual(err.line, 1) // 2行目
132
+ assert.strictEqual(err.file, 'main.nako3')
133
+ return true
134
+ }
135
+ )
136
+ })
137
+ it('エラー位置をプロパティから取得 - 1行目の場合', () => {
138
+ assert.throws(
139
+ () => nako.run('1のエラー発生', 'main.nako3'),
140
+ err => {
141
+ assert(err instanceof NakoRuntimeError)
142
+ assert.strictEqual(err.line, 0) // 1行目
143
+ assert.strictEqual(err.file, 'main.nako3')
144
+ return true
145
+ }
146
+ )
147
+ })
148
+ it('エラー位置をプロパティから取得 - repeatTimes', () => {
149
+ assert.throws(
150
+ () => nako.run('3回\n1のエラー発生\nここまで', 'main.nako3'),
151
+ err => {
152
+ assert(err instanceof NakoRuntimeError)
153
+ assert.strictEqual(err.line, 1) // 2行目
154
+ assert.strictEqual(err.file, 'main.nako3')
155
+ return true
156
+ }
157
+ )
158
+ })
159
+ it('「秒後」の中でエラーが発生した場合', (done) => {
160
+ const nako = new NakoCompiler()
161
+ const logger = nako.run('0.0001秒後には\n1のエラー発生\nここまで', 'main.nako3').logger
162
+ logger.addListener('error', ({ level, noColor }) => {
163
+ assert.strictEqual(level, 'error')
164
+ assert.strictEqual(noColor, '[実行時エラー]main.nako3(2行目): エラー『1』が発生しました。')
165
+ done()
166
+ })
167
+ })
168
+ it('JavaScriptのみで動くコードの場合 - エラー発生', function () {
169
+ if (process.env.NODE_ENV === 'test') {return this.skip()}
170
+ const nako = new NakoCompiler()
171
+ const code = nako.compileStandalone('10のエラー発生')
172
+ const silent = 'const console = { error() {} };\n'
173
+ assert.throws(
174
+ () => new Function(silent + code)(),
175
+ (err) => {
176
+ assert.strictEqual(err.message.split('\n')[0], '[実行時エラー](1行目): エラー『10』が発生しました。')
177
+ return true
178
+ },
179
+ )
180
+ })
181
+ it('JavaScriptのみで動くコードの場合 - 「秒後」内の場合', function (done) {
182
+ if (process.env.NODE_ENV === 'test') {return this.skip()}
183
+ const nako = new NakoCompiler()
184
+ new Function('const console = { error: this.callback };\n' + nako.compileStandalone('0.0001秒後には\n20のエラー発生\nここまで')).apply({
185
+ callback: (err) => {
186
+ assert.strictEqual(err.message.split('\n')[0], '[実行時エラー](2行目): エラー『20』が発生しました。')
187
+ done()
188
+ }
189
+ })
190
+ })
191
+ })
192
+ describe('インデント構文のエラー', () => {
193
+ it('『ここまで』を使用', () => {
194
+ cmp(
195
+ '!インデント構文\n' +
196
+ 'もしはいならば\n' +
197
+ 'ここまで\n', [
198
+ '3行目',
199
+ 'main.nako3',
200
+ 'インデント構文が有効化されているときに『ここまで』を使うことはできません。'
201
+ ], NakoIndentError)
202
+ })
203
+ it('『ここまで』を使用 - "_"を使った場合', () => {
204
+ cmp(
205
+ '!インデント構文\n' +
206
+ 'A=[ _\n' +
207
+ ']\n' +
208
+ 'ここまで\n', [
209
+ '4行目',
210
+ 'main.nako3',
211
+ ], NakoIndentError)
212
+ })
213
+ })
214
+ describe('警告の表示', () => {
215
+ it('未定義の変数を参照したとき', () => {
216
+ const compiler = new NakoCompiler()
217
+ let log = ''
218
+ compiler.logger.addListener('warn', ({ noColor }) => { log += noColor }, false)
219
+ compiler.run(`xを表示`, 'main.nako3')
220
+ assert.strictEqual(log.split('。')[0], `[警告]main.nako3(1行目): 変数『x』は定義されていません`)
221
+ })
222
+ it('存在しない高速化オプションを指定したとき', () => {
223
+ const compiler = new NakoCompiler()
224
+ let log = ''
225
+ compiler.logger.addListener('warn', ({ noColor }) => { log += noColor }, false)
226
+ compiler.run(`「あ」で実行速度優先\nここまで`, 'main.nako3')
227
+ assert.strictEqual(log, `[警告]main.nako3(1行目): 実行速度優先文のオプション『あ』は存在しません。`)
228
+ })
229
+ it('ユーザー定義関数を上書きしたとき', () => {
230
+ const compiler = new NakoCompiler()
231
+ let log = ''
232
+ compiler.logger.addListener('warn', ({ noColor }) => { log += noColor }, false)
233
+ compiler.run(`●Aとは\nここまで\n●Aとは\nここまで`, 'main.nako3')
234
+ assert.strictEqual(log, `[警告]main.nako3(3行目): 関数『A』は既に定義されています。`)
235
+ })
236
+ it('プラグイン関数を上書きしたとき', () => {
237
+ const compiler = new NakoCompiler()
238
+ let log = ''
239
+ compiler.logger.addListener('warn', ({ noColor }) => { log += noColor }, false)
240
+ compiler.run(`●(Aを)足すとは\nここまで`, 'main.nako3')
241
+ assert.strictEqual(log, '[警告]main.nako3(1行目): 関数『足』は既に定義されています。')
242
+ })
243
+ })
244
+ })
@@ -0,0 +1,6 @@
1
+ // もし「回」が2回分割されるなら、2つめの「回」の引数は「それ」 = 「回数」 = 1 であり、「1を表示」は1回だけ実行される。
2
+ // もし「回」が1回だけ分割されるなら、「一回」 = undefiend 回繰り返すため、「1を表示」は実行されない。
3
+ 一=1
4
+ 一回回
5
+ 1を表示
6
+ ここまで
@@ -0,0 +1,43 @@
1
+ const assert = require('assert')
2
+ const child_process = require('child_process')
3
+ const path = require('path')
4
+ const fs = require ('fs')
5
+
6
+ const cnako3 = path.join(__dirname, '../../src/cnako3.js')
7
+ const packagejson = require('../../package.json')
8
+ const debug = false
9
+
10
+ describe('node_test(cnako)', () => {
11
+ const cmp = (code, exRes) => {
12
+ const result = child_process.execSync(`node ${cnako3} -e "${code}"`).toString().replace(/\s+$/, '')
13
+ if (debug) {
14
+ console.log('code=' + code)
15
+ console.log('result=' + result)
16
+ }
17
+ assert.strictEqual(result, exRes)
18
+ }
19
+ // --- バージョンチェック ---
20
+ it('ナデシコバージョン:src/plugin_system.jsを正しく設定しているか?', () => {
21
+ cmp('ナデシコバージョンを表示', packagejson.version)
22
+ cmp('ナデシコ種類を表示', 'cnako3')
23
+ })
24
+ // --- test ---
25
+ it('print simple', () => {
26
+ cmp('3を表示', '3')
27
+ cmp('1+2*3を表示', '7')
28
+ cmp('A=30;「--{A}--」を表示', '--30--')
29
+ }).timeout(15000)
30
+
31
+ it('単独で実行できるプログラムの出力 - Node.js', function () {
32
+ if (process.env.NODE_ENV === 'test') {return this.skip()}
33
+ const stderr = child_process.spawnSync('node', [cnako3, '-c', path.join(__dirname, 'add_test.nako3')]).stderr
34
+ try {
35
+ if (stderr) { console.error(stderr.toString()) }
36
+ const p = child_process.spawnSync('node', [path.join(__dirname, 'add_test.js')])
37
+ if (p.stderr) { console.error(p.stderr.toString()) }
38
+ assert.strictEqual(p.stdout.toString(), '3\n')
39
+ } finally {
40
+ fs.unlinkSync(path.join(__dirname, 'add_test.js'))
41
+ }
42
+ })
43
+ })
@@ -0,0 +1,3 @@
1
+ // 読み込むだけでエラーが発生するプラグインの例。
2
+ // .jsだとテストファイルとして読み込まれてしまうため.js.txtを使用。
3
+ throw new Error("テスト")