本文整理汇总了Golang中github.com/wellington/sass/token.NewFileSet函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFileSet函数的具体用法?Golang NewFileSet怎么用?Golang NewFileSet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFileSet函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSelector_deep_nesting
func TestSelector_deep_nesting(t *testing.T) {
ctx := NewContext()
ctx.fset = token.NewFileSet()
input := `a {
c, d, e {
f, g, h {
m, n, o {
color: blue;
}
}
}
}`
out, err := ctx.runString("", input)
if err != nil {
t.Fatal(err)
}
e := `a c f m, a c f n, a c f o, a c g m, a c g n, a c g o, a c h m, a c h n, a c h o, a d f m, a d f n, a d f o, a d g m, a d g n, a d g o, a d h m, a d h n, a d h o, a e f m, a e f n, a e f o, a e g m, a e g n, a e g o, a e h m, a e h n, a e h o {
color: blue; }
`
if e != out {
t.Fatalf("got:\n%s\nwanted:\n%s", out, e)
}
}
开发者ID:wellington,项目名称:sass,代码行数:25,代码来源:compile_test.go
示例2: TestDirective_each_paran
func TestDirective_each_paran(t *testing.T) {
ctx := NewContext()
ctx.fset = token.NewFileSet()
input := `div {
@each $i in (1 2 3 4 5) {
i: $i;
}
}
`
out, err := ctx.runString("", input)
if err != nil {
t.Fatal(err)
}
e := `div {
i: 1;
i: 2;
i: 3;
i: 4;
i: 5; }
`
if e != out {
t.Fatalf("got:\n%s\nwanted:\n%s", out, e)
}
}
开发者ID:wellington,项目名称:sass,代码行数:26,代码来源:directive_test.go
示例3: TestDecl_if
func TestDecl_if(t *testing.T) {
ctx := NewContext()
ctx.fset = token.NewFileSet()
input := `$x: 1 2;
@if type-of(nth($x, 2)) == number {
div {
background: gray;
}
}
@else if type-of(nth($x, 2)) == string {
div {
background: blue;
}
}
@else {
div {
background: green;
}
}
`
ctx.SetMode(parser.Trace)
out, err := ctx.runString("", input)
if err != nil {
t.Fatal(err)
}
e := `div {
background: gray; }
`
if e != out {
t.Fatalf("got:\n%s\nwanted:\n%s", out, e)
}
}
开发者ID:wellington,项目名称:sass,代码行数:35,代码来源:decl_test.go
示例4: TestDecl_func_if
func TestDecl_func_if(t *testing.T) {
ctx := NewContext()
ctx.fset = token.NewFileSet()
input := `$x: true;
@function foobar() {
@if $x {
$x: false !global;
@return foo;
}
}
div {
content: foobar();
}
`
ctx.SetMode(parser.Trace)
out, err := ctx.runString("", input)
if err != nil {
t.Fatal(err)
}
e := `div {
content: foo; }
`
if e != out {
t.Fatalf("got:\n%s\nwanted:\n%s", out, e)
}
}
开发者ID:wellington,项目名称:sass,代码行数:30,代码来源:decl_test.go
示例5: TestSelector_selector_interp
func TestSelector_selector_interp(t *testing.T) {
ctx := NewContext()
ctx.fset = token.NewFileSet()
input := `$x: oo, ba;
$y: az, hu;
f#{$x}r {
p: 1;
b#{$y}x {
q: 2;
mumble#{length($x) + length($y)} {
r: 3;
}
}
}
`
out, err := ctx.runString("", input)
if err != nil {
t.Fatal(err)
}
e := `foo, bar {
p: 1; }
foo baz, foo hux, bar baz, bar hux {
q: 2; }
foo baz mumble4, foo hux mumble4, bar baz mumble4, bar hux mumble4 {
r: 3; }
`
if e != out {
t.Fatalf("got:\n%s\nwanted:\n%s", out, e)
}
}
开发者ID:wellington,项目名称:sass,代码行数:35,代码来源:compile_test.go
示例6: testString
func testString(t *testing.T, in string, mode Mode) (*ast.File, *token.FileSet) {
fset := token.NewFileSet()
f, err := ParseFile(fset, "testfile", in, mode)
if err != nil {
t.Fatal(err)
}
return f, fset
}
开发者ID:wellington,项目名称:sass,代码行数:9,代码来源:parser_test.go
示例7: TestUnitMath
func TestUnitMath(t *testing.T) {
const src = `
$a: 3px + 3px;
div {
width: $a;
}
`
f, err := ParseFile(token.NewFileSet(), "", src, 0)
if err != nil {
t.Fatal(err)
}
objects := map[string]ast.ObjKind{
"$color": ast.Var,
"$list": ast.Var,
}
ast.Inspect(f, func(n ast.Node) bool {
if spec, ok := n.(*ast.RuleSpec); ok {
ast.Print(token.NewFileSet(), spec)
}
return true
if ident, ok := n.(*ast.Ident); ok {
return true
obj := ident.Obj
if obj == nil {
if objects[ident.Name] != ast.Bad {
t.Errorf("no object for %s", ident.Name)
}
return true
}
if obj.Name != ident.Name {
t.Errorf("names don't match: obj.Name = %s, ident.Name = %s", obj.Name, ident.Name)
}
kind := objects[ident.Name]
if obj.Kind != kind {
t.Errorf("%s: obj.Kind = %s; want %s", ident.Name, obj.Kind, kind)
}
}
return true
})
}
开发者ID:wellington,项目名称:sass,代码行数:41,代码来源:parser_test.go
示例8: TestImports
func TestImports(t *testing.T) {
for path, isValid := range imports {
src := fmt.Sprintf("@import %s;", path)
_, err := ParseFile(token.NewFileSet(), "", src, 0) // Trace
switch {
case err != nil && isValid:
t.Errorf("ParseFile(%s): got %v; expected no error", src, err)
case err == nil && !isValid:
t.Errorf("ParseFile(%s): got no error; expected one", src)
}
}
}
开发者ID:wellington,项目名称:sass,代码行数:12,代码来源:parser_test.go
示例9: runParse
func runParse(t *testing.T, in string, e string) {
ctx := NewContext()
// ctx.SetMode(parser.Trace)
ctx.fset = token.NewFileSet()
bout, err := ctx.run("", in)
if err != nil {
t.Fatal(err)
}
out := string(bout)
if e != out {
t.Errorf("got:\n%q\nwanted:\n%q", out, e)
}
}
开发者ID:wellington,项目名称:sass,代码行数:14,代码来源:builtin_test.go
示例10: run
func (ctx *Context) run(path string, src interface{}) ([]byte, error) {
ctx.fset = token.NewFileSet()
// ctx.mode = parser.Trace
pf, err := parser.ParseFile(ctx.fset, path, src, ctx.mode)
if err != nil {
return nil, err
}
ast.Walk(ctx, pf)
lr, _ := utf8.DecodeLastRune(ctx.buf.Bytes())
_ = lr
if ctx.buf.Len() > 0 && lr != '\n' {
ctx.out("\n")
}
// ctx.printSels(pf.Decls)
return ctx.buf.Bytes(), nil
}
开发者ID:wellington,项目名称:sass,代码行数:18,代码来源:compile.go
示例11: TestSelector_combinators
func TestSelector_combinators(t *testing.T) {
ctx := NewContext()
ctx.fset = token.NewFileSet()
input := `a + b ~ c { color: red; }
`
out, err := ctx.runString("", input)
if err != nil {
t.Fatal(err)
}
e := `a + b ~ c {
color: red; }
`
if e != out {
t.Fatalf("got:\n%s\nwanted:\n%s", out, e)
}
}
开发者ID:wellington,项目名称:sass,代码行数:19,代码来源:compile_test.go
示例12: TestBinary_math
func TestBinary_math(t *testing.T) {
const src = `
$a: inspect(1 + 3);
$b: inspect(3/1);
$c: inspect(1/2 + 1/2);
$d: inspect(2*2);
$d: inspect(1*1/2);
$e: inspect(1/2*1/2);
$f: inspect(2*2/2*2);
//$o: inspect(3px + 3px + 3px);
`
f, err := ParseFile(token.NewFileSet(), "", src, 0|Trace)
if err != nil {
t.Fatal(err)
}
lits := []string{
"4",
"3",
"1",
"4",
"0.5",
"0.25",
"4",
}
var pos int
ast.Inspect(f, func(n ast.Node) bool {
if call, ok := n.(*ast.CallExpr); ok {
// ident := call.Fun.(*ast.Ident)
lit := call.Resolved.(*ast.BasicLit)
val := lits[pos]
pos++
if val != lit.Value {
t.Errorf("useful ident here got: %s wanted %s", lit.Value, val)
}
}
return true
})
}
开发者ID:wellington,项目名称:sass,代码行数:42,代码来源:math_test.go
示例13: TestSelector_many_nests
func TestSelector_many_nests(t *testing.T) {
ctx := NewContext()
ctx.fset = token.NewFileSet()
input := `a, b {
c, d { color: red; }
}
`
out, err := ctx.runString("", input)
if err != nil {
t.Fatal(err)
}
e := `a c, a d, b c, b d {
color: red; }
`
if e != out {
t.Fatalf("got:\n%s\nwanted:\n%s", out, e)
}
}
开发者ID:wellington,项目名称:sass,代码行数:20,代码来源:compile_test.go
示例14: TestInterp
func TestInterp(t *testing.T) {
ctx := NewContext()
ctx.fset = token.NewFileSet()
input := `div {
hello: #{123+321};
}
`
out, err := ctx.runString("", input)
if err != nil {
t.Fatal(err)
}
e := `div {
hello: 444; }
`
if e != out {
t.Fatalf("got:\n%s\nwanted:\n%s", out, e)
}
}
开发者ID:wellington,项目名称:sass,代码行数:20,代码来源:interp_test.go
示例15: register
func register(s string, ch builtin.CallFunc, h builtin.CallHandle) {
fset := token.NewFileSet()
pf, err := ParseFile(fset, "", s, FuncOnly)
if err != nil {
if !strings.HasSuffix(err.Error(), "expected ';', found 'EOF'") {
log.Fatal(err)
}
}
d := &desc{c: call{
ch: ch,
handle: h,
}}
ast.Walk(d, pf.Decls[0])
if d.err != nil {
log.Fatal("failed to parse func description", d.err)
}
if _, ok := builtins[d.c.name]; ok {
log.Println("already registered", d.c.name)
}
builtins[d.c.name] = d.c
}
开发者ID:wellington,项目名称:sass,代码行数:21,代码来源:builtin.go
示例16: TestSelector_comboampersand
func TestSelector_comboampersand(t *testing.T) {
ctx := NewContext()
ctx.fset = token.NewFileSet()
input := `div ~ b {
& + & { color: red; }
}
`
out, err := ctx.runString("", input)
if err != nil {
t.Fatal("compilation fail", err)
}
e := `div ~ b + div ~ b {
color: red; }
`
if e != out {
t.Fatalf("got:\n%s\nwanted:\n%s", out, e)
}
}
开发者ID:wellington,项目名称:sass,代码行数:21,代码来源:compile_test.go
示例17: TestSelector_singleampersand
func TestSelector_singleampersand(t *testing.T) {
ctx := NewContext()
ctx.fset = token.NewFileSet()
input := `div {
& { color: red; }
}
`
out, err := ctx.runString("", input)
if err != nil {
t.Fatal(err)
}
e := `div {
color: red; }
`
if e != out {
t.Fatalf("got:\n%s\nwanted:\n%s", out, e)
}
}
开发者ID:wellington,项目名称:sass,代码行数:21,代码来源:compile_test.go
示例18: TestSelector_nesting_child_group
func TestSelector_nesting_child_group(t *testing.T) {
ctx := NewContext()
ctx.fset = token.NewFileSet()
input := `a {
b, c { color: red; }
}
`
out, err := ctx.runString("", input)
if err != nil {
t.Fatal(err)
}
e := `a b, a c {
color: red; }
`
if e != out {
t.Fatalf("got:\n%s\nwanted:\n%s", out, e)
}
}
开发者ID:wellington,项目名称:sass,代码行数:21,代码来源:compile_test.go
示例19: TestSpec_files
func TestSpec_files(t *testing.T) {
inputs, err := filepath.Glob("../sass-spec/spec/basic/*/input.scss")
if err != nil {
t.Fatal(err)
}
mode := DeclarationErrors
mode = Trace | ParseComments
var name string
for _, name = range inputs {
if strings.Contains(name, "25_") && testing.Short() {
// This is the last test we currently parse properly
return
}
if !strings.Contains(name, "29_") {
continue
}
if strings.Contains(name, "06_") {
continue
}
if strings.Contains(name, "14_") {
continue
}
// These are fucked things in Sass like lists
if strings.Contains(name, "15_") {
continue
}
// namespaces are wtf
if strings.Contains(name, "24_") {
continue
}
fmt.Println("Parsing", name)
_, err := ParseFile(token.NewFileSet(), name, nil, mode)
if err != nil {
t.Fatalf("ParseFile(%s): %v", name, err)
}
fmt.Println("Parsed", name)
}
}
开发者ID:wellington,项目名称:sass,代码行数:40,代码来源:spec_test.go
示例20: TestSelector_inplace_nesting
func TestSelector_inplace_nesting(t *testing.T) {
ctx := NewContext()
ctx.fset = token.NewFileSet()
input := `hey, ho {
foo &.goo {
color: blue;
}
}
`
out, err := ctx.runString("", input)
if err != nil {
t.Fatal(err)
}
e := `foo hey.goo, foo ho.goo {
color: blue; }
`
if e != out {
t.Fatalf("got:\n%s\nwanted:\n%s", out, e)
}
}
开发者ID:wellington,项目名称:sass,代码行数:22,代码来源:compile_test.go
注:本文中的github.com/wellington/sass/token.NewFileSet函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论