Issue 4 allow nested @import
This commit is contained in:
parent
ca9ef1a107
commit
b46f8c4ad0
@ -130,6 +130,7 @@ class LessParser(object):
|
||||
| block_decl
|
||||
| mixin_decl
|
||||
| call_mixin
|
||||
| import_statement
|
||||
"""
|
||||
p[0] = p[1]
|
||||
|
||||
@ -151,7 +152,7 @@ class LessParser(object):
|
||||
p[0].parse(None)
|
||||
|
||||
def p_statement_import(self, p):
|
||||
""" statement : css_import t_ws css_string ';'
|
||||
""" import_statement : css_import t_ws css_string ';'
|
||||
| css_import t_ws css_string dom ';'
|
||||
"""
|
||||
if self.importlvl > 8:
|
||||
@ -354,6 +355,7 @@ class LessParser(object):
|
||||
| block_decl
|
||||
| mixin_decl
|
||||
| call_mixin
|
||||
| import_statement
|
||||
"""
|
||||
p[0] = p[1] if type(p[1]) is list else [p[1]]
|
||||
|
||||
|
@ -10,14 +10,14 @@ import bootstrap
|
||||
def find():
|
||||
svn = re.compile('\.svn')
|
||||
test = re.compile('test.+\.py$')
|
||||
skip = re.compile('testissues.*')
|
||||
# skip = re.compile('testissues.*')
|
||||
alltests = unittest.TestSuite()
|
||||
for path, _, files in os.walk(bootstrap.here):
|
||||
if svn.search(path):
|
||||
continue
|
||||
for f in files:
|
||||
if skip.search(f):
|
||||
continue
|
||||
# if skip.search(f):
|
||||
# continue
|
||||
if test.search(f):
|
||||
module = __import__(f.split('.')[0])
|
||||
alltests.addTest(unittest.findTestCases(module))
|
||||
|
5
lesscpy/test/css/issues/issue4.css
Normal file
5
lesscpy/test/css/issues/issue4.css
Normal file
@ -0,0 +1,5 @@
|
||||
@media print {
|
||||
.mixin {
|
||||
color: red;
|
||||
}
|
||||
}
|
2
lesscpy/test/css/issues/issue4.min.css
vendored
Normal file
2
lesscpy/test/css/issues/issue4.min.css
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
@media print{.mixin{color:red;}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
// class="404"
|
||||
.\34 04 {
|
||||
background: red;
|
||||
|
||||
strong {
|
||||
color: @ugly;
|
||||
.mixin\!tUp;
|
||||
}
|
||||
}
|
6
lesscpy/test/less/issues/issue4.less
Normal file
6
lesscpy/test/less/issues/issue4.less
Normal file
@ -0,0 +1,6 @@
|
||||
/*
|
||||
Allow nested imports
|
||||
*/
|
||||
@media print {
|
||||
@import "../imports/import.less";
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
"""
|
||||
lesscpy tests. Issues
|
||||
lesscpy tests.
|
||||
"""
|
||||
import unittest
|
||||
import os
|
||||
@ -9,30 +9,64 @@ import bootstrap
|
||||
from lesscpy.lessc import parser
|
||||
from lesscpy.lessc import formatter
|
||||
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def create_test (pair):
|
||||
class Opt(object):
|
||||
def __init__(self):
|
||||
self.minify = False
|
||||
self.xminify = False
|
||||
self.tabs = True
|
||||
|
||||
def create_test (args):
|
||||
def do_test_expected(self):
|
||||
if os.path.exists(pair[1]):
|
||||
lessf, cssf, minf = args
|
||||
if os.path.exists(cssf):
|
||||
p = parser.LessParser()
|
||||
p.parse(filename=pair[0])
|
||||
f = formatter.Formatter()
|
||||
p.parse(filename=lessf)
|
||||
f = formatter.Formatter(Opt())
|
||||
pout = f.format(p).split('\n')
|
||||
pl = len(pout)
|
||||
i = 0
|
||||
with open(pair[1]) as cssf:
|
||||
with open(cssf) as cssf:
|
||||
for line in cssf.readlines():
|
||||
self.assertEqual(line.rstrip(), pout[i], '%s: Line %d' % (pair[1], i+1))
|
||||
if i >= pl:
|
||||
self.fail("%s: result has less lines (%d < %d)" % (cssf, i, pl))
|
||||
line = line.rstrip()
|
||||
if not line: continue
|
||||
self.assertEqual(line, pout[i], '%s: Line %d' % (cssf, i+1))
|
||||
i += 1
|
||||
else: self.fail('%s not found' % pair[1])
|
||||
if pl > i and i:
|
||||
self.fail("%s: result has more lines (%d > %d)" % (cssf, i, pl))
|
||||
else:
|
||||
self.fail("%s not found..." % cssf)
|
||||
if os.path.exists(minf):
|
||||
p = parser.LessParser()
|
||||
opt = Opt()
|
||||
opt.minify = True
|
||||
p.parse(filename=lessf)
|
||||
f = formatter.Formatter(opt)
|
||||
mout = f.format(p).split('\n')
|
||||
ml = len(mout)
|
||||
i = 0
|
||||
with open(minf) as cssf:
|
||||
for line in cssf.readlines():
|
||||
if i >= ml:
|
||||
self.fail("%s: result has less lines (%d < %d)" % (minf, i, ml))
|
||||
self.assertEqual(line.rstrip(), mout[i], '%s: Line %d' % (minf, i+1))
|
||||
i += 1
|
||||
if ml > i and i:
|
||||
self.fail("%s: result has more lines (%d > %d)" % (minf, i, ml))
|
||||
else:
|
||||
self.fail("%s not found..." % minf)
|
||||
return do_test_expected
|
||||
|
||||
LESS = glob.glob( os.path.join('less/issues/', '*.less'))
|
||||
LESS = glob.glob( os.path.join('less/issues', '*.less'))
|
||||
for less in LESS:
|
||||
css = less.split('.')[0].split('/')[-1]
|
||||
css = 'css/issues/' + css + '.css'
|
||||
test_method = create_test((less, css))
|
||||
lessf = less.split('.')[0].split('/')[-1]
|
||||
css = 'css/issues/' + lessf + '.css'
|
||||
mincss = 'css/issues/' + lessf + '.min.css'
|
||||
test_method = create_test((less, css, mincss))
|
||||
test_method.__name__ = 'test_%s' % less.replace('./-', '_')
|
||||
setattr(TestCase, test_method.__name__, test_method)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user