File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -68,7 +68,9 @@ def render_to_output_buffer(context, output)
6868 def variables_from_string ( markup )
6969 markup . split ( ',' ) . collect do |var |
7070 var =~ /\s *(#{ QuotedFragment } )\s */o
71- Regexp . last_match ( 1 ) ? parse_expression ( Regexp . last_match ( 1 ) ) : nil
71+ # Expression Parser returns cached objects, and we need to dup them to
72+ # start the cycle over for each new cycle call.
73+ Regexp . last_match ( 1 ) ? parse_expression ( Regexp . last_match ( 1 ) ) . dup : nil
7274 end . compact
7375 end
7476
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require 'test_helper'
4+
5+ class CycleTagTest < Minitest ::Test
6+ def test_simple_cycle
7+ template = <<~LIQUID
8+ {%- cycle '1', '2', '3' -%}
9+ {%- cycle '1', '2', '3' -%}
10+ {%- cycle '1', '2', '3' -%}
11+ LIQUID
12+
13+ assert_template_result ( "123" , template )
14+ end
15+
16+ def test_simple_cycle_inside_for_loop
17+ template = <<~LIQUID
18+ {%- for i in (1..3) -%}
19+ {% cycle '1', '2', '3' %}
20+ {%- endfor -%}
21+ LIQUID
22+
23+ assert_template_result ( "123" , template )
24+ end
25+
26+ def test_cycle_with_variables_inside_for_loop
27+ template = <<~LIQUID
28+ {%- assign a = 1 -%}
29+ {%- assign b = 2 -%}
30+ {%- assign c = 3 -%}
31+ {%- for i in (1..3) -%}
32+ {% cycle a, b, c %}
33+ {%- endfor -%}
34+ LIQUID
35+
36+ assert_template_result ( "123" , template )
37+ end
38+
39+ def test_cycle_tag_always_resets_cycle_at_0
40+ template = <<~LIQUID
41+ {%- assign a = "1" -%}
42+ {%- cycle a, "2" -%}
43+ {%- cycle a, "2" -%}
44+ LIQUID
45+
46+ assert_template_result ( "11" , template )
47+ end
48+ end
You can’t perform that action at this time.
0 commit comments