File: test_string.rb

package info (click to toggle)
ruby-ffaker 2.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,776 kB
  • sloc: ruby: 12,788; makefile: 8; sh: 1
file content (114 lines) | stat: -rw-r--r-- 3,203 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# frozen_string_literal: true

require_relative 'helper'

class TestString < Test::Unit::TestCase
  include DeterministicHelper

  FS = FFaker::String

  def test_atoms
    assert_equal 'abc', FS.from_regexp(/abc/)
    assert_deterministic { FS.from_regexp(/abc/) }
  end

  def test_digits
    assert_match(/\A\d\d\d\z/, FS.from_regexp(/\d\d\d/))
    assert_deterministic { FS.from_regexp(/\d\d\d/) }
  end

  def test_word_characters
    assert_match(/\A\w\w\w\z/, FS.from_regexp(/\w\w\w/))
    assert_deterministic { FS.from_regexp(/\w\w\w/) }
  end

  def test_word_range_character
    assert_match(/\A[a-z]\z/, FS.from_regexp(/[a-z]/))
    assert_deterministic { FS.from_regexp(/[a-z]/) }
  end

  def test_dash_character
    assert_match(/\A[a-z-]\z/, FS.from_regexp(/[a-z-]/))
    assert_match(/\A[a-]\z/, FS.from_regexp(/[a-]/))
    assert_match(/\A-\z/, FS.from_regexp(/-/))

    assert_deterministic { FS.from_regexp(/[a-z-]/) }
    assert_deterministic { FS.from_regexp(/[a-]/) }
    assert_deterministic { FS.from_regexp(/-/) }
  end

  def test_spaces
    assert_match(/\A\s\s\s\z/, FS.from_regexp(/\s\s\s/))
    assert_deterministic { FS.from_regexp(/\s\s\s/) }
  end

  def test_escaped_characters
    assert_equal '\\/.()[]{}', FS.from_regexp(%r{\\/\.\(\)\[\]\{\}})
    assert_deterministic { FS.from_regexp(%r|\\/\.\(\)\[\]\{\}|) }
  end

  def test_atom_sets
    assert_include %w[a b c], FS.from_regexp(/[abc]/)
    assert_deterministic { FS.from_regexp(/[abc]/) }
  end

  def test_special_sets
    assert_match(/\A[\s\d]\z/, FS.from_regexp(/[\s\d]/))
    assert_deterministic { FS.from_regexp(/[\s\d]/) }
  end

  def test_atom_question
    assert_match(/\Aa?\z/, FS.from_regexp(/a?/))
    assert_deterministic { FS.from_regexp(/a?/) }
  end

  def test_special_question
    assert_match(/\A\w?\z/, FS.from_regexp(/\w?/))
    assert_deterministic { FS.from_regexp(/\w?/) }
  end

  def test_set_question
    assert_match(/\A[abc]?\z/, FS.from_regexp(/[abc]?/))
    assert_deterministic { FS.from_regexp(/[abc]?/) }
  end

  def test_atom_plus
    assert_match(/\Aa+\z/, FS.from_regexp(/a+/))
    assert_deterministic { FS.from_regexp(/a+/) }
  end

  def test_special_plus
    assert_match(/\A\w+\z/, FS.from_regexp(/\w+/))
    assert_deterministic { FS.from_regexp(/\w+/) }
  end

  def test_set_plus
    assert_match(/\A[abc]+\z/, FS.from_regexp(/[abc]+/))
    assert_deterministic { FS.from_regexp(/[abc]+/) }
  end

  def test_atom_star
    assert_match(/\Aa*\z/, FS.from_regexp(/a*/))
    assert_deterministic { FS.from_regexp(/a*/) }
  end

  def test_special_star
    assert_match(/\A\w*\z/, FS.from_regexp(/\w*/))
    assert_deterministic { FS.from_regexp(/\w*/) }
  end

  def test_set_star
    assert_match(/\A[abc]*\z/, FS.from_regexp(/[abc]*/))
    assert_deterministic { FS.from_regexp(/[abc]*/) }
  end

  def test_braces
    assert_equal 'a' * 13, FS.from_regexp(/a{13}/)
    assert_match(/\A[abc]{13}\z/, FS.from_regexp(/[abc]{13}/))
    assert_match(/\A\w{13}\z/, FS.from_regexp(/\w{13}/))

    assert_deterministic { FS.from_regexp(/a{13}/) }
    assert_deterministic { FS.from_regexp(/[abc]{13}/) }
    assert_deterministic { FS.from_regexp(/\w{13}/) }
  end
end