def test_if_else_node(): s = "if x\n Do\n Not Fail\nelse\n A\n B C" toks = StylusParser().parse(s) assert isinstance(toks[0], AST.ConditionalNode) s = "if x\n Do\n Not Fail\n\nelse\n A\n B C" toks = StylusParser().parse(s) assert isinstance(toks[0], AST.ConditionalNode)
def test_selector_list(): s = "div,body\n background blue" res = StylusParser().parse(s) s = "div\nbody\n background blue" res = StylusParser().parse(s) assert isinstance(res[0], AST.StyleNode) assert str(res[0]) == "div, body{background:blue}"
def test_if_node(): s = "if x\n Do\n Not Fail" toks = StylusParser().parse(s) assert isinstance(toks[0], AST.ConditionalNode) s = "if (x)\n Do\n Not Fail" toks = StylusParser().parse(s) assert isinstance(toks[0], AST.ConditionalNode)
def test_function_definition(): s = "foo(a, b,c)\n return a" styl = StylusParser() styl.parse(s) func = styl.stack[0] assert type(func) == AST.FunctionNode assert func.name == 'foo' assert func.args == ['a', 'b', 'c']
def test_if_elif_node(): s = "if x\n Do\n Not Fail\nelif y\n A\n B C" toks = StylusParser().parse(s) assert isinstance(toks[0], AST.ConditionalNode) s = "if x\n Do\n Not Fail\n\nelif (y)\n A\n B C" toks = StylusParser().parse(s) assert isinstance(toks[0], AST.ConditionalNode) s = "if x\n Do\n Not Fail\n\nelif (y)\n A\n B C\nelif a\n A\n B C" toks = StylusParser().parse(s) assert isinstance(toks[0], AST.ConditionalNode) assert len(toks[0].else_ifs) == 2
def test_multi_style(): s = """ div color red body margin 0 0 30px 30px """ res = StylusParser().parse(s)
def test_constructor(): styl = StylusParser() assert isinstance(styl, StylusParser)
def xtest_function_block(): s = """add(x, y) x + y """ styl = StylusParser() styl.parse(s)
def test_empty_function(): with pytest.raises(StylusParserError): StylusParser().parse("A(a)\n")
def test_bad_function_definition(): with pytest.raises(StylusParserError): StylusParser().parse("A (a, b,c)\n return")
def test_funcdef_no_args(): s = 'foo()\n return' StylusParser().parse(s)
def test_block(): s = "body\ndiv\n color red" styl = StylusParser() styl.parse(s)
def test_simple_style(): s = """ div color red """ res = StylusParser().parse(s)
def test_universal_selector(): s = "*\n color red" res = StylusParser().parse(s) assert isinstance(res[0], AST.StyleNode) assert res[0].selectors[0] == '*'