1
0
mirror of https://github.com/danog/liquid.git synced 2024-12-11 16:19:38 +01:00
liquid/expressions/statements_test.go

38 lines
1.1 KiB
Go
Raw Normal View History

2017-07-19 00:37:28 +02:00
package expressions
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestParseStatement(t *testing.T) {
stmt, err := ParseStatement(AssignStatementSelector, "a = b")
require.NoError(t, err)
require.Equal(t, "a", stmt.Assignment.Variable)
stmt, err = ParseStatement(CycleStatementSelector, "'a', 'b'")
require.NoError(t, err)
require.Equal(t, "", stmt.Cycle.Group)
require.Len(t, stmt.Cycle.Values, 2)
require.Equal(t, []string{"a", "b"}, stmt.Cycle.Values)
stmt, err = ParseStatement(CycleStatementSelector, "'g': 'a', 'b'")
require.NoError(t, err)
require.Equal(t, "g", stmt.Cycle.Group)
require.Len(t, stmt.Cycle.Values, 2)
require.Equal(t, []string{"a", "b"}, stmt.Cycle.Values)
stmt, err = ParseStatement(LoopStatementSelector, "x in array reversed offset: 2 limit: 3")
require.NoError(t, err)
require.Equal(t, "x", stmt.Loop.Variable)
require.True(t, stmt.Loop.Reversed)
require.Equal(t, 2, stmt.Loop.Offset)
require.NotNil(t, stmt.Loop.Limit)
require.Equal(t, 3, *stmt.Loop.Limit)
stmt, err = ParseStatement(WhenStatementSelector, "a, b")
require.NoError(t, err)
require.Len(t, stmt.When.Exprs, 2)
}