def test_filter_properties(self): first = ''' foo color green bar margin 0 margin 0 0 margin 0 0 0 margin 0 0 0 0 baz pass div pass pass span pass margin 0 pass ''' second = [ (1, 'foo', 0, 1, True, True ), (2, ('color', 'green'), 1, 1, False, True ), (3, 'bar', 0, -1, True, False), (7, ('margin', '0 0 0 0'), 1, 1, False, True ), (8, 'baz', 0, -1, True, False), (10, 'pass', 1, 1, False, True ), (10, 'div', 0, -1, True, False), (13, 'pass', 1, 1, False, True ), (13, 'span', 0, -1, True, False), (15, ('margin', '0'), 1, 0, False, False), (0, '', 0, -1, True, False)] first = tokenize_selectors_and_properties(_in(first), self.indent) first = _out(filter_properties(first)) self.assertEquals(first, second)
def test_check_media_queries_syntax(self): first = ''' div pass @media --- @media margin 0 --- @media div pass --- div span @media --- @media @media margin 0 --- @media ''' for first in first.split('---'): first = tokenize_selectors_and_properties(_in(first), self.indent) with self.assertRaises(IndentationError): _out(check_media_queries_syntax(first))
def test_tokenize_selectors_and_properties(self): first = ''' .menu pass color red margin 0 -item color blue float left _selected color green border none ''' second = [ (1, '.menu', 0, 1, True, True), (2, 'pass', 1, 1, False, True), (3, ('color', 'red'), 1, 0, False, False), (4, ('margin', '0'), 1, 0, False, False), (5, '-item', 1, 0, True, False), (6, ('color', 'blue'), 2, 1, False, True), (7, ('float', 'left'), 2, 0, False, False), (8, '_selected', 2, 0, True, False), (9, ('color', 'green'), 3, 1, False, True), (10, ('border', 'none'), 3, 0, False, False), (0, '', 0, -3, True, False)] first = _out(tokenize_selectors_and_properties(_in(first), self.indent)) self.assertEquals(first, second)
def test_check_imports_syntax_error(self): first = ''' @import ''' for first in first.split('---'): first = tokenize_selectors_and_properties(_in(first), self.indent) with self.assertRaises(SyntaxError): _out(check_imports_syntax(first))
def test_check_indentation_errors(self): first = ''' .foo --- .bar --- \t.baz --- div input --- div input --- div \t input --- margin-bottom 1px --- div div.sidebar margin-bottom 0px --- div div --- div .menu input pass --- .menu .item span float left --- .menu float left margin-bottom 0px --- .menu #item float left margin-bottom 0px --- @media screen @media screen ''' for first in first.split('---'): first = tokenize_selectors_and_properties(_in(first), self.indent) with self.assertRaises(IndentationError): _out(check_indentation_errors(first))
def test_check_imports_syntax_for_indentation_error(self): first = ''' @import foo.css foo pass --- div span @import foo.css ''' for first in first.split('---'): first = tokenize_selectors_and_properties(_in(first), self.indent) with self.assertRaises(IndentationError): _out(check_imports_syntax(first))
def test_combine_selectors1(self): first = ''' foo foo1 bar baz baz1 pass dum dum1 div pass must must1 div pass qalandar qalandar1 div pass ''' second = [ (['foo', 'bar', 'baz'], True, True), (['foo1', 'bar', 'baz'], True, True), (['foo', 'bar', 'baz1'], True, True), (['foo1', 'bar', 'baz1'], True, True), ('pass', False, True), (['foo', 'bar', 'dum', 'div'], True, False), (['foo1', 'bar', 'dum', 'div'], True, True), (['foo', 'bar', 'dum1', 'div'], True, True), (['foo1', 'bar', 'dum1', 'div'], True, True), ('pass', False, True), (['foo', 'must', 'div'], True, False), (['foo1', 'must', 'div'], True, True), (['foo', 'must1', 'div'], True, True), (['foo1', 'must1', 'div'], True, True), ('pass', False, True), (['qalandar', 'div'], True, False), (['qalandar1', 'div'], True, True), ('pass', False, True), ] first = tokenize_selectors_and_properties(_in(first), self.indent) first = list(combine_selectors(_out(first, 2))) self.assertEquals(first, second)
def test_make_statements_list1(self): first = ''' .header .footer a .left .right pass .banner div pass :hover :active div pass @import print .header .footer div pass ''' second = [ ([['.header', 'a', '.left'], ['.footer', 'a', '.left'], ['.header', 'a', '.right'], ['.footer', 'a', '.right']], []), ([['.header', 'a', '.banner', 'div'], ['.footer', 'a', '.banner', 'div']], []), ([['.header', ':hover', 'div'], ['.footer', ':hover', 'div'], ['.header', ':active', 'div'], ['.footer', ':active', 'div']], []), ([['@import print', '.header', 'div'], ['@import print', '.footer', 'div']], []), ] first = tokenize_selectors_and_properties(_in(first), self.indent) first = combine_selectors(_out(first, 2)) first = list(make_statements_list(first)) self.assertEqual(first, second)
def test_combine_selectors(self): first = ''' .last _menu pass -item pass _selected color green _modified pass :hover :active color green font serif _last color green font serif width 100% ''' second = [ (['.last', '_menu'], True, True), ('pass', False, True), (['.last', '_menu', '-item'], True, False), ('pass', False, True), (['.last', '_menu', '-item', '_selected'], True, False), (('color', 'green'), False, True), (['.last', '_menu', '-item', '_selected', '_modified'], True, False), ('pass', False, True), (['.last', '_menu', '-item', '_selected', '_modified', ':hover'], True, False), (['.last', '_menu', '-item', '_selected', '_modified', ':active'], True, True), (('color', 'green'), False, True), (('font', 'serif'), False, False), (['.last', '_menu', '-item', '_last'], True, False), (('color', 'green'), False, True), (('font', 'serif'), False, False), (('width', '100%'), False, False), ] first = tokenize_selectors_and_properties(_in(first), self.indent) first = list(combine_selectors(_out(first, 2))) self.assertEquals(first, second)
def test_tokenize_selectors_and_properties_for_empty_input(self): first = ''' ''' first = _out(tokenize_selectors_and_properties(_in(first), self.indent)) self.assertEquals(first, [])