diff -r 69d1c3ea0d6f -r edbd60e31217 tests/test-highlight.t --- a/tests/test-highlight.t Tue Jun 20 12:51:36 2017 +0100 +++ b/tests/test-highlight.t Tue Jun 20 08:44:56 2017 -0400 @@ -20,8 +20,6 @@ create random Python file to exercise Pygments $ cat < primes.py - > #!/usr/bin/env python - > > """Fun with generators. Corresponding Haskell implementation: > > primes = 2 : sieve [3, 5..] @@ -76,7 +74,7 @@ - test: 06824edf55d0 primes.py + test: 1af356141006 primes.py @@ -114,7 +112,7 @@

- view primes.py @ 0:06824edf55d0 + view primes.py @ 0:1af356141006 tip

@@ -151,39 +149,37 @@
line wrap: on
line source
-  #!/usr/bin/env python
+  """Fun with generators. Corresponding Haskell implementation:
   
-  """Fun with generators. Corresponding Haskell implementation:
-  
-  primes = 2 : sieve [3, 5..]
-      where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0]
-  """
+  primes = 2 : sieve [3, 5..]
+      where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0]
+  """
+  
+  from itertools import dropwhile, ifilter, islice, count, chain
   
-  from itertools import dropwhile, ifilter, islice, count, chain
-  
-  def primes():
-      """Generate all primes."""
-      def sieve(ns):
-          p = ns.next()
-          # It is important to yield *here* in order to stop the
-          # infinite recursion.
-          yield p
-          ns = ifilter(lambda n: n % p != 0, ns)
-          for n in sieve(ns):
-              yield n
-  
-      odds = ifilter(lambda i: i % 2 == 1, count())
-      return chain([2], sieve(dropwhile(lambda n: n < 3, odds)))
-  
-  if __name__ == "__main__":
-      import sys
-      try:
-          n = int(sys.argv[1])
-      except (ValueError, IndexError):
-          n = 10
-      p = primes()
-      print "The first %d primes: %s" % (n, list(islice(p, n)))
-  
+ def primes(): + """Generate all primes.""" + def sieve(ns): + p = ns.next() + # It is important to yield *here* in order to stop the + # infinite recursion. + yield p + ns = ifilter(lambda n: n % p != 0, ns) + for n in sieve(ns): + yield n + + odds = ifilter(lambda i: i % 2 == 1, count()) + return chain([2], sieve(dropwhile(lambda n: n < 3, odds))) + + if __name__ == "__main__": + import sys + try: + n = int(sys.argv[1]) + except (ValueError, IndexError): + n = 10 + p = primes() + print "The first %d primes: %s" % (n, list(islice(p, n))) +
@@ -250,7 +246,7 @@

- annotate primes.py @ 0:06824edf55d0 + annotate primes.py @ 0:1af356141006 tip

@@ -295,36 +291,36 @@ - + 0 - 1 #!/usr/bin/env python + 1 """Fun with generators. Corresponding Haskell implementation: 2 @@ -334,99 +330,99 @@ - 3 """Fun with generators. Corresponding Haskell implementation: + 3 primes = 2 : sieve [3, 5..] - 4 + 4 where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0] - 5 primes = 2 : sieve [3, 5..] + 5 """ - 6 where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0] + 6 - 7 """ + 7 from itertools import dropwhile, ifilter, islice, count, chain 8 @@ -436,425 +432,391 @@ - 9 from itertools import dropwhile, ifilter, islice, count, chain + 9 def primes(): - 10 + 10 """Generate all primes.""" - 11 def primes(): + 11 def sieve(ns): - 12 """Generate all primes.""" + 12 p = ns.next() - 13 def sieve(ns): + 13 # It is important to yield *here* in order to stop the - 14 p = ns.next() + 14 # infinite recursion. - 15 # It is important to yield *here* in order to stop the + 15 yield p - 16 # infinite recursion. + 16 ns = ifilter(lambda n: n % p != 0, ns) - 17 yield p + 17 for n in sieve(ns): - 18 ns = ifilter(lambda n: n % p != 0, ns) + 18 yield n - 19 for n in sieve(ns): + 19 - 20 yield n + 20 odds = ifilter(lambda i: i % 2 == 1, count()) - 21 + 21 return chain([2], sieve(dropwhile(lambda n: n < 3, odds))) - 22 odds = ifilter(lambda i: i % 2 == 1, count()) + 22 - 23 return chain([2], sieve(dropwhile(lambda n: n < 3, odds))) + 23 if __name__ == "__main__": - 24 + 24 import sys - 25 if __name__ == "__main__": + 25 try: - 26 import sys + 26 n = int(sys.argv[1]) - 27 try: + 27 except (ValueError, IndexError): - 28 n = int(sys.argv[1]) + 28 n = 10 - 29 except (ValueError, IndexError): + 29 p = primes() - 30 n = 10 + 30 print "The first %d primes: %s" % (n, list(islice(p, n)))
- - 06824edf55d0 - a -
-
test
-
parents:
- diff - changeset -
- - 31 p = primes() - - - - - - 32 print "The first %d primes: %s" % (n, list(islice(p, n))) - - - - -
-
- - 06824edf55d0 - a -
-
test
-
parents:
- diff - changeset -
- - 33 + 31 @@ -948,7 +910,7 @@ test that fileset in highlightfiles works and primes.py is not highlighted $ get-with-headers.py localhost:$HGPORT 'file/tip/primes.py' | grep 'id="l11"' - def primes(): + def sieve(ns): errors encountered