예제 #1
0
function parse($content, $expected, $note = '', $debug = false)
{
    global $t;
    $parser = new SCSS_Parser();
    $lexer = new SCSS_Lexer();
    $lexer->setBuffer($content);
    if ($debug) {
        $lexer->debug = true;
        $parser->debug = true;
    }
    try {
        $parser->yyparse($lexer);
    } catch (Exception $e) {
        echo '[ERROR]' . $e->getMessage() . PHP_EOL;
        var_dump($lexer->lexbuf);
        var_dump($e->getTraceAsString());
        $t->fail('Caught unexpected Exception');
        exit(1);
    }
    $t->is($parser->run(), $expected . PHP_EOL, $note);
    $parser->reset();
}
예제 #2
0
<?php

require 'initialize.php';
$parser = new SCSS_Parser();
$t->comment('test import node');
$t->ok($base = $parser->genImport('@import "base.css";'), 'generate import node');
$t->isa_ok($base, 'SCSS_YYNode_Import', 'node isa SCSS_YYNode_Import');
$t->is($base->getType(), 'import', 'get node type');
$t->is($base->publish(), '@import "base.css";' . "\n", 'publish node');
$t->comment('import with media type');
$t->ok($print = $parser->genImport('@import    "print.css"    print  ;'), 'generate import node');
$t->isa_ok($print, 'SCSS_YYNode_Import', 'node isa SCSS_YYNode_Import');
$t->is($print->publish(), '@import    "print.css"    print  ;' . "\n", 'publish node');
$t->comment('import with multi media types');
$t->ok($multi = $parser->genImport('@import "multi.css" print,tv;'), 'generate import node');
$t->isa_ok($multi, 'SCSS_YYNode_Import', 'node isa SCSS_YYNode_Import');
$t->is($multi->publish(), '@import "multi.css" print,tv;' . "\n", 'publish node');
예제 #3
0
<?php

require 'initialize.php';
$parser = new SCSS_Parser();
$t->comment('test charset node');
$t->ok($charset = $parser->genCharset("'utf-8'"), 'generate charset node of "utf-8"');
$t->is(mb_internal_encoding(), 'UTF-8', 'mb_internal_encoding returns "UTF-8"');
$t->isa_ok($charset, 'SCSS_YYNode_Charset', 'charset node isa SCSS_YYNode_Charset');
$t->is($charset->getType(), 'charset', 'get node type');
$t->false($charset->hasChildren(), 'has not child nodes');
$t->false($charset->hasNext(), 'has not next node');
$t->is($charset->publish(), '@charset "utf-8";' . PHP_EOL, 'publish charset');
$t->ok($charset = $parser->genCharset('"shift-jis"'), 'generate charset node of "shift-jis"');
$t->is(mb_internal_encoding(), 'SJIS', 'mb_internal_encoding returns "SJIS"');
$t->is($charset->publish(), '@charset "shift-jis";' . PHP_EOL, 'publish charset');
예제 #4
0
<?php

require 'initialize.php';
$parser = new SCSS_Parser();
$t->comment('create declaration node');
$t->ok($decl = $parser->genDeclaration('margin', '0'), 'generate node');
$t->isa_ok($decl, 'SCSS_YYNode_Declaration', 'node isa SCSS_YYNode_Declaration');
$t->iss($decl->id, 0, 'id of first node is 0');
$t->is($decl->getType(), 'declaration', 'get node type');
$t->false($decl->hasChildren(), 'has not child nodes');
$t->false($decl->hasNext(), 'has not next node');
$t->is($decl->publish(), 'margin:0;', 'publish, not line breaking');
$t->comment('next node operation');
$t->ok($next = $parser->genDeclaration('padding', '10px'), 'generate node');
$t->is($parser->catNode($decl, $next), $decl, 'cat next node');
$t->true($decl->hasNext(), 'base declaration node has next one');
$t->is($decl->publish(), 'margin:0;', 'not publish next node');
$t->comment('without semicolon');
$t->ok($noSemi = $parser->genDeclaration('margin', '0'), 'generate node');
$t->is($noSemi->publish(), 'margin:0;', 'publish with semicolon');
$t->comment('blank spaces');
$t->ok($blank = $parser->genDeclaration('margin', '0'), 'generate node');
$t->is($blank->publish(), 'margin:0;', 'publish trimed');
$t->ok($blank = $parser->genDeclaration(' margin', ' 5px   10px  0 '), 'generate node');
$t->is($blank->publish(), 'margin:5px 10px 0;', 'space trimming and compressed');
/*
 * Expression formats.
 */
function through($property, $expr)
{
    global $t, $parser;
예제 #5
0
<?php

require 'initialize.php';
$parser = new SCSS_Parser();
$t->comment('test variables');
$t->is($parser->getVar('hoge'), '', 'get undefined variable is ""');
$t->is($parser->setVar('hoge', '"fuga"'), 'fuga', 'set variable, return value');
$t->is($parser->getVar('hoge'), 'fuga', 'get variable');
예제 #6
0
<?php

require 'initialize.php';
$parser = new SCSS_Parser();
$t->comment('test empty node');
$t->ok($empty = $parser->genEmpty(''), 'generate empty node');
$t->isa_ok($empty, 'SCSS_YYNode_Empty', 'empty node isa SCSS_YYNode_Empty');
$t->is($empty->getType(), 'empty', 'get node type');
$t->iss($empty->value, '', 'node value is empty');
$t->iss($empty->publish(), '', 'publish empty node');
$empty->appendValue('append');
$t->is($empty->value, 'append', 'node value is appended');
$t->iss($empty->publish(), '', 'publish empty regardless of node value');
예제 #7
0
<?php

require 'initialize.php';
$parser = new SCSS_Parser();
$t->comment('ident');
$t->ok($sel = $parser->genSelector('div'), 'generate node');
$t->is($sel->getType(), 'selector', 'get node type');
$t->false($sel->hasChildren(), 'has not child nodes');
$t->false($sel->hasNext(), 'has not next node');
$t->is($sel->getSelectors(), array('div'), 'get selectors (no parent)');
$t->is($sel->publish(), 'div', 'publish');
$t->comment('space selector');
$t->ok($sel = $parser->genSelector('div p'), 'generate node');
$t->is($sel->publish(), 'div p', 'publish');
$t->comment('comma separated multi selector');
$t->ok($sel = $parser->genSelector('#content div , p'), 'generate node');
$t->is($sel->publish(), '#content div, p', 'publish');
$t->comment('ident hash');
$t->ok($sel = $parser->genSelector('div#header'), 'generate node');
$t->is($sel->publish(), 'div#header', 'publish');
$t->comment('ident class');
$t->ok($sel = $parser->genSelector('div.section'), 'generate node');
$t->is($sel->publish(), 'div.section', 'publish');
$t->comment('ident hash and class');
$t->ok($sel = $parser->genSelector('div#container.col-ms'), 'generate node');
$t->is($sel->publish(), 'div#container.col-ms', 'publish');
$t->comment('ident pseudo');
$t->ok($sel = $parser->genSelector('a:hover'), 'generate node');
$t->is($sel->publish(), 'a:hover', 'publish');
$t->comment('plus combinator');
$t->ok($sel = $parser->genSelector('h1 + p'), 'generate node');