scribe/regexp.go

32 строки
806 B
Go
Исходник Постоянная ссылка Обычный вид История

2015-07-07 12:02:58 +03:00
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Contributor:
// - Aaron Meihm ameihm@mozilla.com
2015-07-14 07:34:50 +03:00
2015-07-07 12:02:58 +03:00
package scribe
import (
"regexp"
)
2017-07-19 18:55:45 +03:00
// Regex is used to specify regular expression matching criteria within a test.
type Regex struct {
2016-03-22 00:36:07 +03:00
Value string `json:"value,omitempty" yaml:"value,omitempty"`
2015-07-07 12:02:58 +03:00
}
func (r *Regex) evaluate(c evaluationCriteria) (ret evaluationResult, err error) {
2015-07-07 20:14:32 +03:00
var re *regexp.Regexp
debugPrint("evaluate(): regexp %v \"%v\", \"%v\"\n", c.identifier, c.testValue, r.Value)
2015-07-07 20:14:32 +03:00
re, err = regexp.Compile(r.Value)
if err != nil {
return
}
ret.criteria = c
if re.MatchString(c.testValue) {
ret.result = true
}
return
}