nadesiko3 3.4.21 → 3.4.22

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 (90) hide show
  1. package/README.md +3 -2
  2. package/batch/.DS_Store +0 -0
  3. package/batch/command.txt +88 -13
  4. package/batch/command_nakopad.txt +72 -1
  5. package/batch/pickup_command.nako3 +2 -0
  6. package/core/batch/.DS_Store +0 -0
  7. package/core/command/.DS_Store +0 -0
  8. package/core/src/plugin_system.mts +1 -1
  9. package/demo/extlib/.DS_Store +0 -0
  10. package/demo/index.html +3 -6
  11. package/package.json +2 -2
  12. package/release/.DS_Store +0 -0
  13. package/release/_hash.txt +16 -16
  14. package/release/_script-tags.txt +14 -14
  15. package/release/command.json +1 -1
  16. package/release/command.json.js +1 -1
  17. package/release/command_cnako3.json +1 -1
  18. package/release/command_list.json +1 -1
  19. package/release/editor.js +1 -1
  20. package/release/editor.js.map +1 -1
  21. package/release/stats.json +1 -1
  22. package/release/version.js +1 -1
  23. package/release/version.js.map +1 -1
  24. package/release/wnako3.js +1 -1
  25. package/release/wnako3.js.map +1 -1
  26. package/src/browsers.json +1 -1
  27. package/src/nako_version.mjs +2 -2
  28. package/src/nako_version.mts +2 -2
  29. package/src/plugin_browser.mjs +15 -2
  30. package/src/plugin_browser.mts +15 -2
  31. package/src/plugin_browser_chart.mjs +29 -23
  32. package/src/plugin_browser_chart.mts +29 -23
  33. package/src/plugin_browser_dom_parts.mjs +20 -0
  34. package/src/plugin_browser_dom_parts.mts +20 -0
  35. package/test/.DS_Store +0 -0
  36. package/test/browser/.DS_Store +0 -0
  37. package/test/bundled/.DS_Store +0 -0
  38. package/test/bundled/test_base/.DS_Store +0 -0
  39. package/test/common/.DS_Store +0 -0
  40. package/test/node/.DS_Store +0 -0
  41. package/test/node/plugin_node_test.mjs +8 -0
  42. package/test/selenium/.DS_Store +0 -0
  43. package/test/selenium/requirements.txt +1 -1
  44. package/test/selenium/test_chrome.py +1 -1
  45. package/tools/.DS_Store +0 -0
  46. package/tools/nako3edit/.DS_Store +0 -0
  47. package/tools/nako3edit/html/.DS_Store +0 -0
  48. package/core/.editorconfig +0 -6
  49. package/core/.eslintrc.cjs +0 -41
  50. package/core/.github/dependabot.yml +0 -7
  51. package/core/.github/workflows/nodejs.yml +0 -40
  52. package/core/.github/workflows/textlint.yml +0 -199
  53. package/core/bun.lockb +0 -0
  54. package/core/core.code-workspace +0 -8
  55. package/core/deno/plugin_snako_deno.ts +0 -109
  56. package/core/deno/snako.ts +0 -116
  57. package/core/deno_build_ver.sh +0 -4
  58. package/core/deno_hello.sh +0 -7
  59. package/core/doc/README.md +0 -68
  60. package/core/index.mts +0 -27
  61. package/core/package-lock.json +0 -3579
  62. package/core/test/andor_test.mjs +0 -26
  63. package/core/test/array_test.mjs +0 -65
  64. package/core/test/basic_test.mjs +0 -358
  65. package/core/test/calc_test.mjs +0 -240
  66. package/core/test/core_module_test.mjs +0 -23
  67. package/core/test/debug_test.mjs +0 -17
  68. package/core/test/dncl2_test.mjs +0 -246
  69. package/core/test/dncl_test.mjs +0 -179
  70. package/core/test/error_message_test.mjs +0 -210
  71. package/core/test/error_test.mjs +0 -17
  72. package/core/test/flow_test.mjs +0 -433
  73. package/core/test/func_call.mjs +0 -163
  74. package/core/test/func_test.mjs +0 -150
  75. package/core/test/indent_test.mjs +0 -273
  76. package/core/test/inline_indent_test.mjs +0 -178
  77. package/core/test/lex_test.mjs +0 -177
  78. package/core/test/literal_test.mjs +0 -87
  79. package/core/test/nako_lexer_test.mjs +0 -36
  80. package/core/test/nako_logger_test.mjs +0 -78
  81. package/core/test/or_test.mjs +0 -30
  82. package/core/test/plugin_csv_test.mjs +0 -38
  83. package/core/test/plugin_math_test.mjs +0 -34
  84. package/core/test/plugin_promise_test.mjs +0 -18
  85. package/core/test/plugin_system_test.mjs +0 -651
  86. package/core/test/prepare_test.mjs +0 -96
  87. package/core/test/re_test.mjs +0 -22
  88. package/core/test/side_effects_test.mjs +0 -98
  89. package/core/test/variable_scope_test.mjs +0 -149
  90. package/core/tsconfig.json +0 -102
@@ -1,177 +0,0 @@
1
- /* eslint-disable no-undef */
2
- import assert from 'assert'
3
- import { NakoCompiler } from '../src/nako3.mjs'
4
-
5
- describe('lex_test', async () => {
6
- // nako.logger.addListener('trace', ({ browserConsole }) => { console.log(...browserConsole) })
7
- const cmp = async (/** @type {string} */ code, /** @type {string} */ res) => {
8
- const nako = new NakoCompiler()
9
- nako.logger.debug('code=' + code)
10
- assert.strictEqual((await nako.runAsync(code)).log, res)
11
- }
12
- // --- test ---
13
- it('送り仮名の省略テスト', async () => {
14
- await cmp('『abc』の『a』を「*」に置換。表示', '*bc')
15
- await cmp('『abc』の『a』を「*」に置換します。それを表示', '*bc')
16
- await cmp('『abc』の『a』を「*」に置換しろ。表示しろ。', '*bc')
17
- })
18
- it('仮名表記の曖昧', async () => {
19
- await cmp('『abc』の『a』を「*」に置き換え。表示', '*bc')
20
- })
21
- it('範囲コメントの処理', async () => {
22
- await cmp('1を表示\n/*2を表示\n3を表示\n*/\n4を表示\n', '1\n4')
23
- await cmp('1を表示\n/*2を表示\n3を表示\n4を表示\n5を表示\n*/\n6を表示\n', '1\n6')
24
- })
25
- it('文字列の埋め込み', async () => {
26
- await cmp('見出し=30;「--{見出し}--」を表示', '--30--')
27
- })
28
- it('文字列の埋め込み語句のかな省略', async () => {
29
- await cmp('見出し=30;「--{見出}--」を表示', '--30--')
30
- })
31
- it('文字列に式を埋め込む', async () => {
32
- await cmp('「--{3に2を掛ける}--」を表示', '--6--')
33
- })
34
- it('文字列の埋め込み変数名全角英数字', async () => {
35
- await cmp('N1=30;「--{N1}--」を表示', '--30--')
36
- })
37
- it('文字列の埋め込みで対応しない閉じ括弧がある場合', async () => {
38
- await cmp('B=1;E=2;「A{B}C}D{E}F」を表示', 'A1C}D2F')
39
- })
40
- it('文字列の埋め込み配列', async () => {
41
- await cmp('手説明=["グー","チョキ","パー"];「自分は{手説明@1}、相手は{手説明@0}」と表示', '自分はチョキ、相手はグー')
42
- })
43
- it('はい/いいえ', async () => {
44
- await cmp('はいを表示', '1')
45
- await cmp('いいえを表示', '0')
46
- })
47
- it('A = 8の書き方', async () => {
48
- await cmp('A = 8;Aを表示', '8')
49
- })
50
- it('数値表現のテスト', async () => {
51
- await cmp('123e1を表示', '1230')
52
- await cmp('123E-1を表示', '12.3')
53
- await cmp('123e+1を表示', '1230')
54
- await cmp('.123e-1を表示', '0.0123')
55
- await cmp('123.e1を表示', '1230')
56
- })
57
- it('2進数/8進数/16進数のテスト', async () => {
58
- await cmp('0xFFを表示', '255')
59
- await cmp('0XFFを表示', '255')
60
- await cmp('0b11を表示', '3')
61
- await cmp('0B1111を表示', '15')
62
- await cmp('0o10を表示', '8')
63
- await cmp('0O11を表示', '9')
64
- })
65
- it('bigintのテスト', async () => {
66
- await cmp('12345678901234567890123nを表示', '12345678901234567890123')
67
- await cmp('-12345678901234567890123nを表示', '-12345678901234567890123')
68
- await cmp('0x123456789abcdefnを表示', '81985529216486895')
69
- await cmp('0o1234567123456712345671234567nを表示', '3158001080923004573399415')
70
- await cmp('0b1101011010100101101110100101000111011011010101011110011100111000110011100110110101101nを表示', '32436594107500554171829677')
71
- await cmp('1_2_3_4_5678_9_0_1_234_567_890_123nを表示', '12345678901234567890123')
72
- })
73
- it('《特別名トークン》のテスト', async () => {
74
- await cmp('《今日から明日》=30;《今日から明日》を表示', '30')
75
- await cmp('《AからBまで》=30;《AからBまで》を表示', '30')
76
- })
77
- it('以上、以下、超、未満 (#918)', async () => {
78
- await cmp('A=4;もし、Aが2以上ならば\nAを表示;\nここまで。', '4')
79
- await cmp('A=4;もし、30がA以上ならば\nAを表示;\nここまで。', '4')
80
- })
81
- it('ソースマップ - 単純な例', async () => {
82
- const nako = new NakoCompiler()
83
- const tokens = nako.lex('「こんにちは」と表示', 'main.nako3', '').tokens
84
-
85
- // 0-7文字目: 「こんにちは」と
86
- assert.strictEqual(tokens[0].startOffset, 0)
87
- assert.strictEqual(tokens[0].endOffset, 8)
88
-
89
- // 8-9文字目: 表示
90
- assert.strictEqual(tokens[1].startOffset, 8)
91
- assert.strictEqual(tokens[1].endOffset, 10)
92
- })
93
- it('ソースマップ - スペース扱いの文字', async () => {
94
- // '・'はスペース扱いであり、トークン化されない。
95
- const nako = new NakoCompiler()
96
- const tokens = nako.lex('ならば・A', 'main.nako3', '').tokens
97
-
98
- // 0-2文字目: ならば
99
- assert.strictEqual(tokens[0].startOffset, 0)
100
- assert.strictEqual(tokens[0].endOffset, 3)
101
-
102
- // 4文字目: A
103
- assert.strictEqual(tokens[1].startOffset, 4)
104
- assert.strictEqual(tokens[1].endOffset, 5)
105
- })
106
- it('ソースマップ - 複数行の場合', async () => {
107
- const nako = new NakoCompiler()
108
- const tokens = nako.lex('「こんにちは」を表示する。\n「こんにちは」を表示する。', 'main.nako3', '').tokens
109
- assert.strictEqual(tokens[0].startOffset, 0) // 0-7: 「こんにちは」を
110
- assert.strictEqual(tokens[1].startOffset, 8) // 8-11: 表示する
111
- assert.strictEqual(tokens[2].startOffset, 12) // 12: 。
112
- assert.strictEqual(tokens[3].startOffset, 13) // 13: eol
113
- assert.strictEqual(tokens[4].startOffset, 14) // 14-21: 「こんにちは」を
114
- assert.strictEqual(tokens[5].startOffset, 22) // 22-25: 表示する
115
- assert.strictEqual(tokens[6].startOffset, 26) // 26: 。
116
- })
117
- it('ソースマップ - 行コメント', async () => {
118
- const nako = new NakoCompiler()
119
- const tokens = nako.lex('# コメント').commentTokens
120
- assert.strictEqual(tokens[0].startOffset, 0)
121
- assert.strictEqual(tokens[0].endOffset, 6)
122
- })
123
- it('ソースマップ - 範囲コメント', async () => {
124
- const nako = new NakoCompiler()
125
- const tokens = nako.lex('/*\nここは全部コメント\nここは全部コメント\n*/').commentTokens
126
- assert.strictEqual(tokens[0].startOffset, 0)
127
- assert.strictEqual(tokens[0].endOffset, 25)
128
- })
129
- it('ソースマップ - 範囲コメントの直後に文字がある場合', async () => {
130
- const nako = new NakoCompiler()
131
- const result = nako.lex('/*\nここは全部コメント\nここは全部コメント\n*/a')
132
-
133
- // コメント
134
- assert.strictEqual(result.commentTokens[0].startOffset, 0)
135
- assert.strictEqual(result.commentTokens[0].endOffset, 25)
136
-
137
- // a
138
- assert.strictEqual(result.tokens[0].startOffset, 25)
139
- assert.strictEqual(result.tokens[0].endOffset, 26)
140
- })
141
- it('ソースマップ - "_"による改行', async () => {
142
- const nako = new NakoCompiler()
143
- const tokens = nako.lex('[_\n]\nりんごの値段は30').tokens
144
- const nedan = tokens.find((t) => t.value === '値段') || { startOffset: 0, endOffset: 0 }
145
- assert.strictEqual(nedan.startOffset, 9)
146
- assert.strictEqual(nedan.endOffset, 11)
147
- })
148
- it('ソースマップ - インデント構文', async () => {
149
- const nako = new NakoCompiler()
150
- const tokens = nako.lex('!インデント構文\n1回\n 「2」を表示\n\n「3」を表示').tokens
151
- // @ts-ignore
152
- assert.strictEqual(tokens.find((t) => t.value === '2').startOffset, 16) // 「1」を
153
- // @ts-ignore
154
- assert.strictEqual(tokens.find((t) => t.value === '3').startOffset, 24) // 「2」を
155
- })
156
- it('ソースマップ - string_ex', async () => {
157
- const nako = new NakoCompiler()
158
- const tokens = nako.lex('"{あ}"').tokens
159
- // @ts-ignore
160
- assert.strictEqual(tokens.find((t) => t.value === 'あ').startOffset, 2)
161
- // @ts-ignore
162
- assert.strictEqual(tokens.find((t) => t.value === 'あ').endOffset, 3)
163
- })
164
- it('「ならば」+「(全角|半角)空白」直後の改行が消える問題 #1015', async () => {
165
- await cmp('もし、3=3ならば \n『OK』と表示;違えば;「NG」と表示;ここまで。', 'OK')
166
- await cmp('もし、3=3ならば \n『OK』と表示;違えば;「NG」と表示;ここまで。', 'OK')
167
- })
168
- it('助詞の前後に空白があるとエラーになる問題 #1079', async () => {
169
- await cmp('x=1;x と 2 と "3" を連続表示', '123')
170
- })
171
- it('丸付き数字が変数名として使えない #1185', async () => {
172
- await cmp('⓪=0;①=1;㊿=50;❿=10;⓪+①+㊿+❿を表示', '61')
173
- })
174
- it('絵文字の四則演算を認識する #1183', async () => {
175
- await cmp('リンゴ🟰3✖5;ミカン🟰9➗3;リンゴ+ミカンを表示', '18')
176
- })
177
- })
@@ -1,87 +0,0 @@
1
- /* eslint-disable no-undef */
2
- import assert from 'assert'
3
- import { NakoCompiler } from '../src/nako3.mjs'
4
-
5
- describe('literal_test', async () => {
6
- const cmp = async (/** @type {string} */ code, /** @type {string} */ res) => {
7
- const nako = new NakoCompiler()
8
- nako.logger.debug('code=' + code)
9
- assert.strictEqual((await nako.runAsync(code)).log, res)
10
- }
11
- const err = async (/** @type {string} */ code) => {
12
- const nako = new NakoCompiler()
13
- nako.logger.debug('code=' + code)
14
- try {
15
- await nako.runAsync(code)
16
- } catch (error) {
17
- assert.ok(error)
18
- return
19
- }
20
- assert.fail()
21
- }
22
- // --- test ---
23
- it('非数', async () => {
24
- await cmp('0/0を表示', 'NaN')
25
- await cmp('非数を表示', 'NaN')
26
- })
27
- it('無限大', async () => {
28
- await cmp('3/無限大を表示', '0')
29
- })
30
- describe('十進法のテスト', async () => {
31
- // 基本的に(整数部)(小数部)(指数部)です
32
- it('0', async () => {
33
- await cmp('0の変数型確認して表示', 'number')
34
- await cmp('013+014を表示', '27') // javascriptとは違い0から始まる7以下の数字だけで構成される数は八進数ではなく十進数として解釈されます
35
- })
36
- it('小数点', async () => {
37
- await cmp('.11の変数型確認して表示', 'number') // 小数点から始まっても数として解釈
38
- await cmp('222.の変数型確認して表示', 'number') // 逆に小数点で終わっても数として解釈
39
- err('123.$の変数型確認して表示') // しかしドットの後に定義されていない文字列をくっつけるとエラー
40
- })
41
- it('指数表記', async () => {
42
- await cmp('7e+8=7e8を表示', 'true') // 指数表記の+は省略可能
43
- await cmp('7.5e8の変数型確認して表示', 'number') // 小数と組み合わせることもできる
44
- await cmp('7.e8の変数型確認して表示', 'number') // もちろん小数部を省略しても数として解釈
45
- })
46
- })
47
- it('十六進法のテスト', async () => {
48
- await cmp('0x1dfの変数型確認して表示', 'number')
49
- })
50
- it('八進法のテスト', async () => {
51
- await cmp('0o157の変数型確認して表示', 'number')
52
- })
53
- it('二進法のテスト', async () => {
54
- await cmp('0b101の変数型確認して表示', 'number')
55
- })
56
- it('数値区切文字', async () => {
57
- await cmp('12345_00=123_4500を表示', 'true') // 区切り文字として「_」が使用できます
58
- await cmp('12345_00=1_23_4500を表示', 'true') // 数字の中でのどこでも使用できます
59
- err('1____23_4500を表示') // 連続して使うことはできません
60
- await cmp('_123を表示', 'undefined') // 区切り文字で始めることはできません(定義されていない変数「_123」の参照)
61
- err('123_を表示') // 区切り文字で終わらせることはできません
62
- await cmp('0xCAFE_F00Dの変数型確認して表示', 'number') // 十六進数でも
63
- await cmp('0o123456_777の変数型確認して表示', 'number') // 八進数でも
64
- await cmp('0b1111_0000の変数型確認して表示', 'number') // 二進数でも
65
- await cmp('101_475_938.322_8の変数型確認して表示', 'number') // 小数でも
66
- err('3_.1415の変数型確認して表示') // 小数点等の標識の前後では区切り文字は使えません
67
- err('3e_1415の変数型確認して表示')
68
- })
69
- it('単位のテスト #994', async () => {
70
- await cmp('30kgを表示', '30')
71
- await cmp('A=100円;Aを表示', '100')
72
- await cmp('B=300㎡;B=B+1㎡;Bを表示', '301')
73
- })
74
- it('bigintのテスト', async () => {
75
- await cmp('123456789nの変数型確認して表示', 'bigint')
76
- await cmp('-123456789nの変数型確認して表示', 'bigint')
77
- await cmp('0x123456789ABCDEFnの変数型確認して表示', 'bigint')
78
- await cmp('-0x123456789ABCDEFnの変数型確認して表示', 'bigint')
79
- await cmp('0x123456789nの変数型確認して表示', 'bigint')
80
- await cmp('-0x123456789nの変数型確認して表示', 'bigint')
81
- await cmp('0o1234567nの変数型確認して表示', 'bigint')
82
- await cmp('-0o1234567nの変数型確認して表示', 'bigint')
83
- await cmp('0b10111010110nの変数型確認して表示', 'bigint')
84
- await cmp('-0b10111010110nの変数型確認して表示', 'bigint')
85
- await cmp('123_456_789nの変数型確認して表示', 'bigint')
86
- })
87
- })
@@ -1,36 +0,0 @@
1
- /* eslint-disable no-undef */
2
- import assert from 'assert'
3
- import { NakoLexer } from '../src/nako_lexer.mjs'
4
- import { NakoLogger } from '../src/nako_logger.mjs'
5
- import { NakoPrepare } from '../src/nako_prepare.mjs'
6
-
7
- describe('nako_lexer_test', () => {
8
- const lex = new NakoLexer(new NakoLogger())
9
- const pre = NakoPrepare.getInstance()
10
- // --- test ---
11
- it('トークンの区切りテスト', () => {
12
- const a = lex.tokenize('Nは30', 0, 'test.nako3')
13
- assert.strictEqual(NakoLexer.tokensToTypeStr(a, '|'), 'word|number')
14
- const b = lex.tokenize('もしN=30ならば', 0, 'test.nako3')
15
- assert.strictEqual(NakoLexer.tokensToTypeStr(b, '|'), 'もし|word|eq|number')
16
- })
17
- it('関数の登録テスト', () => {
18
- const code = '●AAAとは\n「あ」を表示\nここまで。\n'
19
- const code2 = pre.convert(code).map((v) => v.text).join('')
20
- const tok = lex.tokenize(code2, 0, 'test.nako3')
21
- /** @type {any} */
22
- const funclist = {}
23
- // @ts-ignore
24
- NakoLexer.preDefineFunc(tok, lex.logger, funclist)
25
- assert.strictEqual(funclist.test__AAA.type, 'func')
26
- })
27
- it('変数は登録しないというテスト', () => {
28
- const code = 'HOGE=333\n'
29
- const code2 = pre.convert(code).map((v) => v.text).join('')
30
- const tok = lex.tokenize(code2, 0, 'test.nako3')
31
- /** @type {any} */
32
- const funclist = {}
33
- NakoLexer.preDefineFunc(tok, lex.logger, funclist)
34
- assert.strictEqual(funclist.HOGE, undefined)
35
- })
36
- })
@@ -1,78 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- /* eslint-disable no-undef */
3
- import assert from 'assert'
4
- import { NakoColors } from '../src/nako_colors.mjs'
5
- import { NakoLogger } from '../src/nako_logger.mjs'
6
- describe('nako_logger_test', () => {
7
- it('色付けのテスト', () => {
8
- const out = NakoColors.convertColorTextFormat(`デフォルト${NakoColors.color.bold}太字${NakoColors.color.red}太字赤${NakoColors.color.reset}デフォルト<script>`)
9
- assert.strictEqual(out.noColor, 'デフォルト太字太字赤デフォルト<script>')
10
- assert.strictEqual(out.nodeConsole, 'デフォルト\u001b[1m太字\u001b[31m太字赤\u001b[0mデフォルト<script>\u001b[0m')
11
- assert.strictEqual(out.html, '<span>デフォルト</span><span style="color: inherit; font-weight: bold;">太字</span><span style="color: red; font-weight: bold;">太字赤</span><span style="color: inherit; font-weight: inherit;">デフォルト&lt;script&gt;</span>')
12
- assert.deepStrictEqual(out.browserConsole, [
13
- 'デフォルト%c太字%c太字赤%cデフォルト<script>',
14
- 'color: inherit; font-weight: bold;',
15
- 'color: red; font-weight: bold;',
16
- 'color: inherit; font-weight: inherit;'
17
- ])
18
- })
19
- it('ログの取得のテスト', (done) => {
20
- const logger = new NakoLogger()
21
- logger.addListener('info', (data) => {
22
- assert.strictEqual(data.noColor, '[情報]main.nako3(2行目): foo')
23
- done()
24
- })
25
- logger.info('foo', {
26
- startOffset: 0,
27
- endOffset: 0,
28
- line: 1,
29
- file: 'main.nako3'
30
- })
31
- })
32
- it('複数のリスナーのテスト1', () => {
33
- const logger = new NakoLogger()
34
- let logStr = ''
35
- logger.addListener('info', (data) => { logStr += 'i' })
36
- logger.addListener('error', (data) => { logStr += 'e' })
37
- logger.addListener('stdout', (data) => { logStr += 's' })
38
- logger.error('foo', { startOffset: 0, endOffset: 0, line: 1, file: 'main.nako3' })
39
- assert.strictEqual(logStr, 'ie')
40
- })
41
- it('複数リスナーのテスト2', () => {
42
- const logger = new NakoLogger()
43
- let logStr = ''
44
- logger.addListener('info', (data) => { logStr += 'i' })
45
- logger.addListener('error', (data) => { logStr += 'e' })
46
- logger.addListener('stdout', (data) => { logStr += 's' })
47
- logger.info('foo', { startOffset: 0, endOffset: 0, line: 1, file: 'main.nako3' })
48
- assert.strictEqual(logStr, 'i')
49
- })
50
- it('複数リスナーのテスト3', () => {
51
- const logger = new NakoLogger()
52
- let logStr = ''
53
- logger.addListener('info', (data) => { logStr += 'i' })
54
- logger.addListener('error', (data) => { logStr += 'e' })
55
- logger.addListener('stdout', (data) => { logStr += 's' })
56
- logger.stdout('foo', { startOffset: 0, endOffset: 0, line: 1, file: 'main.nako3' })
57
- assert.strictEqual(logStr, 'ies')
58
- })
59
- it('複数リスナーのテスト4', () => {
60
- const logger = new NakoLogger()
61
- let logStr = ''
62
- logger.addListener('info', (data) => { logStr += 'i' })
63
- logger.addListener('error', (data) => { logStr += 'e' })
64
- logger.addListener('stdout', (data) => { logStr += 's' })
65
- logger.stdout('foo', { startOffset: 0, endOffset: 0, line: 1, file: 'main.nako3' })
66
- assert.strictEqual(logStr, 'ies')
67
- })
68
- it('複数リスナーのテスト5', () => {
69
- const logger = new NakoLogger()
70
- let logStr = ''
71
- logger.addListener('all', (data) => { logStr += 'a' })
72
- logger.addListener('info', (data) => { logStr += 'i' })
73
- logger.addListener('error', (data) => { logStr += 'e' })
74
- logger.addListener('stdout', (data) => { logStr += 's' })
75
- logger.info('foo', { startOffset: 0, endOffset: 0, line: 1, file: 'main.nako3' })
76
- assert.strictEqual(logStr, 'ai')
77
- })
78
- })
@@ -1,30 +0,0 @@
1
- /* eslint-disable no-undef */
2
- import assert from 'assert'
3
- import { NakoCompiler } from '../src/nako3.mjs'
4
-
5
- describe('or_test.js', async () => {
6
- const cmp = async (/** @type {string} */ code, /** @type {string} */ res) => {
7
- const nako = new NakoCompiler()
8
- assert.strictEqual((await nako.runAsync(code)).log, res)
9
- }
10
- it('『または』がうまく動いてない #1379', async () => {
11
- await cmp('(0||0)を表示', '0')
12
- await cmp('(0または0)を表示', '0')
13
- await cmp('(0または1)を表示', '1')
14
- await cmp('ゼロ=0;(ゼロ||ゼロ)を表示', '0')
15
- await cmp('ゼロ=0;(ゼロまたはゼロ)を表示', '0')
16
- await cmp('ゼロ=0;イチ=1;(ゼロまたはイチ)を表示', '1')
17
- })
18
- it('『かつ』がうまく動いてない #1379', async () => {
19
- await cmp('(0かつ0)を表示', '0')
20
- await cmp('(1かつ1)を表示', '1')
21
- await cmp('ゼロ=0;イチ=1;(ゼロかつゼロ)を表示', '0')
22
- await cmp('ゼロ=0;イチ=1;(ゼロかつイチ)を表示', '0')
23
- await cmp('ゼロ=0;イチ=1;(ゼロかつゼロ)を表示', '0')
24
- await cmp('ゼロ=0;イチ=1;(イチかつイチ)を表示', '1')
25
- })
26
- it('『または』が動かない #1379', async () => {
27
- await cmp('条件イははい。条件ロはいいえ。もし、条件イまたは条件ロならば「AAA」と表示。', 'AAA')
28
- await cmp('条件イははい。条件ロははい。もし、条件イかつ条件ロならば「BBB」と表示。', 'BBB')
29
- })
30
- })
@@ -1,38 +0,0 @@
1
- /* eslint-disable no-undef */
2
- import assert from 'assert'
3
- import { NakoCompiler } from '../src/nako3.mjs'
4
-
5
- // eslint-disable-next-line no-undef
6
- describe('plugin_csv_test', () => {
7
- const cmp = async (/** @type {string} */ code, /** @type {string} */ res) => {
8
- const nako = new NakoCompiler()
9
- nako.logger.debug('code=' + code)
10
- const g = await nako.runAsync(code)
11
- assert.strictEqual(g.log, res)
12
- }
13
-
14
- // --- test ---
15
- it('CSV取得', async () => {
16
- await cmp('a=「1,2,3\n4,5,6」のCSV取得。a[1][2]を表示', '6')
17
- await cmp('a=「"a",b,c\n""a,b,c\na,""b,c\na,b,c""\n"a,\nb",c,d\na,"b,\nc",d\na,b,"c,\nd"」のCSV取得。a[5][1]を表示', 'b,\nc')
18
- await cmp('a=「1,"a""a",2」のCSV取得。a[0][1]を表示', 'a"a')
19
- await cmp('a=「1,"2""2",3\n4,5,6」のCSV取得。a[0][1]を表示', '2"2')
20
- await cmp('a=「1,,3\n4,5,6」のCSV取得。a[0][2]を表示', '3')
21
- await cmp('a=「1,2,3,\n4,5,6」のCSV取得。a[1][0]を表示', '4') // #353
22
- })
23
- it('TSV取得', async () => {
24
- await cmp('a=「1\t2\t3\n4\t5\t6」のTSV取得。a[1][2]を表示', '6')
25
- await cmp('a=「"a"\tb\tc\n""a\tb\tc\na\t""b\tc\na\tb\tc""\n"a\t\nb"\tc\td\na\t"b\t\nc"\td\na\tb\t"c\t\nd"」のTSV取得。a[5][1]を表示', 'b\t\nc')
26
- await cmp('a=「1\t"a""a"\t2」のTSV取得。a[0][1]を表示', 'a"a')
27
- await cmp('a=「1\t"2""2"\t3\n4\t5\t6」のTSV取得。a[0][1]を表示', '2"2')
28
- await cmp('a=「1\t\t3\n4\t5\t6」のTSV取得。a[0][2]を表示', '3')
29
- })
30
- it('表CSV変換', async () => {
31
- await cmp('[[1,2,3],[4,5,6]]を表CSV変換して表示', '1,2,3\r\n4,5,6')
32
- await cmp('[[1,2,"3\r\n,"],[4,5,6]]を表CSV変換して表示', '1,2,"3\r\n,"\r\n4,5,6')
33
- })
34
- it('表TSV変換', async () => {
35
- await cmp('[[1,2,3],[4,5,6]]を表TSV変換して表示', '1\t2\t3\r\n4\t5\t6')
36
- await cmp('[[1,2,"3\r\n\t"],[4,5,6]]を表TSV変換して表示', '1\t2\t"3\r\n\t"\r\n4\t5\t6')
37
- })
38
- })
@@ -1,34 +0,0 @@
1
- /* eslint-disable no-undef */
2
- import assert from 'assert'
3
- import { NakoCompiler } from '../src/nako3.mjs'
4
-
5
- // eslint-disable-next-line no-undef
6
- describe('plugin_math_test', async () => {
7
- const cmp = async (/** @type {string} */ code, /** @type {string} */ res) => {
8
- const nako = new NakoCompiler()
9
- assert.strictEqual((await nako.runAsync(code)).log, res)
10
- }
11
-
12
- // --- test ---
13
- it('算術関数/SIGN', async () => {
14
- await cmp('-5のSIGNを表示', '-1')
15
- await cmp('-5の符号を表示', '-1')
16
- await cmp('5の符号を表示', '1')
17
- await cmp('0の符号を表示', '0')
18
- })
19
- it('算術関数/FRAC', async () => {
20
- await cmp('5.5のFRACを表示', '0.5')
21
- await cmp('5.5の小数部分を表示', '0.5')
22
- await cmp('3.14の整数部分を表示', '3')
23
- await cmp('-3.14の整数部分を表示', '-3')
24
- })
25
- it('ATAN2', async () => {
26
- await cmp('90と15のATAN2を表示', '1.4056476493802699')
27
- await cmp('15と90のATAN2を表示', '0.16514867741462683')
28
- })
29
- it('座標角度計算 (#875)', async () => {
30
- await cmp('[10,10]の座標角度計算して表示', '45')
31
- await cmp('[0,10]の座標角度計算して表示', '90')
32
- await cmp('[10,0]の座標角度計算して表示', '0')
33
- })
34
- })
@@ -1,18 +0,0 @@
1
- import assert from 'assert'
2
- import { NakoCompiler } from '../src/nako3.mjs'
3
-
4
- // eslint-disable-next-line no-undef
5
- describe('plugin_promise_test', async () => {
6
- const cmp = async (/** @type {string} */ code, /** @type {string} */ res) => {
7
- const nako = new NakoCompiler()
8
- nako.logger.debug('code=' + code)
9
- const g = await nako.runAsync(code)
10
- assert.strictEqual(g.log, res)
11
- }
12
- // --- test ---
13
- // eslint-disable-next-line no-undef
14
- it('Promise', async () => {
15
- await cmp('動いた時には(成功,失敗)\n成功(9)\nここまで\nFはそれ\nFの成功した時には\n対象を表示\nここまで\nその失敗した時には\n"NG"を表示\nここまで', '9')
16
- await cmp('動いた時には(成功,失敗)\n失敗(5)\nここまで\nFはそれ\nFの成功した時には\n"NG"を表示\nここまで\nFの失敗した時には\n対象を表示\nここまで', '5')
17
- })
18
- })