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
|
|
|
|
|
2015-07-07 13:19:12 +03:00
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
)
|
|
|
|
|
2017-07-19 18:55:45 +03:00
|
|
|
// Regex is used to specify regular expression matching criteria within a test.
|
2015-10-15 18:55:38 +03:00
|
|
|
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
|
|
|
}
|
2015-07-07 13:19:12 +03:00
|
|
|
|
2015-10-15 18:55:38 +03:00
|
|
|
func (r *Regex) evaluate(c evaluationCriteria) (ret evaluationResult, err error) {
|
2015-07-07 20:14:32 +03:00
|
|
|
var re *regexp.Regexp
|
2015-07-14 22:13:02 +03:00
|
|
|
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)
|
2015-07-07 13:19:12 +03:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2015-07-14 22:13:02 +03:00
|
|
|
ret.criteria = c
|
|
|
|
if re.MatchString(c.testValue) {
|
|
|
|
ret.result = true
|
2015-07-07 13:19:12 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|