-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCompiler_test.go
67 lines (51 loc) · 1.12 KB
/
Compiler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package scarlet_test
import (
"fmt"
"io"
"os"
"strings"
"testing"
"time"
"github.com/aerogo/scarlet"
"github.com/akyoto/color"
)
func testFile(t *testing.T, filePath string) {
file, err := os.Open(filePath)
if err != nil {
t.Fatal(err)
}
start := time.Now()
css, _ := scarlet.Compile(file, true)
elapsed := time.Since(start)
fmt.Println(css)
fmt.Println(strings.Repeat("-", 80))
fmt.Println("Lines:", color.YellowString("%d", len(strings.Split(css, "\n"))))
fmt.Println("Size: ", color.YellowString("%d", len(css)))
fmt.Println("Time: ", color.GreenString("%v", elapsed))
}
func TestCompiler1(t *testing.T) {
testFile(t, "testdata/test.scarlet")
}
func TestCompiler2(t *testing.T) {
testFile(t, "testdata/test2.scarlet")
}
func BenchmarkCompiler(b *testing.B) {
file, err := os.Open("testdata/test.scarlet")
if err != nil {
b.Fatal(err)
}
b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, err := file.Seek(0, io.SeekStart)
if err != nil {
panic(err)
}
_, err = scarlet.Compile(file, false)
if err != nil {
panic(err)
}
}
})
}