Skip to content

Commit

Permalink
test(svg): add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMarble committed Mar 8, 2022
1 parent 8d7d490 commit 4360c80
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
41 changes: 41 additions & 0 deletions internal/svg/svg_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package svg_test

import (
"bytes"
"testing"

"github.com/mrmarble/termsvg/internal/svg"
"github.com/mrmarble/termsvg/internal/testutils"
"github.com/mrmarble/termsvg/pkg/asciicast"
"github.com/sebdah/goldie/v2"
)

func TestExport(t *testing.T) {
input := testutils.GoldenData(t, "TestExportInput")

cast, err := asciicast.Unmarshal(input)
if err != nil {
t.Fatal(err)
}

var output bytes.Buffer

svg.Export(*cast, &output)

g := goldie.New(t)
g.Assert(t, "TestExportOutput", output.Bytes())
}

func BenchmarkExport(b *testing.B) {
input := testutils.GoldenData(b, "TestExportInput")

cast, err := asciicast.Unmarshal(input)
if err != nil {
b.Fatal(err)
}

for i := 0; i < b.N; i++ {
var output bytes.Buffer
svg.Export(*cast, &output)
}
}
6 changes: 6 additions & 0 deletions internal/svg/testdata/TestExportInput.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"version": 2, "width": 213, "height": 58, "timestamp": 1598646467, "env": {"SHELL": "/usr/bin/zsh", "TERM": "alacritty"}}
[2.677085, "o", "h"]
[2.76064, "o", "e"]
[2.944434, "o", "l"]
[3.111831, "o", "l"]
[3.354445, "o", "o"]
34 changes: 34 additions & 0 deletions internal/svg/testdata/TestExportOutput.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<!-- Generated by SVGo -->
<svg width="2383" height="1510"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="0" y="0" width="2383" height="1510" rx="5" ry="5" style="fill:#282d35" />
<circle cx="20" cy="20" r="7" style="fill:#ff5f58" />
<circle cx="43" cy="20" r="7" style="fill:#ffbd2e" />
<circle cx="66" cy="20" r="7" style="fill:#18c132" />
<g style="animation-duration:3.35s;animation-iteration-count:infinite;animation-name:k;animation-timing-function:steps(1,end);font-family:Monaco,Consolas,Menlo,'Bitstream Vera Sans Mono','Powerline Symbols',monospace;font-size:20px">
<style type="text/css">
<![CDATA[
@keyframes k {79.807%{transform:translateX(-0px)}82.298%{transform:translateX(-2383px)}87.777%{transform:translateX(-4766px)}92.767%{transform:translateX(-7149px)}100.000%{transform:translateX(-9532px)}}
]]>
</style>
<g transform="translate(20,60)" >
<g transform="translate(0)">
<text x="0" y="0" fill="#e5e5e5" >h</text>
</g>
<g transform="translate(2383)">
<text x="0" y="0" fill="#e5e5e5" >he</text>
</g>
<g transform="translate(4766)">
<text x="0" y="0" fill="#e5e5e5" >hel</text>
</g>
<g transform="translate(7149)">
<text x="0" y="0" fill="#e5e5e5" >hell</text>
</g>
<g transform="translate(9532)">
<text x="0" y="0" fill="#e5e5e5" >hello</text>
</g>
</g>
</g>
</svg>

0 comments on commit 4360c80

Please sign in to comment.