class Assert::Assertions::RegexMatch(PropertyType)

Overview

Validates a property matches a Regex pattern.

Optional Arguments

Example

class Example
  include Assert

  def initialize; end

  @[Assert::RegexMatch(pattern: /foo==bar/)]
  property match : String? = "foo==bar"

  @[Assert::RegexMatch(pattern: /foo==bar/, match: false)]
  property not_match : String = "foo--bar"

  @[Assert::RegexMatch(pattern: /^foo/, normalizer: ->(actual : String) { actual.strip })]
  property normalizer : String = " foo"
end

Example.new.valid? # => true

Defined in:

assertions/regex_match.cr

Constructors

Instance Method Summary

Instance methods inherited from class Assert::Assertions::Assertion

default_message_template : String default_message_template, groups : Array(String) groups, message : String message, message_template : String message_template, property_name : String property_name, valid? : Bool valid?

Constructor methods inherited from class Assert::Assertions::Assertion

new(property_name : String, message : String? = nil, groups : Array(String)? = nil) new

Constructor Detail

def self.new(property_name : String, actual : Union(String, Nil), pattern : Regex, match : Bool = true, normalizer : Proc(String, String)? = nil, message : String? = nil, groups : Array(String)? = nil) #

[View source]

Instance Method Detail

def default_message_template : String #

Returns the default #message_template to use if no message is provided.


[View source]
def message : String #

The message to display if self is not valid.

NOTE This method is defined automatically, and is just present for documentation purposes.


[View source]
def valid? : Bool #

Returns true if a property satisfies self, otherwise false.


[View source]