Exemple #1
0
 def test_fibgen(self):
     result, context = self.eval('fibgen.js')
     self.assertEqual(context['fibonacciNumbers'],
                      js.Array([0.0, 1.0, 1.0, 2.0, 3.0,
                                5.0, 8.0, 13.0, 21.0, 34.0,
                                55.0, 89.0, 144.0, 233.0, 377.0,
                                610.0, 987.0, 1597.0, 2584.0, 4181.0,
                                6765.0]))
Exemple #2
0
 def test_array_elision(self):
     self.assertEqual(self.eval('[,]'), js.Array([js.UNDEFINED]))
     self.assertEqual(self.eval('[,,]'), js.Array([js.UNDEFINED, js.UNDEFINED]))
     self.assertEqual(self.eval('[,,,]'), js.Array([js.UNDEFINED, js.UNDEFINED, js.UNDEFINED]))
     self.assertEqual(self.eval('[1, 2,]'), js.Array([1, 2]))
     self.assertEqual(self.eval('[1, 2,,]'), js.Array([1, 2, js.UNDEFINED]))
     self.assertEqual(self.eval('[1,,2]'), js.Array([1, js.UNDEFINED, 2]))
     self.assertEqual(self.eval('[1,,,2]'), js.Array([1, js.UNDEFINED, js.UNDEFINED, 2]))
Exemple #3
0
 def test_object_literal(self):
     result, context = self.eval('object_literal.js')
     self.assertEqual(result, js.Object({'season': js.Object({'episode': js.Array([js.Object({
                                         'available': 'true',
                                         'episodenumber': '402',
                                         'description': '...',
                                         'tags': 'Tooth Fairy|Cartman|T**s|Kyle|Stan',
                                         'url': 'http://www.southparkstudios.com/full-episodes/s04e02-the-tooth-fairy-tats',
                                         'title': 'The Tooth Fairy Tats',
                                         'when': '04.05.2000',
                                         'thumbnail_190': 'http://example.com/episode_thumbnails/s04e02_480.jpg?width=190',
                                         'id': '103570',
                                         'airdate': '04.05.2000',
                                         'thumbnail_larger': 'http://example.com/episode_thumbnails/s04e02_480.jpg?width=63',
                                         'thumbnail': 'http://example.com/episode_thumbnails/s04e02_480.jpg?width=55'})])})}))
Exemple #4
0
 def eval(self, context):
     items = [self.get_item_value(item, context) for item in self.items]
     # Elision: remove last item if it's undefined
     if len(items) > 0 and items[-1] is js.UNDEFINED:
         items.pop()
     return js.Array(items=items)
Exemple #5
0
 def test_array_set_index(self):
     context = js.ExecutionContext({'x': js.Array([9, 10, 'ala ma kota'])})
     self.assertEqual(self.eval('x[2] = 11', context), 11)
     self.assertEqual(context['x'], js.Array([9, 10, 11]))
Exemple #6
0
 def test_empty_array_literal(self):
     self.assertEqual(self.eval('[]'), js.Array([]))
Exemple #7
0
 def test_array_literal(self):
     self.assertEqual(self.eval('[9, 10, "ala ma kota"]'),
                      js.Array([9, 10, 'ala ma kota']))