rapydscript-ns 0.8.2 → 0.8.4

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 (141) hide show
  1. package/.agignore +1 -1
  2. package/.github/workflows/ci.yml +38 -38
  3. package/=template.pyj +5 -5
  4. package/CHANGELOG.md +39 -0
  5. package/HACKING.md +103 -103
  6. package/LICENSE +24 -24
  7. package/PYTHON_DIFFERENCES_REPORT.md +291 -0
  8. package/PYTHON_FEATURE_COVERAGE.md +106 -15
  9. package/README.md +831 -52
  10. package/TODO.md +4 -286
  11. package/add-toc-to-readme +2 -2
  12. package/bin/export +75 -75
  13. package/bin/rapydscript +70 -70
  14. package/bin/web-repl-export +102 -102
  15. package/build +2 -2
  16. package/language-service/index.js +4623 -0
  17. package/language-service/language-service.d.ts +40 -0
  18. package/package.json +9 -7
  19. package/publish.py +37 -37
  20. package/release/baselib-plain-pretty.js +2006 -229
  21. package/release/baselib-plain-ugly.js +70 -3
  22. package/release/compiler.js +11554 -3870
  23. package/release/signatures.json +31 -29
  24. package/session.vim +4 -4
  25. package/setup.cfg +2 -2
  26. package/src/ast.pyj +93 -1
  27. package/src/baselib-builtins.pyj +99 -2
  28. package/src/baselib-containers.pyj +107 -4
  29. package/src/baselib-errors.pyj +44 -0
  30. package/src/baselib-internal.pyj +124 -5
  31. package/src/baselib-itertools.pyj +97 -97
  32. package/src/baselib-str.pyj +32 -1
  33. package/src/compiler.pyj +36 -36
  34. package/src/errors.pyj +30 -30
  35. package/src/lib/aes.pyj +646 -646
  36. package/src/lib/collections.pyj +1 -1
  37. package/src/lib/copy.pyj +120 -0
  38. package/src/lib/elementmaker.pyj +83 -83
  39. package/src/lib/encodings.pyj +126 -126
  40. package/src/lib/gettext.pyj +569 -569
  41. package/src/lib/itertools.pyj +580 -580
  42. package/src/lib/math.pyj +193 -193
  43. package/src/lib/numpy.pyj +10 -10
  44. package/src/lib/operator.pyj +11 -11
  45. package/src/lib/pythonize.pyj +20 -20
  46. package/src/lib/random.pyj +118 -118
  47. package/src/lib/re.pyj +470 -470
  48. package/src/lib/react.pyj +74 -0
  49. package/src/lib/traceback.pyj +63 -63
  50. package/src/lib/uuid.pyj +77 -77
  51. package/src/monaco-language-service/analyzer.js +131 -9
  52. package/src/monaco-language-service/builtins.js +17 -2
  53. package/src/monaco-language-service/completions.js +170 -1
  54. package/src/monaco-language-service/diagnostics.js +25 -3
  55. package/src/monaco-language-service/dts.js +550 -550
  56. package/src/monaco-language-service/index.js +17 -0
  57. package/src/monaco-language-service/scope.js +3 -0
  58. package/src/output/classes.pyj +128 -11
  59. package/src/output/codegen.pyj +17 -3
  60. package/src/output/comments.pyj +45 -45
  61. package/src/output/exceptions.pyj +201 -105
  62. package/src/output/functions.pyj +13 -16
  63. package/src/output/jsx.pyj +164 -0
  64. package/src/output/literals.pyj +28 -2
  65. package/src/output/loops.pyj +0 -9
  66. package/src/output/modules.pyj +2 -5
  67. package/src/output/operators.pyj +22 -2
  68. package/src/output/statements.pyj +2 -2
  69. package/src/output/stream.pyj +1 -13
  70. package/src/output/treeshake.pyj +182 -182
  71. package/src/output/utils.pyj +72 -72
  72. package/src/parse.pyj +434 -114
  73. package/src/string_interpolation.pyj +72 -72
  74. package/src/tokenizer.pyj +29 -0
  75. package/src/unicode_aliases.pyj +576 -576
  76. package/src/utils.pyj +192 -192
  77. package/test/_import_one.pyj +37 -37
  78. package/test/_import_two/__init__.pyj +11 -11
  79. package/test/_import_two/level2/deep.pyj +4 -4
  80. package/test/_import_two/other.pyj +6 -6
  81. package/test/_import_two/sub.pyj +13 -13
  82. package/test/aes_vectors.pyj +421 -421
  83. package/test/annotations.pyj +80 -80
  84. package/test/baselib.pyj +4 -4
  85. package/test/classes.pyj +56 -17
  86. package/test/collections.pyj +5 -5
  87. package/test/decorators.pyj +77 -77
  88. package/test/docstrings.pyj +39 -39
  89. package/test/elementmaker_test.pyj +45 -45
  90. package/test/functions.pyj +151 -151
  91. package/test/generators.pyj +41 -41
  92. package/test/generic.pyj +370 -370
  93. package/test/imports.pyj +72 -72
  94. package/test/internationalization.pyj +73 -73
  95. package/test/lint.pyj +164 -164
  96. package/test/loops.pyj +85 -85
  97. package/test/numpy.pyj +734 -734
  98. package/test/omit_function_metadata.pyj +20 -20
  99. package/test/python_compat.pyj +326 -0
  100. package/test/python_features.pyj +129 -29
  101. package/test/regexp.pyj +55 -55
  102. package/test/repl.pyj +121 -121
  103. package/test/scoped_flags.pyj +76 -76
  104. package/test/slice.pyj +105 -0
  105. package/test/str.pyj +25 -0
  106. package/test/unit/fixtures/fibonacci_expected.js +1 -1
  107. package/test/unit/index.js +2296 -71
  108. package/test/unit/language-service-builtins.js +70 -0
  109. package/test/unit/language-service-bundle.js +5 -5
  110. package/test/unit/language-service-completions.js +180 -0
  111. package/test/unit/language-service-dts.js +543 -543
  112. package/test/unit/language-service-hover.js +455 -455
  113. package/test/unit/language-service-index.js +350 -0
  114. package/test/unit/language-service-scope.js +255 -0
  115. package/test/unit/language-service.js +625 -4
  116. package/test/unit/run-language-service.js +1 -0
  117. package/test/unit/web-repl.js +437 -0
  118. package/tools/build-language-service.js +2 -2
  119. package/tools/cli.js +547 -547
  120. package/tools/compile.js +219 -219
  121. package/tools/compiler.js +0 -24
  122. package/tools/completer.js +131 -131
  123. package/tools/embedded_compiler.js +251 -251
  124. package/tools/export.js +3 -37
  125. package/tools/gettext.js +185 -185
  126. package/tools/ini.js +65 -65
  127. package/tools/msgfmt.js +187 -187
  128. package/tools/repl.js +223 -223
  129. package/tools/test.js +118 -118
  130. package/tools/utils.js +128 -128
  131. package/tools/web_repl.js +95 -95
  132. package/try +41 -41
  133. package/web-repl/env.js +196 -74
  134. package/web-repl/index.html +163 -163
  135. package/web-repl/main.js +252 -254
  136. package/web-repl/prism.css +139 -139
  137. package/web-repl/prism.js +113 -113
  138. package/web-repl/rapydscript.js +227 -139
  139. package/web-repl/sha1.js +25 -25
  140. package/hack_demo.pyj +0 -112
  141. package/web-repl/language-service.js +0 -4187
package/test/regexp.pyj CHANGED
@@ -1,55 +1,55 @@
1
- # vim:fileencoding=utf-8
2
- # License: BSD
3
- # Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
4
-
5
- # Test the re module
6
- import re
7
- s = "Isaac Newton, physicist"
8
- c = re.search("(\\w+) (\\w+)", s)
9
- assrt.equal(c.group(1), 'Isaac')
10
- assrt.equal(c.group(2), 'Newton')
11
- c = re.match("(\\w+) (\\w+)", s)
12
- assrt.equal(c.group(1), 'Isaac')
13
- assrt.equal(c.start(1), 0)
14
- assrt.equal(c.end(1), c.group(1).length)
15
- assrt.equal(c.start(2), c.group(1).length + 1)
16
- assrt.equal(c.group(2), 'Newton')
17
- m = re.search('a(b)cd', 'abc abcd')
18
- assrt.equal(m.group(1), 'b')
19
- assrt.equal(m.start(1), m.string.lastIndexOf('b'))
20
- assrt.deepEqual(re.split('\\s', s), ['Isaac', 'Newton,', 'physicist'])
21
- assrt.deepEqual(re.findall('s[a-z]', s), ['sa', 'si', 'st'])
22
- assrt.deepEqual([m.group() for m in re.finditer('s[a-z]', s)], ['sa', 'si', 'st'])
23
- assrt.deepEqual(re.findall(/s[a-z]/, s), ['sa', 'si', 'st'])
24
- assrt.equal(re.sub('[A-Z]', '_', s), '_saac _ewton, physicist')
25
- assrt.equal(re.sub('[A-Z]', '_', s, count=1), '_saac Newton, physicist')
26
- assrt.equal(re.search('a[.]b', 'axb'), None)
27
- assrt.equal(re.search(r'a\.b', 'axb'), None)
28
- assrt.equal(re.search('a[.]b', 'axb', flags=re.D), None)
29
- assrt.equal(re.search('.+', 'a\nb').group(), 'a')
30
- assrt.equal(re.search('.+', 'a\nb', flags=re.D).group(), 'a\nb')
31
- assrt.equal(re.search('(?s).+', 'a\nb').group(), 'a\nb')
32
- assrt.equal(re.sub('a(b)', r'xx', 'ab'), r'xx')
33
- assrt.equal(re.sub('a(b)', r'\\1', 'ab'), r'\1')
34
- assrt.equal(re.sub('a(b)', r'\\\1', 'ab'), r'\b')
35
- assrt.equal(re.sub('a(b)', r'\g<1>', 'ab'), r'b')
36
- assrt.equal(re.sub('a(b)', def(m):return m.group(1);, 'ab'), r'b')
37
- assrt.equal(']', re.match('[]]', ']').group())
38
-
39
- assrt.throws(def():re.search(r'(?(1)a|b)b', 'ab');, re.error)
40
-
41
- # Test lookbehind assertions
42
- assrt.equal('acdb', re.sub(r'(?<=a)b', 'c', 'abdb'))
43
-
44
- # Test named groups
45
- assrt.equal('aa', re.sub(r'(?P<a>a)b', r'\g<a>\1', 'ab'))
46
- assrt.equal('bb', re.sub(r'(?P<a>a)(?P=a)', r'bb', 'aa'))
47
- assrt.equal('ab', re.sub(r'(.)(?P<a>a)', r'\g<a>\1', 'ba'))
48
- assrt.deepEqual({'a':'a', 'b':'b'}, re.search(r'(?P<a>a)(?P<b>b)', 'ab').groupdict())
49
-
50
- # Test verbose mode literals
51
- assrt.equal(re.search(///
52
- a
53
- . # anything
54
- b
55
- ///, ' axb').group(), 'axb')
1
+ # vim:fileencoding=utf-8
2
+ # License: BSD
3
+ # Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
4
+
5
+ # Test the re module
6
+ import re
7
+ s = "Isaac Newton, physicist"
8
+ c = re.search("(\\w+) (\\w+)", s)
9
+ assrt.equal(c.group(1), 'Isaac')
10
+ assrt.equal(c.group(2), 'Newton')
11
+ c = re.match("(\\w+) (\\w+)", s)
12
+ assrt.equal(c.group(1), 'Isaac')
13
+ assrt.equal(c.start(1), 0)
14
+ assrt.equal(c.end(1), c.group(1).length)
15
+ assrt.equal(c.start(2), c.group(1).length + 1)
16
+ assrt.equal(c.group(2), 'Newton')
17
+ m = re.search('a(b)cd', 'abc abcd')
18
+ assrt.equal(m.group(1), 'b')
19
+ assrt.equal(m.start(1), m.string.lastIndexOf('b'))
20
+ assrt.deepEqual(re.split('\\s', s), ['Isaac', 'Newton,', 'physicist'])
21
+ assrt.deepEqual(re.findall('s[a-z]', s), ['sa', 'si', 'st'])
22
+ assrt.deepEqual([m.group() for m in re.finditer('s[a-z]', s)], ['sa', 'si', 'st'])
23
+ assrt.deepEqual(re.findall(/s[a-z]/, s), ['sa', 'si', 'st'])
24
+ assrt.equal(re.sub('[A-Z]', '_', s), '_saac _ewton, physicist')
25
+ assrt.equal(re.sub('[A-Z]', '_', s, count=1), '_saac Newton, physicist')
26
+ assrt.equal(re.search('a[.]b', 'axb'), None)
27
+ assrt.equal(re.search(r'a\.b', 'axb'), None)
28
+ assrt.equal(re.search('a[.]b', 'axb', flags=re.D), None)
29
+ assrt.equal(re.search('.+', 'a\nb').group(), 'a')
30
+ assrt.equal(re.search('.+', 'a\nb', flags=re.D).group(), 'a\nb')
31
+ assrt.equal(re.search('(?s).+', 'a\nb').group(), 'a\nb')
32
+ assrt.equal(re.sub('a(b)', r'xx', 'ab'), r'xx')
33
+ assrt.equal(re.sub('a(b)', r'\\1', 'ab'), r'\1')
34
+ assrt.equal(re.sub('a(b)', r'\\\1', 'ab'), r'\b')
35
+ assrt.equal(re.sub('a(b)', r'\g<1>', 'ab'), r'b')
36
+ assrt.equal(re.sub('a(b)', def(m):return m.group(1);, 'ab'), r'b')
37
+ assrt.equal(']', re.match('[]]', ']').group())
38
+
39
+ assrt.throws(def():re.search(r'(?(1)a|b)b', 'ab');, re.error)
40
+
41
+ # Test lookbehind assertions
42
+ assrt.equal('acdb', re.sub(r'(?<=a)b', 'c', 'abdb'))
43
+
44
+ # Test named groups
45
+ assrt.equal('aa', re.sub(r'(?P<a>a)b', r'\g<a>\1', 'ab'))
46
+ assrt.equal('bb', re.sub(r'(?P<a>a)(?P=a)', r'bb', 'aa'))
47
+ assrt.equal('ab', re.sub(r'(.)(?P<a>a)', r'\g<a>\1', 'ba'))
48
+ assrt.deepEqual({'a':'a', 'b':'b'}, re.search(r'(?P<a>a)(?P<b>b)', 'ab').groupdict())
49
+
50
+ # Test verbose mode literals
51
+ assrt.equal(re.search(///
52
+ a
53
+ . # anything
54
+ b
55
+ ///, ' axb').group(), 'axb')
package/test/repl.pyj CHANGED
@@ -1,121 +1,121 @@
1
- # globals: compiler_dir
2
- stdout = []
3
- def clear():
4
- stdout.length = 0
5
-
6
- class FakeConsole:
7
-
8
- def log(self):
9
- Array.prototype.slice.call(arguments).forEach(def (arg):
10
- stdout.push((arg or '').toString())
11
- )
12
- stdout.push('\n')
13
-
14
- def error(self):
15
- Array.prototype.slice.call(arguments).forEach(def (arg):
16
- stdout.push((arg or '').toString())
17
- )
18
- stdout.push('\n')
19
-
20
- class FakeReadline:
21
-
22
- def __init__(self):
23
- self.listeners = {}
24
- self._prompt = ''
25
-
26
- def setPrompt(self, prompt):
27
- self._prompt = prompt
28
-
29
- def write(self, data):
30
- stdout.push(data)
31
-
32
- def clearLine(self):
33
- pass
34
-
35
- def on(self, event, callback):
36
- self.listeners[event] = callback
37
- return self
38
-
39
- def prompt(self):
40
- stdout.push(self._prompt)
41
-
42
- def send_line(self, text):
43
- self.listeners['line'](text)
44
-
45
- repl = require('./repl')
46
- rl = FakeReadline()
47
-
48
- send_line = rl.send_line.bind(rl)
49
-
50
- def send_text(text):
51
- for line in text.split('\n'):
52
- send_line(line)
53
-
54
- def check(text, output):
55
- send_text(text)
56
- eq(output, stdout[0])
57
- clear()
58
-
59
- def check_in(text, output):
60
- send_text(text)
61
- assrt.ok(output in stdout, output + ' not in ' + stdout)
62
- clear()
63
-
64
- def check_not_in(text, output):
65
- send_text(text)
66
- assrt.ok(output not in stdout)
67
- clear()
68
-
69
- readline = {
70
- 'createInterface': def(options):
71
- rl.completer = options.completer
72
- return rl
73
- }
74
- repl({'lib_path':compiler_dir, 'console':FakeConsole(), 'readline':readline, 'terminal':False, 'show_js':False, 'histfile':False})
75
- eq = assrt.equal
76
- eq('>>> ', stdout[-1])
77
- clear()
78
- check('1', '1')
79
- check_in('if 1:\n 2\n \n ', '2')
80
- check_not_in('if 1:\n 2\n ', '2')
81
- check_in('1 +\n1\n\n', '2')
82
- check('max(1, 2)', '2')
83
- send_text(
84
- '''
85
- class A:
86
-
87
- def __init__(self, a):
88
- self. a = a
89
-
90
-
91
- ''')
92
- clear()
93
- check_in('b = A(1)\nb.a', '1')
94
- check_in('c = A(2)\nc.a', '2')
95
- send_text('from __python__ import dict_literals\nd={1:1}')
96
- check_in('isinstance(d, dict)', 'true')
97
- send_text('from __python__ import no_dict_literals\nd={1:1}')
98
- check_in('isinstance(d, dict)', 'false')
99
- # Test completions
100
- def completions(line):
101
- return rl.completer(line)[0]
102
-
103
- def check_completions():
104
- items = completions(arguments[0])
105
- for x in Array.prototype.slice.call(arguments, 1):
106
- assrt.ok(items and x in items, x + ' not in completions for: ' + arguments[0])
107
-
108
- check_completions('', 'return', 'A')
109
- check_completions('Array.', 'isArray', 'apply')
110
- send_text('x = ""\ny = []'), clear()
111
- check_completions('x.', 'substr', 'trim')
112
- check_completions('y.', 'concat', 'push')
113
- check_completions('x.sl', 'slice')
114
- send_text('y = {"x":1}'), clear()
115
- check_completions('y.', 'x')
116
-
117
- # Test docstrings
118
- clear()
119
- send_text('def ds():\n "xxx"\n\n')
120
- clear()
121
- check('ds.__doc__', "'xxx'")
1
+ # globals: compiler_dir
2
+ stdout = []
3
+ def clear():
4
+ stdout.length = 0
5
+
6
+ class FakeConsole:
7
+
8
+ def log(self):
9
+ Array.prototype.slice.call(arguments).forEach(def (arg):
10
+ stdout.push((arg or '').toString())
11
+ )
12
+ stdout.push('\n')
13
+
14
+ def error(self):
15
+ Array.prototype.slice.call(arguments).forEach(def (arg):
16
+ stdout.push((arg or '').toString())
17
+ )
18
+ stdout.push('\n')
19
+
20
+ class FakeReadline:
21
+
22
+ def __init__(self):
23
+ self.listeners = {}
24
+ self._prompt = ''
25
+
26
+ def setPrompt(self, prompt):
27
+ self._prompt = prompt
28
+
29
+ def write(self, data):
30
+ stdout.push(data)
31
+
32
+ def clearLine(self):
33
+ pass
34
+
35
+ def on(self, event, callback):
36
+ self.listeners[event] = callback
37
+ return self
38
+
39
+ def prompt(self):
40
+ stdout.push(self._prompt)
41
+
42
+ def send_line(self, text):
43
+ self.listeners['line'](text)
44
+
45
+ repl = require('./repl')
46
+ rl = FakeReadline()
47
+
48
+ send_line = rl.send_line.bind(rl)
49
+
50
+ def send_text(text):
51
+ for line in text.split('\n'):
52
+ send_line(line)
53
+
54
+ def check(text, output):
55
+ send_text(text)
56
+ eq(output, stdout[0])
57
+ clear()
58
+
59
+ def check_in(text, output):
60
+ send_text(text)
61
+ assrt.ok(output in stdout, output + ' not in ' + stdout)
62
+ clear()
63
+
64
+ def check_not_in(text, output):
65
+ send_text(text)
66
+ assrt.ok(output not in stdout)
67
+ clear()
68
+
69
+ readline = {
70
+ 'createInterface': def(options):
71
+ rl.completer = options.completer
72
+ return rl
73
+ }
74
+ repl({'lib_path':compiler_dir, 'console':FakeConsole(), 'readline':readline, 'terminal':False, 'show_js':False, 'histfile':False})
75
+ eq = assrt.equal
76
+ eq('>>> ', stdout[-1])
77
+ clear()
78
+ check('1', '1')
79
+ check_in('if 1:\n 2\n \n ', '2')
80
+ check_not_in('if 1:\n 2\n ', '2')
81
+ check_in('1 +\n1\n\n', '2')
82
+ check('max(1, 2)', '2')
83
+ send_text(
84
+ '''
85
+ class A:
86
+
87
+ def __init__(self, a):
88
+ self. a = a
89
+
90
+
91
+ ''')
92
+ clear()
93
+ check_in('b = A(1)\nb.a', '1')
94
+ check_in('c = A(2)\nc.a', '2')
95
+ send_text('from __python__ import dict_literals\nd={1:1}')
96
+ check_in('isinstance(d, dict)', 'true')
97
+ send_text('from __python__ import no_dict_literals\nd={1:1}')
98
+ check_in('isinstance(d, dict)', 'false')
99
+ # Test completions
100
+ def completions(line):
101
+ return rl.completer(line)[0]
102
+
103
+ def check_completions():
104
+ items = completions(arguments[0])
105
+ for x in Array.prototype.slice.call(arguments, 1):
106
+ assrt.ok(items and x in items, x + ' not in completions for: ' + arguments[0])
107
+
108
+ check_completions('', 'return', 'A')
109
+ check_completions('Array.', 'isArray', 'apply')
110
+ send_text('x = ""\ny = []'), clear()
111
+ check_completions('x.', 'substr', 'trim')
112
+ check_completions('y.', 'concat', 'push')
113
+ check_completions('x.sl', 'slice')
114
+ send_text('y = {"x":1}'), clear()
115
+ check_completions('y.', 'x')
116
+
117
+ # Test docstrings
118
+ clear()
119
+ send_text('def ds():\n "xxx"\n\n')
120
+ clear()
121
+ check('ds.__doc__', "'xxx'")
@@ -1,76 +1,76 @@
1
- # vim:fileencoding=utf-8
2
- # License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
3
-
4
- a = {1:1}
5
- assrt.ok(not isinstance(a, dict))
6
-
7
- from __python__ import dict_literals, overload_getitem
8
- a = {1:1}
9
- assrt.ok(isinstance(a, dict))
10
- assrt.equal(a[1], 1)
11
- a[2] = 2
12
- assrt.equal(a[2], 2)
13
- a[2] += 4
14
- assrt.equal(a[2], 6)
15
- assrt.deepEqual(list(a.keys()), [1, 2])
16
- from __python__ import no_dict_literals, no_overload_getitem
17
-
18
-
19
- a = {1:1}
20
- assrt.ok(not isinstance(a, dict))
21
-
22
- def f():
23
- from __python__ import dict_literals
24
- a = {1:1}
25
- assrt.ok(isinstance(a, dict))
26
-
27
- a = {1:1}
28
- assrt.ok(not isinstance(a, dict))
29
-
30
- class S:
31
- from __python__ import bound_methods
32
-
33
- def __init__(self):
34
- self.a = 3
35
-
36
- def val(self):
37
- return self.a if self else None
38
-
39
- f = S().val
40
- assrt.equal(f(), S().val())
41
-
42
- class U:
43
-
44
- def __init__(self):
45
- self.a = 3
46
-
47
- def val(self):
48
- return self.a if self else None
49
-
50
- f = U().val
51
- assrt.equal(f(), None)
52
-
53
- class C:
54
-
55
- def __init__(self):
56
- self.a = 3
57
-
58
- def uval1(self):
59
- return self.a if self else None
60
-
61
- from __python__ import bound_methods
62
-
63
- def bval(self):
64
- return self.a
65
-
66
- from __python__ import no_bound_methods
67
-
68
- def uval2(self):
69
- return self.a if self else None
70
-
71
- c = C()
72
- u1, u2 = c.uval1, c.uval2
73
- f = c.bval
74
- assrt.equal(u1(), None)
75
- assrt.equal(u2(), None)
76
- assrt.equal(f(), 3)
1
+ # vim:fileencoding=utf-8
2
+ # License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
3
+
4
+ a = {1:1}
5
+ assrt.ok(not isinstance(a, dict))
6
+
7
+ from __python__ import dict_literals, overload_getitem
8
+ a = {1:1}
9
+ assrt.ok(isinstance(a, dict))
10
+ assrt.equal(a[1], 1)
11
+ a[2] = 2
12
+ assrt.equal(a[2], 2)
13
+ a[2] += 4
14
+ assrt.equal(a[2], 6)
15
+ assrt.deepEqual(list(a.keys()), [1, 2])
16
+ from __python__ import no_dict_literals, no_overload_getitem
17
+
18
+
19
+ a = {1:1}
20
+ assrt.ok(not isinstance(a, dict))
21
+
22
+ def f():
23
+ from __python__ import dict_literals
24
+ a = {1:1}
25
+ assrt.ok(isinstance(a, dict))
26
+
27
+ a = {1:1}
28
+ assrt.ok(not isinstance(a, dict))
29
+
30
+ class S:
31
+ from __python__ import bound_methods
32
+
33
+ def __init__(self):
34
+ self.a = 3
35
+
36
+ def val(self):
37
+ return self.a if self else None
38
+
39
+ f = S().val
40
+ assrt.equal(f(), S().val())
41
+
42
+ class U:
43
+
44
+ def __init__(self):
45
+ self.a = 3
46
+
47
+ def val(self):
48
+ return self.a if self else None
49
+
50
+ f = U().val
51
+ assrt.equal(f(), None)
52
+
53
+ class C:
54
+
55
+ def __init__(self):
56
+ self.a = 3
57
+
58
+ def uval1(self):
59
+ return self.a if self else None
60
+
61
+ from __python__ import bound_methods
62
+
63
+ def bval(self):
64
+ return self.a
65
+
66
+ from __python__ import no_bound_methods
67
+
68
+ def uval2(self):
69
+ return self.a if self else None
70
+
71
+ c = C()
72
+ u1, u2 = c.uval1, c.uval2
73
+ f = c.bval
74
+ assrt.equal(u1(), None)
75
+ assrt.equal(u2(), None)
76
+ assrt.equal(f(), 3)
package/test/slice.pyj ADDED
@@ -0,0 +1,105 @@
1
+ # globals: assrt
2
+ # vim:fileencoding=utf-8
3
+ #
4
+ # slice.pyj — tests for the slice() builtin class.
5
+ # Subscript read/write via a slice object (lst[s], lst[s]=val) requires
6
+ # overload_getitem so that the compiler routes [] through ρσ_getitem.
7
+
8
+ from __python__ import overload_getitem
9
+
10
+ ae = assrt.equal
11
+ ade = assrt.deepEqual
12
+ ok = assrt.ok
13
+
14
+ # ── Construction forms ────────────────────────────────────────────────────────
15
+
16
+ s1 = slice(5)
17
+ ae(s1.start, None)
18
+ ae(s1.stop, 5)
19
+ ae(s1.step, None)
20
+
21
+ s2 = slice(2, 8)
22
+ ae(s2.start, 2)
23
+ ae(s2.stop, 8)
24
+ ae(s2.step, None)
25
+
26
+ s3 = slice(1, 9, 2)
27
+ ae(s3.start, 1)
28
+ ae(s3.stop, 9)
29
+ ae(s3.step, 2)
30
+
31
+ # None values preserved
32
+ sn = slice(None, None, -1)
33
+ ae(sn.start, None)
34
+ ae(sn.stop, None)
35
+ ae(sn.step, -1)
36
+
37
+ # ── indices() ─────────────────────────────────────────────────────────────────
38
+
39
+ ade(s2.indices(10), [2, 8, 1])
40
+ ade(slice(None, None, 1).indices(5), [0, 5, 1])
41
+ ade(slice(-3, -1).indices(10), [7, 9, 1])
42
+ ade(slice(None, None, -1).indices(5), [4, -1, -1])
43
+ ade(slice(0, 100).indices(10), [0, 10, 1]) # stop clamped to length
44
+ ade(slice(-100, 5).indices(10), [0, 5, 1]) # start clamped to 0
45
+
46
+ # ── repr / str ────────────────────────────────────────────────────────────────
47
+
48
+ ae(str(slice(1, 5, None)), 'slice(1, 5, None)')
49
+ ae(str(slice(None, 5, 2)), 'slice(None, 5, 2)')
50
+ ae(str(slice(None, None, None)), 'slice(None, None, None)')
51
+
52
+ # ── Equality ──────────────────────────────────────────────────────────────────
53
+
54
+ ok(slice(1, 5) == slice(1, 5))
55
+ ok(not (slice(1, 5) == slice(1, 6)))
56
+ ok(not (slice(1, 5) == slice(0, 5)))
57
+ ok(slice(1, 5, 2) == slice(1, 5, 2))
58
+ ok(not (slice(1, 5, 2) == slice(1, 5, 3)))
59
+
60
+ # ── isinstance ────────────────────────────────────────────────────────────────
61
+
62
+ ok(isinstance(slice(1, 5), slice))
63
+ ok(not isinstance(42, slice))
64
+ ok(not isinstance([1, 2, 3], slice))
65
+
66
+ # ── List subscript read ───────────────────────────────────────────────────────
67
+
68
+ lst = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
69
+
70
+ ade(lst[slice(2, 5)], [2, 3, 4])
71
+ ade(lst[slice(0, 6, 2)], [0, 2, 4])
72
+ ade(lst[slice(None, 4)], [0, 1, 2, 3])
73
+ ade(lst[slice(None)], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
74
+
75
+ # Negative step
76
+ ade(lst[slice(5, 1, -1)], [5, 4, 3, 2])
77
+ ade(lst[slice(None, None, -1)], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0])
78
+ ade(lst[slice(9, 0, -2)], [9, 7, 5, 3, 1])
79
+
80
+ # ── String subscript read ─────────────────────────────────────────────────────
81
+
82
+ s = 'hello'
83
+ ae(s[slice(1, 4)], 'ell')
84
+ ae(s[slice(None, None, -1)], 'olleh')
85
+ ae(s[slice(0, 5, 2)], 'hlo')
86
+
87
+ # ── List subscript write ──────────────────────────────────────────────────────
88
+
89
+ a = [0, 1, 2, 3, 4]
90
+ a[slice(1, 3)] = [10, 20]
91
+ ade(a, [0, 10, 20, 3, 4])
92
+
93
+ b = [0, 1, 2, 3, 4]
94
+ b[slice(0, 2)] = [99]
95
+ ade(b, [99, 2, 3, 4])
96
+
97
+ # ── List subscript delete ─────────────────────────────────────────────────────
98
+
99
+ c = [0, 1, 2, 3, 4]
100
+ del c[slice(1, 3)]
101
+ ade(c, [0, 3, 4])
102
+
103
+ d = [0, 1, 2, 3, 4]
104
+ del d[slice(0, 1)]
105
+ ade(d, [1, 2, 3, 4])
package/test/str.pyj CHANGED
@@ -98,6 +98,31 @@ test_throws(IndexError, '{1} {2}', 1)
98
98
  test_throws(ValueError, '{1')
99
99
  test_interpolation()
100
100
 
101
+ # Test format() builtin
102
+ ae('3.14', format(3.14159, '.2f'))
103
+ ae(' 42', format(42, '>4d'))
104
+ ae('42 ', format(42, '<4d'))
105
+ ae(' 42 ', format(42, '^4d'))
106
+ ae('0042', format(42, '04d'))
107
+ ae('2a', format(42, 'x'))
108
+ ae('0b101010', format(42, '#b'))
109
+ ae('hello', format('hello'))
110
+ ae('42', format(42))
111
+ ae('None', format(None))
112
+ ae('hello ', format('hello', '<10'))
113
+ ae(' hello', format('hello', '>10'))
114
+ ae(' hello ', format('hello', '^10'))
115
+ ae('1.23e+2', format(123.456, '.2e').toLowerCase())
116
+ ae('hello', format('hello world', '.5'))
117
+
118
+ class FormattableNum:
119
+ def __init__(self, n):
120
+ self.n = n
121
+ def __format__(self, spec):
122
+ return 'FN:' + format(self.n, spec)
123
+
124
+ ae('FN:042', format(FormattableNum(42), '03d'))
125
+
101
126
  # Test miscellaneous services
102
127
  ae('Abc', str.capitalize('aBC'))
103
128
  ae(' 1 ', str.center('1', 3))
@@ -30,7 +30,7 @@ var fib = memoize((function() {
30
30
  } else if ((n === 1 || typeof n === "object" && ρσ_equals(n, 1))) {
31
31
  return 1;
32
32
  } else {
33
- return fib(n - 1) + fib(n - 2);
33
+ return ρσ_list_add(fib(n - 1), fib(n - 2));
34
34
  }
35
35
  };
36
36
  if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {