1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-30 08:08:58 +01:00

Chunk scanner test cases

This commit is contained in:
Oliver Steele 2017-06-27 13:18:11 -04:00
parent babfc3e527
commit fc6d96ed40

45
chunks/scanner_test.go Normal file
View File

@ -0,0 +1,45 @@
package chunks
import (
"testing"
"github.com/stretchr/testify/require"
)
var scannerTests = []struct{ in, expected string }{
{"{{12}}", "12"},
}
func TestScanner(t *testing.T) {
tokens := Scan("12", "")
require.NotNil(t, tokens)
require.Len(t, tokens, 1)
require.Equal(t, TextChunkType, tokens[0].Type)
require.Equal(t, "12", tokens[0].Source)
tokens = Scan("{{obj}}", "")
require.NotNil(t, tokens)
require.Len(t, tokens, 1)
require.Equal(t, ObjChunkType, tokens[0].Type)
require.Equal(t, "obj", tokens[0].Args)
tokens = Scan("{{ obj }}", "")
require.NotNil(t, tokens)
require.Len(t, tokens, 1)
require.Equal(t, ObjChunkType, tokens[0].Type)
require.Equal(t, "obj", tokens[0].Args)
tokens = Scan("{%tag args%}", "")
require.NotNil(t, tokens)
require.Len(t, tokens, 1)
require.Equal(t, TagChunkType, tokens[0].Type)
require.Equal(t, "tag", tokens[0].Tag)
require.Equal(t, "args", tokens[0].Args)
tokens = Scan("{% tag args %}", "")
require.NotNil(t, tokens)
require.Len(t, tokens, 1)
require.Equal(t, TagChunkType, tokens[0].Type)
require.Equal(t, "tag", tokens[0].Tag)
require.Equal(t, "args", tokens[0].Args)
}