Esempio n. 1
0
func TestParserChildCombinator(t *testing.T) {
	p := NewParser(runtime.NewContext())
	stmts := p.ParseScss(`.foo > .bar { width: auto; }`)
	ruleset, ok := (*stmts)[0].(*ast.RuleSet)
	assert.True(t, ok)
	assert.NotNil(t, ruleset)
}
Esempio n. 2
0
func main() {
	var rootCmd = &cobra.Command{
		Use:   "c6",
		Short: "C6 is a very fast SASS compatible compiler",
		Long:  `C6 is a SASS compatible implementation written in Go. But wait! this is not only to implement SASS, but also to improve the language for better consistency, syntax and performance.`,
		Run: func(cmd *cobra.Command, args []string) {
			// Do Stuff Here
		},
	}

	var versionCmd = &cobra.Command{
		Use:   "version",
		Short: "Print the version number of C6",
		Long:  `All software has versions. This is C6's`,
		Run: func(cmd *cobra.Command, args []string) {
			fmt.Println("C6 SASS Compiler v0.1 -- HEAD")
		},
	}
	rootCmd.AddCommand(versionCmd)

	var compileCmd = &cobra.Command{
		Use:   "compile",
		Short: "Compile some scss files",
		// Long:  "",
		Run: func(cmd *cobra.Command, args []string) {
			fmt.Println("Run compile!")

			_ = runtime.NewContext()
		},
	}
	rootCmd.AddCommand(compileCmd)
	rootCmd.Execute()
}
Esempio n. 3
0
func TestParserTypeSelector(t *testing.T) {
	p := NewParser(runtime.NewContext())
	stmts := p.ParseScss(`div { width: auto; }`)
	ruleset, ok := (*stmts)[0].(*ast.RuleSet)
	assert.True(t, ok)
	assert.NotNil(t, ruleset)
}
Esempio n. 4
0
func AssertCompile(t *testing.T, code string, expected string) {
	var context = runtime.NewContext()
	var parser = parser.NewParser(context)
	var stmts = parser.ParseScss(code)
	var compiler = NewCompactCompiler(context)
	var out = compiler.CompileString(stmts)
	assert.Equal(t, expected, out)
}
Esempio n. 5
0
func TestParserImportRuleWithUrl(t *testing.T) {
	p := NewParser(runtime.NewContext())
	stmts := p.ParseScss(`@import url("http://foo.com/bar.css");`)
	assert.Equal(t, 1, len(*stmts))

	rule, ok := (*stmts)[0].(*ast.ImportStmt)
	assert.True(t, ok, "Convert to ImportStmt OK")
	assert.NotNil(t, rule)
}
Esempio n. 6
0
func TestCompilerCompliant(t *testing.T) {
	var context = runtime.NewContext()
	var compiler = NewCompactCompiler(context)
	compiler.EnableCompliant(CSS3Compliant)
	compiler.EnableCompliant(IE7Compliant)
	assert.True(t, compiler.HasCompliant(CSS3Compliant))
	assert.False(t, compiler.HasCompliant(CSS4Compliant))

	assert.True(t, compiler.HasCompliant(IE7Compliant))
	assert.False(t, compiler.HasCompliant(IE8Compliant))
}
Esempio n. 7
0
func TestParserParseFile(t *testing.T) {
	testPath := "test/file.scss"
	bs, _ := ioutil.ReadFile(testPath)
	p := NewParser(runtime.NewContext())
	err := p.ParseFile(testPath)
	if err != nil {
		t.Fatal(err)
	}

	if e := string(bs); e != p.Content {
		t.Fatalf("got: %s wanted: %s", p.Content, e)
	}

	if e := testPath; e != p.File.FileName {
		t.Fatalf("got: %s wanted: %s", p.File.FileName, e)
	}
}
Esempio n. 8
0
func BenchmarkParserOverAll(b *testing.B) {
	for i := 0; i < b.N; i++ {
		var p = NewParser(runtime.NewContext())
		p.ParseScss(`div#myId.first-name.last-name {
			.foo-bar {
				color: red;
				background: #fff;
				border-radius: 10px;
			}

			@for $i from 1 through 100 { }
			@if $i == 1 {
				color: #111;
			} @else if $i == 2 {
				color: #222;
			} @else if $i == 3 {
				color: #333;
			} @else {
				color: red;
				background: url(../background.png);
			}

			div { width: auto; }
			div { width: 100px }
			div { width: 100pt }
			div { width: 100em }
			div { width: 100rem }
			div { padding: 10px 10px; }
			div { padding: 10px 10px 20px 30px; }
			div { padding: 10px + 10px; }
			div { padding: 10px + 10px * 3; }
			div { color: red; }
			div { color: rgb(255,255,255); }
			div { color: rgba(255,255,255,0); }
			div { background-image: url("../images/foo.png"); }
		}`)
	}

}
Esempio n. 9
0
func TestParserMassiveRules(t *testing.T) {
	var buffers []string = []string{
		`div { width: auto; }`,
		`div { width: 100px }`,
		`div { width: 100pt }`,
		`div { width: 100em }`,
		`div { width: 100rem }`,
		`div { padding: 10px 10px; }`,
		`div { padding: 10px 10px 20px 30px; }`,
		`div { padding: 10px + 10px; }`,
		`div { padding: 10px + 10px * 3; }`,
		`div { color: red; }`,
		`div { color: rgb(255,255,255); }`,
		`div { color: rgba(255,255,255,0); }`,
		`div { background-image: url("../images/foo.png"); }`,
		// `div { color: #ccddee; }`,
	}
	for _, buffer := range buffers {
		t.Logf("%s\n", buffer)
		var p = NewParser(runtime.NewContext())
		var stmts = p.ParseScss(buffer)
		t.Logf("%+v\n", stmts)
	}
}
Esempio n. 10
0
func BenchmarkParserMediaQueryAllAndMinWidth(b *testing.B) {
	for i := 0; i < b.N; i++ {
		var p = NewParser(runtime.NewContext())
		p.ParseScss(`@media all and (min-width:500px) {  .red { color: red; } }`)
	}
}
Esempio n. 11
0
func BenchmarkParserComplexSelector(b *testing.B) {
	for i := 0; i < b.N; i++ {
		var p = NewParser(runtime.NewContext())
		p.ParseScss(`div#myId.first-name.last-name, span, html, .first-name, .last-name { }`)
	}
}
Esempio n. 12
0
func BenchmarkParserAttributeSelector(b *testing.B) {
	for i := 0; i < b.N; i++ {
		var p = NewParser(runtime.NewContext())
		p.ParseScss(`input[type=text] {  }`)
	}
}
Esempio n. 13
0
func BenchmarkParserClassSelector(b *testing.B) {
	for i := 0; i < b.N; i++ {
		var p = NewParser(runtime.NewContext())
		p.ParseScss(`.foo-bar {}`)
	}
}
Esempio n. 14
0
func TestParserImportRuleWithString(t *testing.T) {
	p := NewParser(runtime.NewContext())
	stmts := p.ParseScss(`@import "foo.css";`)
	assert.Equal(t, 1, len(*stmts))
}
Esempio n. 15
0
func RunParserTest(code string) *ast.StmtList {
	var p = NewParser(runtime.NewContext())
	return p.ParseScss(code)
}