File: regexp_unit_test.rb

package info (click to toggle)
ruby-liquid 5.4.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,176 kB
  • sloc: ruby: 10,561; makefile: 6
file content (46 lines) | stat: -rw-r--r-- 1,649 bytes parent folder | download | duplicates (2)
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
# frozen_string_literal: true

require 'test_helper'

class RegexpUnitTest < Minitest::Test
  include Liquid

  def test_empty
    assert_equal([], ''.scan(QuotedFragment))
  end

  def test_quote
    assert_equal(['"arg 1"'], '"arg 1"'.scan(QuotedFragment))
  end

  def test_words
    assert_equal(['arg1', 'arg2'], 'arg1 arg2'.scan(QuotedFragment))
  end

  def test_tags
    assert_equal(['<tr>', '</tr>'], '<tr> </tr>'.scan(QuotedFragment))
    assert_equal(['<tr></tr>'], '<tr></tr>'.scan(QuotedFragment))
    assert_equal(['<style', 'class="hello">', '</style>'], %(<style class="hello">' </style>).scan(QuotedFragment))
  end

  def test_double_quoted_words
    assert_equal(['arg1', 'arg2', '"arg 3"'], 'arg1 arg2 "arg 3"'.scan(QuotedFragment))
  end

  def test_single_quoted_words
    assert_equal(['arg1', 'arg2', "'arg 3'"], 'arg1 arg2 \'arg 3\''.scan(QuotedFragment))
  end

  def test_quoted_words_in_the_middle
    assert_equal(['arg1', 'arg2', '"arg 3"', 'arg4'], 'arg1 arg2 "arg 3" arg4   '.scan(QuotedFragment))
  end

  def test_variable_parser
    assert_equal(['var'],                               'var'.scan(VariableParser))
    assert_equal(['var', 'method'],                     'var.method'.scan(VariableParser))
    assert_equal(['var', '[method]'],                   'var[method]'.scan(VariableParser))
    assert_equal(['var', '[method]', '[0]'],            'var[method][0]'.scan(VariableParser))
    assert_equal(['var', '["method"]', '[0]'],          'var["method"][0]'.scan(VariableParser))
    assert_equal(['var', '[method]', '[0]', 'method'],  'var[method][0].method'.scan(VariableParser))
  end
end # RegexpTest