We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

public
Description: object-oriented activerecord validations and machine/human formatting
Clone URL: git://github.com/cainlevy/semantic-attributes.git
cainlevy (author)
Tue Mar 18 18:30:11 -0700 2008
commit  555c2f8b647ea67c6c605f4d960a21ac0325d60b
tree    055b1af8932b5770855c516d7d98a7de2abbba5b
parent  fab2d0d80b72185e5c594080d5012c6b21254a72
semantic-attributes / test / unit / predicates / pattern_predicate_test.rb
100644 29 lines (23 sloc) 0.789 kb
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
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
 
class PatternPredicateTest < Test::Unit::TestCase
  def setup
    @predicate = Predicates::Pattern.new(:foo)
  end
 
  def test_regexp_pattern
    @predicate.like = /bar$/
 
    assert @predicate.validate('foobar', nil)
    assert @predicate.validate(:foobar, nil)
    assert !@predicate.validate('foobario', nil)
  end
 
  def test_string_pattern
    @predicate.like = 'bar'
 
    assert @predicate.validate('foobar', nil)
    assert @predicate.validate(:bar, nil)
  end
 
  def test_line_breaks
    @predicate.like = /^hello world$/
    assert @predicate.validate("malicious\nhello world\ntext", nil)
    @predicate.like = /\Ahello world\Z/
    assert !@predicate.validate("malicious\nhello world\ntext", nil)
  end
end