Permalink
Browse files

Fixed bug with multiline comments, added a test.

  • Loading branch information...
1 parent a3dadec commit 78d5f8eddaadf7c8cd8776d2d9f9e72b743423ee @tymofij tymofij committed with Sep 18, 2009
Showing with 46 additions and 21 deletions.
  1. +1 −0 .gitignore
  2. +3 −1 BUGFIXES
  3. +6 −3 clevercss.py
  4. +36 −17 tests/__init__.py
View
@@ -1,3 +1,4 @@
+*.pyc
*.swp
CleverCSS.egg-info
build
View
@@ -1,7 +1,9 @@
List of bug fixes since CleverCSS-0.1
===================================
- - submitted by Tim Babych - The Parser was not aware of negative numbers, thus any minus sign was an operator, leading to calculation where it should not be, like "margin: -2px -2px" was converted into "margin: -4px"
+9/18/09 - v.0.1.5 - submitted by Tim Babych - The Parser was not aware of negative numbers. Thus any minus sign was an operator, leading to unneeded calculations. Say, "margin: -2px -2px" was converted into "margin: -4px"
+
+9/18/09 - v.0.1.5 - submitted by Tim Babych - LineIterator was not filtering out "\n"s that were left after trimming /* comments */, causing an exception in Parser
9/01/09 - v.0.1.4 - submitted by David Niergarth and 'Lasse' - Missing None check in Engine.evaluate which causes context to always be reset to {}.
View
@@ -559,12 +559,15 @@ def _next(self):
def next(self):
"""
- Get the next line without multiline comments and emit the
- endmarker if we reached the end of the sourcecode and endmarkers
+ Get the next non-whitespace line without multiline comments and emit
+ the endmarker if we reached the end of the sourcecode and endmarkers
were requested.
"""
try:
- return self._next()
+ while True:
+ lineno, stripped_line = self._next()
+ if stripped_line:
+ return lineno, stripped_line
except StopIteration:
if self.emit_endmarker:
self.emit_endmarker = False
View
@@ -1,4 +1,5 @@
from unittest import TestCase, main
+from textwrap import dedent
from clevercss import rgb_to_hls
@@ -70,23 +71,41 @@ def test_02_convert(self):
u'body {\n background-color: #cc0000;\n}')
def test_math(self):
- self.assertEqual(convert("""
-div:
- margin: -2px -2px
- padding: 2px + 2px
- top: 1px+1
- left: 5+5px
- right: 4px-5px
- bottom: 0 - 5px
-"""),
-"""div {
- margin: -2px -2px;
- padding: 4px;
- top: 2px;
- left: 10px;
- right: -1px;
- bottom: -5px;
-}""")
+ self.assertEqual(convert(dedent("""
+ div:
+ margin: -2px -2px
+ padding: 2px + 2px
+ top: 1px+1
+ left: 5+5px
+ right: 4px-5px
+ bottom: 0 - 5px
+ """)), dedent("""
+ div {
+ margin: -2px -2px;
+ padding: 4px;
+ top: 2px;
+ left: 10px;
+ right: -1px;
+ bottom: -5px;
+ }""").strip())
+
+from clevercss import LineIterator
+
+class LineIterTestCase(TestCase):
+ def test_comments(self):
+ line_iter = LineIterator(dedent(
+ """
+ /* block */
+ /* multiblock
+ */
+
+ aa, /* comment */bb:
+ x:1 // comment
+
+ """))
+ self.assertEqual("\n".join([s[1] for s in line_iter]),
+ "aa, bb:\n x:1")
+
if __name__ == '__main__':
main()

0 comments on commit 78d5f8e

Please sign in to comment.