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
@@ -1,80 +1,80 @@
1
- def add(a: int, b: float):
2
- return a + b
3
-
4
- assrt.ok(add.__annotations__)
5
- assrt.equal(add.__annotations__['a'], int)
6
- assrt.equal(add.__annotations__['b'], float)
7
- assrt.equal(add.__annotations__['return'], undefined)
8
-
9
- def sum(ls: list) -> int:
10
- pass
11
-
12
- assrt.ok(not (sum.__annotations__ == undefined))
13
- assrt.deepEqual(sum.__annotations__, {
14
- 'ls': list,
15
- 'return': int
16
- })
17
-
18
- def optional(a:int=10):
19
- return a
20
-
21
- assrt.ok(not (optional.__annotations__ == undefined))
22
- assrt.equal(optional.__annotations__.a, int)
23
- assrt.equal(optional.__defaults__.a, 10)
24
-
25
- def otherexpr(a:3+4) -> [1, 2]:
26
- pass
27
-
28
- assrt.ok(not (otherexpr.__annotations__ == undefined))
29
- assrt.equal(otherexpr.__annotations__['a'], 7)
30
- assrt.deepEqual(otherexpr.__annotations__['return'], [1, 2])
31
-
32
- def basic(x:float):
33
- pass
34
-
35
- assrt.deepEqual(basic.__annotations__, {
36
- 'x': float
37
- })
38
-
39
- def kwstarargs(*args:list, **kwargs:dict) -> int:
40
- pass
41
-
42
- assrt.equal(kwstarargs.__annotations__['return'], int)
43
-
44
- def nothing():
45
- pass
46
-
47
- assrt.ok(nothing.__annotations__ == undefined)
48
- assrt.throws(def():
49
- nothing.__annotations__['return']
50
- )
51
-
52
- test = def(x: int):
53
- pass
54
-
55
- assrt.deepEqual(test.__annotations__, {
56
- 'x': int
57
- })
58
-
59
- anonreturn = def() -> 'test':
60
- pass
61
-
62
- assrt.equal(anonreturn.__annotations__['return'], 'test')
63
-
64
- assrt.equal(def asexpr(a: int):
65
- a
66
- .__annotations__['a'], int)
67
-
68
- assrt.deepEqual(def(a: int) -> float:
69
- a + 10.0
70
- .__annotations__, {
71
- 'a': int,
72
- 'return': float
73
- })
74
-
75
- class A:
76
-
77
- def f(self, a : int, b: 'x') -> float:
78
- pass
79
-
80
- assrt.deepEqual(A.prototype.f.__annotations__, {'a':int, 'b':'x', 'return': float})
1
+ def add(a: int, b: float):
2
+ return a + b
3
+
4
+ assrt.ok(add.__annotations__)
5
+ assrt.equal(add.__annotations__['a'], int)
6
+ assrt.equal(add.__annotations__['b'], float)
7
+ assrt.equal(add.__annotations__['return'], undefined)
8
+
9
+ def sum(ls: list) -> int:
10
+ pass
11
+
12
+ assrt.ok(not (sum.__annotations__ == undefined))
13
+ assrt.deepEqual(sum.__annotations__, {
14
+ 'ls': list,
15
+ 'return': int
16
+ })
17
+
18
+ def optional(a:int=10):
19
+ return a
20
+
21
+ assrt.ok(not (optional.__annotations__ == undefined))
22
+ assrt.equal(optional.__annotations__.a, int)
23
+ assrt.equal(optional.__defaults__.a, 10)
24
+
25
+ def otherexpr(a:3+4) -> [1, 2]:
26
+ pass
27
+
28
+ assrt.ok(not (otherexpr.__annotations__ == undefined))
29
+ assrt.equal(otherexpr.__annotations__['a'], 7)
30
+ assrt.deepEqual(otherexpr.__annotations__['return'], [1, 2])
31
+
32
+ def basic(x:float):
33
+ pass
34
+
35
+ assrt.deepEqual(basic.__annotations__, {
36
+ 'x': float
37
+ })
38
+
39
+ def kwstarargs(*args:list, **kwargs:dict) -> int:
40
+ pass
41
+
42
+ assrt.equal(kwstarargs.__annotations__['return'], int)
43
+
44
+ def nothing():
45
+ pass
46
+
47
+ assrt.ok(nothing.__annotations__ == undefined)
48
+ assrt.throws(def():
49
+ nothing.__annotations__['return']
50
+ )
51
+
52
+ test = def(x: int):
53
+ pass
54
+
55
+ assrt.deepEqual(test.__annotations__, {
56
+ 'x': int
57
+ })
58
+
59
+ anonreturn = def() -> 'test':
60
+ pass
61
+
62
+ assrt.equal(anonreturn.__annotations__['return'], 'test')
63
+
64
+ assrt.equal(def asexpr(a: int):
65
+ a
66
+ .__annotations__['a'], int)
67
+
68
+ assrt.deepEqual(def(a: int) -> float:
69
+ a + 10.0
70
+ .__annotations__, {
71
+ 'a': int,
72
+ 'return': float
73
+ })
74
+
75
+ class A:
76
+
77
+ def f(self, a : int, b: 'x') -> float:
78
+ pass
79
+
80
+ assrt.deepEqual(A.prototype.f.__annotations__, {'a':int, 'b':'x', 'return': float})
package/test/baselib.pyj CHANGED
@@ -117,8 +117,8 @@ assrt.throws(def():a.index(8);, ValueError)
117
117
  assrt.throws(def():a.index(1, 1);, ValueError)
118
118
  assrt.throws(def():a.index(4, 1, 2);, ValueError)
119
119
  assrt.equal(1, a.index(2, 1, 2))
120
- assrt.throws(def():a.pypop(10);, IndexError)
121
- assrt.equal(a.pypop(-1), 4)
120
+ assrt.throws(def():a.pop(10);, IndexError)
121
+ assrt.equal(a.pop(-1), 4)
122
122
  assrt.deepEqual(a, [1,2,3])
123
123
  assrt.equal(a.remove(2), None)
124
124
  assrt.deepEqual(a, [1, 3])
@@ -141,9 +141,9 @@ assrt.ok(a.as_array().extend == undefined)
141
141
  a = [1, 2, 1]
142
142
  assrt.equal(a.count(1), 2)
143
143
  a = [3, 2, 4, 1]
144
- a.pysort()
144
+ a.sort()
145
145
  assrt.deepEqual(a, [1,2,3,4])
146
- a.pysort(reverse=True)
146
+ a.sort(reverse=True)
147
147
  assrt.deepEqual(a, [4,3,2,1])
148
148
  assrt.deepEqual(a, a.slice())
149
149
  assrt.ok(a is not a.slice())
package/test/classes.pyj CHANGED
@@ -67,7 +67,7 @@ bound = angela.get_bound_method()
67
67
  assrt.equal(bound(), angela.how_long())
68
68
 
69
69
  # function methods
70
- assrt.deepEqual(dir(angela).sort(), [
70
+ assrt.deepEqual(sorted(dir(angela)), [
71
71
  'HAIRS',
72
72
  "__init__",
73
73
  '__repr__',
@@ -137,22 +137,61 @@ inc()
137
137
  assrt.equal(c.count, 6)
138
138
 
139
139
  # nested classes
140
- # not yet fully implemented
141
- #class Molecule:
142
- # class Atom:
143
- # def __init__(self, element):
144
- # self.element = element
145
- #
146
- # def __init__(self, elements):
147
- # self.structure = []
148
- # for e in elements:
149
- # self.structure.push(Molecule.Atom(e))
150
- #
151
- #water = Molecule(['H', "H", 'O'])
152
- #assrt.equal(len(water.structure), 3)
153
- #assrt.equal(water.structure[0].element, 'H')
154
- #for atom in water.structure:
155
- # assrt.ok(isinstance(atom, Molecule.Atom))
140
+ class Molecule:
141
+ class Atom:
142
+ def __init__(self, element):
143
+ self.element = element
144
+ def __repr__(self):
145
+ return 'Atom(' + self.element + ')'
146
+
147
+ def __init__(self, elements):
148
+ self.structure = []
149
+ for e in elements:
150
+ self.structure.push(Molecule.Atom(e))
151
+
152
+ water = Molecule(['H', 'H', 'O'])
153
+ assrt.equal(len(water.structure), 3)
154
+ assrt.equal(water.structure[0].element, 'H')
155
+ assrt.equal(water.structure[2].element, 'O')
156
+ for atom in water.structure:
157
+ assrt.ok(isinstance(atom, Molecule.Atom))
158
+
159
+ # nested class accessible via class reference and via instance attribute
160
+ assrt.ok(Molecule.Atom is water.structure[0].__class__)
161
+ # nested class can also be accessed via instance (self.Inner semantics)
162
+ mol2 = Molecule(['C'])
163
+ assrt.ok(isinstance(mol2.structure[0], mol2.Atom))
164
+
165
+ # two levels of nesting
166
+ class Universe:
167
+ class Galaxy:
168
+ class Star:
169
+ def __init__(self, name):
170
+ self.name = name
171
+ def __init__(self, star_name):
172
+ self.star = Universe.Galaxy.Star(star_name)
173
+ def __init__(self, star_name):
174
+ self.galaxy = Universe.Galaxy(star_name)
175
+
176
+ u = Universe('Sol')
177
+ assrt.equal(u.galaxy.star.name, 'Sol')
178
+ assrt.ok(isinstance(u.galaxy.star, Universe.Galaxy.Star))
179
+
180
+ # nested class with inheritance from outer-scope class
181
+ class Animal:
182
+ def __init__(self, sound):
183
+ self.sound = sound
184
+
185
+ class Zoo:
186
+ class Dog(Animal):
187
+ def __init__(self):
188
+ Animal.__init__(self, 'woof')
189
+
190
+ zoo = Zoo()
191
+ fido = Zoo.Dog()
192
+ assrt.equal(fido.sound, 'woof')
193
+ assrt.ok(isinstance(fido, Animal))
194
+ assrt.ok(isinstance(fido, Zoo.Dog))
156
195
 
157
196
  # starargs and method decorators
158
197
  def negate(fn):
@@ -62,18 +62,18 @@ assrt.equal(s[4:1:-2], 'ec')
62
62
 
63
63
  # sorting
64
64
  a = [2,1,3]
65
- a.pysort(key=def(x):return 0;)
65
+ a.sort(key=def(x):return 0;)
66
66
  assrt.deepEqual(a, [2,1,3]) # stable sort
67
- a.pysort(reverse=True)
67
+ a.sort(reverse=True)
68
68
  assrt.deepEqual(a, [3,2,1])
69
- a.pysort()
69
+ a.sort()
70
70
  assrt.deepEqual(a, [1,2,3])
71
71
 
72
72
  # misc interface
73
73
  a = [1,2,3]
74
- assrt.equal(a.pypop(), 3)
74
+ assrt.equal(a.pop(), 3)
75
75
  assrt.deepEqual(a, [1,2])
76
- assrt.equal(a.pypop(0), 1)
76
+ assrt.equal(a.pop(0), 1)
77
77
  assrt.deepEqual(a, [2])
78
78
 
79
79
  # strings
@@ -1,77 +1,77 @@
1
- # vim:fileencoding=utf-8
2
- # License: BSD Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
3
-
4
- def double(f):
5
- return def (x):
6
- return 2 * f(x)
7
-
8
- def triple(f):
9
- return def(x):
10
- return 3 * f(x)
11
-
12
- @double
13
- def half(x):
14
- return x // 2
15
-
16
- @double
17
- def f1(x):
18
- return x
19
-
20
- @double
21
- @triple
22
- def f2(x):
23
- return x
24
-
25
- def append_one(f):
26
- return def(x):
27
- ans = f(x)
28
- ans.push(1)
29
- return ans
30
-
31
- def append_two(f):
32
- return def(x):
33
- ans = f(x)
34
- ans.push(2)
35
- return ans
36
-
37
- @append_two
38
- @append_one
39
- def f3():
40
- return []
41
-
42
- o = {'double':double}
43
-
44
- @o.double
45
- def f4():
46
- return 1
47
-
48
- assrt.equal(2, half(2))
49
- assrt.equal(4, f1(2))
50
- assrt.equal(12, f2(2))
51
- assrt.equal(2, f4())
52
- assrt.deepEqual([1, 2], f3())
53
-
54
- def multiply(amt):
55
-
56
- def wrapper(f):
57
- return def ():
58
- return amt * f()
59
-
60
- return wrapper
61
-
62
- @multiply(2)
63
- def two():
64
- return 1
65
-
66
- @multiply(3)
67
- def three():
68
- return 1
69
-
70
- @multiply(2)
71
- @multiply(2)
72
- def four():
73
- return 1
74
-
75
- assrt.equal(2, two())
76
- assrt.equal(3, three())
77
- assrt.equal(4, four())
1
+ # vim:fileencoding=utf-8
2
+ # License: BSD Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
3
+
4
+ def double(f):
5
+ return def (x):
6
+ return 2 * f(x)
7
+
8
+ def triple(f):
9
+ return def(x):
10
+ return 3 * f(x)
11
+
12
+ @double
13
+ def half(x):
14
+ return x // 2
15
+
16
+ @double
17
+ def f1(x):
18
+ return x
19
+
20
+ @double
21
+ @triple
22
+ def f2(x):
23
+ return x
24
+
25
+ def append_one(f):
26
+ return def(x):
27
+ ans = f(x)
28
+ ans.push(1)
29
+ return ans
30
+
31
+ def append_two(f):
32
+ return def(x):
33
+ ans = f(x)
34
+ ans.push(2)
35
+ return ans
36
+
37
+ @append_two
38
+ @append_one
39
+ def f3():
40
+ return []
41
+
42
+ o = {'double':double}
43
+
44
+ @o.double
45
+ def f4():
46
+ return 1
47
+
48
+ assrt.equal(2, half(2))
49
+ assrt.equal(4, f1(2))
50
+ assrt.equal(12, f2(2))
51
+ assrt.equal(2, f4())
52
+ assrt.deepEqual([1, 2], f3())
53
+
54
+ def multiply(amt):
55
+
56
+ def wrapper(f):
57
+ return def ():
58
+ return amt * f()
59
+
60
+ return wrapper
61
+
62
+ @multiply(2)
63
+ def two():
64
+ return 1
65
+
66
+ @multiply(3)
67
+ def three():
68
+ return 1
69
+
70
+ @multiply(2)
71
+ @multiply(2)
72
+ def four():
73
+ return 1
74
+
75
+ assrt.equal(2, two())
76
+ assrt.equal(3, three())
77
+ assrt.equal(4, four())
@@ -1,39 +1,39 @@
1
- # vim:fileencoding=utf-8
2
- # License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
3
- # globals: ρσ_module_doc__
4
-
5
- import _import_one
6
-
7
- def f():
8
- " A basic docstring "
9
- pass
10
-
11
- assrt.equal(f.__doc__, 'A basic docstring')
12
- assrt.equal(_import_one.__doc__, 'Module level ds1\n\nModule level ds2\nline2\n\nModule level ds 3')
13
-
14
- def g():
15
- '''
16
- A more complex docstring:
17
- xxx
18
- yyyy
19
-
20
- the end
21
- '''
22
- pass
23
-
24
- assrt.equal(g.__doc__, 'A more complex docstring:\n xxx\n yyyy\n\nthe end')
25
-
26
- class D:
27
- ' Docstring for a class '
28
-
29
- def method(self):
30
- 'ds for a method'
31
- pass
32
-
33
- assrt.equal(D().__doc__, 'Docstring for a class')
34
- assrt.equal(D().method.__doc__, 'ds for a method')
35
-
36
- x = def():
37
- 'xxx'
38
-
39
- assrt.equal(x.__doc__, 'xxx')
1
+ # vim:fileencoding=utf-8
2
+ # License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
3
+ # globals: ρσ_module_doc__
4
+
5
+ import _import_one
6
+
7
+ def f():
8
+ " A basic docstring "
9
+ pass
10
+
11
+ assrt.equal(f.__doc__, 'A basic docstring')
12
+ assrt.equal(_import_one.__doc__, 'Module level ds1\n\nModule level ds2\nline2\n\nModule level ds 3')
13
+
14
+ def g():
15
+ '''
16
+ A more complex docstring:
17
+ xxx
18
+ yyyy
19
+
20
+ the end
21
+ '''
22
+ pass
23
+
24
+ assrt.equal(g.__doc__, 'A more complex docstring:\n xxx\n yyyy\n\nthe end')
25
+
26
+ class D:
27
+ ' Docstring for a class '
28
+
29
+ def method(self):
30
+ 'ds for a method'
31
+ pass
32
+
33
+ assrt.equal(D().__doc__, 'Docstring for a class')
34
+ assrt.equal(D().method.__doc__, 'ds for a method')
35
+
36
+ x = def():
37
+ 'xxx'
38
+
39
+ assrt.equal(x.__doc__, 'xxx')
@@ -1,45 +1,45 @@
1
- # vim:fileencoding=utf-8
2
- # License: BSD Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
3
- # globals: assrt
4
-
5
- from elementmaker import E
6
-
7
- eq = assrt.equal
8
-
9
- def dummy_elem_eq(a, b):
10
- eq(jstype(a), jstype(b))
11
- if (jstype(a) == 'string'):
12
- eq(a, b)
13
- return
14
- eq(a.attributes.length, b.attributes.length)
15
- eq(a.children.length, b.children.length)
16
- eq(a.name, b.name)
17
- for attr in a.attributes:
18
- eq(a[attr], b[attr])
19
- for i, child in enumerate(a.children):
20
- dummy_elem_eq(child, b.children[i])
21
-
22
- q = E.div('text', id='1', class_='c', data_x='x')
23
- dummy_elem_eq(q, {'name':'div', 'children':['text'], 'attributes':{'id':'1', 'class':'c', 'data-x': 'x'}})
24
-
25
- q = E.div(
26
- E.span('a'),
27
- E.span('b'),
28
- E.a(),
29
- id='1',
30
- boolean_attr=True,
31
- )
32
- dummy_elem_eq(q, {'name':'div', 'children':[
33
- {
34
- 'name':'span',
35
- 'children':['a'], 'attributes': {}
36
- },
37
- {
38
- 'name':'span',
39
- 'children':['b'], 'attributes': {}
40
- },
41
- {
42
- 'name':'a',
43
- 'children':[], 'attributes': {}
44
- },
45
- ], 'attributes':{'id':'1', 'boolean-attr':'boolean-attr'}})
1
+ # vim:fileencoding=utf-8
2
+ # License: BSD Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
3
+ # globals: assrt
4
+
5
+ from elementmaker import E
6
+
7
+ eq = assrt.equal
8
+
9
+ def dummy_elem_eq(a, b):
10
+ eq(jstype(a), jstype(b))
11
+ if (jstype(a) == 'string'):
12
+ eq(a, b)
13
+ return
14
+ eq(a.attributes.length, b.attributes.length)
15
+ eq(a.children.length, b.children.length)
16
+ eq(a.name, b.name)
17
+ for attr in a.attributes:
18
+ eq(a[attr], b[attr])
19
+ for i, child in enumerate(a.children):
20
+ dummy_elem_eq(child, b.children[i])
21
+
22
+ q = E.div('text', id='1', class_='c', data_x='x')
23
+ dummy_elem_eq(q, {'name':'div', 'children':['text'], 'attributes':{'id':'1', 'class':'c', 'data-x': 'x'}})
24
+
25
+ q = E.div(
26
+ E.span('a'),
27
+ E.span('b'),
28
+ E.a(),
29
+ id='1',
30
+ boolean_attr=True,
31
+ )
32
+ dummy_elem_eq(q, {'name':'div', 'children':[
33
+ {
34
+ 'name':'span',
35
+ 'children':['a'], 'attributes': {}
36
+ },
37
+ {
38
+ 'name':'span',
39
+ 'children':['b'], 'attributes': {}
40
+ },
41
+ {
42
+ 'name':'a',
43
+ 'children':[], 'attributes': {}
44
+ },
45
+ ], 'attributes':{'id':'1', 'boolean-attr':'boolean-attr'}})