Documentation ¶
Index ¶
- Variables
- func HasAllWords(env utils.Environment, text types.XText, test types.XText) types.XValue
- func HasAnyWord(env utils.Environment, text types.XText, test types.XText) types.XValue
- func HasBeginning(env utils.Environment, text types.XText, beginning types.XText) types.XValue
- func HasDate(env utils.Environment, text types.XText) types.XValue
- func HasDateEQ(env utils.Environment, text types.XText, date types.XDateTime) types.XValue
- func HasDateGT(env utils.Environment, text types.XText, date types.XDateTime) types.XValue
- func HasDateLT(env utils.Environment, text types.XText, date types.XDateTime) types.XValue
- func HasDistrict(env utils.Environment, args ...types.XValue) types.XValue
- func HasEmail(env utils.Environment, text types.XText) types.XValue
- func HasGroup(env utils.Environment, arg1 types.XValue, arg2 types.XValue) types.XValue
- func HasNumber(env utils.Environment, text types.XText) types.XValue
- func HasNumberBetween(env utils.Environment, arg1 types.XValue, arg2 types.XValue, arg3 types.XValue) types.XValue
- func HasNumberEQ(env utils.Environment, text types.XText, num types.XNumber) types.XValue
- func HasNumberGT(env utils.Environment, text types.XText, num types.XNumber) types.XValue
- func HasNumberGTE(env utils.Environment, text types.XText, num types.XNumber) types.XValue
- func HasNumberLT(env utils.Environment, text types.XText, num types.XNumber) types.XValue
- func HasNumberLTE(env utils.Environment, text types.XText, num types.XNumber) types.XValue
- func HasOnlyPhrase(env utils.Environment, text types.XText, test types.XText) types.XValue
- func HasPattern(env utils.Environment, text types.XText, pattern types.XText) types.XValue
- func HasPhone(env utils.Environment, text types.XText, args ...types.XValue) types.XValue
- func HasPhrase(env utils.Environment, text types.XText, test types.XText) types.XValue
- func HasState(env utils.Environment, text types.XText) types.XValue
- func HasText(env utils.Environment, text types.XText) types.XValue
- func HasTime(env utils.Environment, text types.XText) types.XValue
- func HasValue(env utils.Environment, value types.XValue) types.XValue
- func HasWard(env utils.Environment, args ...types.XValue) types.XValue
- func IsError(env utils.Environment, value types.XValue) types.XValue
- func IsTextEQ(env utils.Environment, text1 types.XText, text2 types.XText) types.XValue
- func NewTrueResult(match types.XValue) *types.XDict
- func NewTrueResultWithExtra(match types.XValue, extra *types.XDict) *types.XDict
- func ParseDecimalFuzzy(val string, format *utils.NumberFormat) (decimal.Decimal, error)
- func RegisterXTest(name string, function types.XFunction)
Constants ¶
This section is empty.
Variables ¶
var XTESTS = map[string]types.XFunction{ "is_error": functions.OneArgFunction(IsError), "has_value": functions.OneArgFunction(HasValue), "is_text_eq": functions.TwoTextFunction(IsTextEQ), "has_phrase": functions.TwoTextFunction(HasPhrase), "has_only_phrase": functions.TwoTextFunction(HasOnlyPhrase), "has_any_word": functions.TwoTextFunction(HasAnyWord), "has_all_words": functions.TwoTextFunction(HasAllWords), "has_beginning": functions.TwoTextFunction(HasBeginning), "has_text": functions.OneTextFunction(HasText), "has_pattern": functions.TwoTextFunction(HasPattern), "has_number": functions.OneTextFunction(HasNumber), "has_number_between": functions.ThreeArgFunction(HasNumberBetween), "has_number_lt": functions.TextAndNumberFunction(HasNumberLT), "has_number_lte": functions.TextAndNumberFunction(HasNumberLTE), "has_number_eq": functions.TextAndNumberFunction(HasNumberEQ), "has_number_gte": functions.TextAndNumberFunction(HasNumberGTE), "has_number_gt": functions.TextAndNumberFunction(HasNumberGT), "has_date": functions.OneTextFunction(HasDate), "has_date_lt": functions.TextAndDateFunction(HasDateLT), "has_date_eq": functions.TextAndDateFunction(HasDateEQ), "has_date_gt": functions.TextAndDateFunction(HasDateGT), "has_time": functions.OneTextFunction(HasTime), "has_phone": functions.InitialTextFunction(0, 1, HasPhone), "has_email": functions.OneTextFunction(HasEmail), "has_group": functions.TwoArgFunction(HasGroup), "has_state": functions.OneTextFunction(HasState), "has_district": HasDistrict, "has_ward": HasWard, }
XTESTS is our mapping of the excellent test names to their actual functions
Functions ¶
func HasAllWords ¶
HasAllWords tests whether all the `words` are contained in `text`
The words can be in any order and may appear more than once.
@(has_all_words("the quick brown FOX", "the fox")) -> {match: the FOX} @(has_all_words("the quick brown fox", "red fox")) ->
@test has_all_words(text, words)
func HasAnyWord ¶
HasAnyWord tests whether any of the `words` are contained in the `text`
Only one of the words needs to match and it may appear more than once.
@(has_any_word("The Quick Brown Fox", "fox quick")) -> {match: Quick Fox} @(has_any_word("The Quick Brown Fox", "red fox")) -> {match: Fox}
@test has_any_word(text, words)
func HasBeginning ¶
HasBeginning tests whether `text` starts with `beginning`
Both text values are trimmed of surrounding whitespace, but otherwise matching is strict without any tokenization.
@(has_beginning("The Quick Brown", "the quick")) -> {match: The Quick} @(has_beginning("The Quick Brown", "the quick")) -> @(has_beginning("The Quick Brown", "quick brown")) ->
@test has_beginning(text, beginning)
func HasDate ¶
HasDate tests whether `text` contains a date formatted according to our environment
@(has_date("the date is 2017-01-15")) -> {match: 2017-01-15T13:24:30.123456-05:00} @(has_date("there is no date here, just a year 2017")) ->
@test has_date(text)
func HasDateEQ ¶
HasDateEQ tests whether `text` a date equal to `date`
@(has_date_eq("the date is 2017-01-15", "2017-01-15")) -> {match: 2017-01-15T13:24:30.123456-05:00} @(has_date_eq("the date is 2017-01-15 15:00", "2017-01-15")) -> {match: 2017-01-15T15:00:00.000000-05:00} @(has_date_eq("there is no date here, just a year 2017", "2017-06-01")) -> @(has_date_eq("there is no date here, just a year 2017", "not date")) -> ERROR
@test has_date_eq(text, date)
func HasDateGT ¶
HasDateGT tests whether `text` a date after the date `min`
@(has_date_gt("the date is 2017-01-15", "2017-01-01")) -> {match: 2017-01-15T13:24:30.123456-05:00} @(has_date_gt("the date is 2017-01-15", "2017-03-15")) -> @(has_date_gt("there is no date here, just a year 2017", "2017-06-01")) -> @(has_date_gt("there is no date here, just a year 2017", "not date")) -> ERROR
@test has_date_gt(text, min)
func HasDateLT ¶
HasDateLT tests whether `text` contains a date before the date `max`
@(has_date_lt("the date is 2017-01-15", "2017-06-01")) -> {match: 2017-01-15T13:24:30.123456-05:00} @(has_date_lt("there is no date here, just a year 2017", "2017-06-01")) -> @(has_date_lt("there is no date here, just a year 2017", "not date")) -> ERROR
@test has_date_lt(text, max)
func HasDistrict ¶
HasDistrict tests whether a district name is contained in the `text`. If `state` is also provided then the returned district must be within that state.
@(has_district("Gasabo", "Kigali")) -> {match: Rwanda > Kigali City > Gasabo} @(has_district("I live in Gasabo", "Kigali")) -> {match: Rwanda > Kigali City > Gasabo} @(has_district("Gasabo", "Boston")) -> @(has_district("Gasabo")) -> {match: Rwanda > Kigali City > Gasabo}
@test has_district(text, state)
func HasEmail ¶
HasEmail tests whether an email is contained in `text`
@(has_email("my email is foo1@bar.com, please respond")) -> {match: foo1@bar.com} @(has_email("my email is <foo@bar2.com>")) -> {match: foo@bar2.com} @(has_email("i'm not sharing my email")) ->
@test has_email(text)
func HasGroup ¶
HasGroup returns whether the `contact` is part of group with the passed in UUID
@(has_group(contact.groups, "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d")) -> {match: {name: Testers, uuid: b7cf0d83-f1c9-411c-96fd-c511a4cfa86d}} @(has_group(array(), "97fe7029-3a15-4005-b0c7-277b884fc1d5")) ->
@test has_group(contact, group_uuid)
func HasNumber ¶
HasNumber tests whether `text` contains a number
@(has_number("the number is 42")) -> {match: 42} @(has_number("the number is forty two")) ->
@test has_number(text)
func HasNumberBetween ¶
func HasNumberBetween(env utils.Environment, arg1 types.XValue, arg2 types.XValue, arg3 types.XValue) types.XValue
HasNumberBetween tests whether `text` contains a number between `min` and `max` inclusive
@(has_number_between("the number is 42", 40, 44)) -> {match: 42} @(has_number_between("the number is 42", 50, 60)) -> @(has_number_between("the number is not there", 50, 60)) -> @(has_number_between("the number is not there", "foo", 60)) -> ERROR
@test has_number_between(text, min, max)
func HasNumberEQ ¶
HasNumberEQ tests whether `text` contains a number equal to the `value`
@(has_number_eq("the number is 42", 42)) -> {match: 42} @(has_number_eq("the number is 42", 40)) -> @(has_number_eq("the number is not there", 40)) -> @(has_number_eq("the number is not there", "foo")) -> ERROR
@test has_number_eq(text, value)
func HasNumberGT ¶
HasNumberGT tests whether `text` contains a number greater than `min`
@(has_number_gt("the number is 42", 40)) -> {match: 42} @(has_number_gt("the number is 42", 42)) -> @(has_number_gt("the number is not there", 40)) -> @(has_number_gt("the number is not there", "foo")) -> ERROR
@test has_number_gt(text, min)
func HasNumberGTE ¶
HasNumberGTE tests whether `text` contains a number greater than or equal to `min`
@(has_number_gte("the number is 42", 42)) -> {match: 42} @(has_number_gte("the number is 42", 45)) -> @(has_number_gte("the number is not there", 40)) -> @(has_number_gte("the number is not there", "foo")) -> ERROR
@test has_number_gte(text, min)
func HasNumberLT ¶
HasNumberLT tests whether `text` contains a number less than `max`
@(has_number_lt("the number is 42", 44)) -> {match: 42} @(has_number_lt("the number is 42", 40)) -> @(has_number_lt("the number is not there", 40)) -> @(has_number_lt("the number is not there", "foo")) -> ERROR
@test has_number_lt(text, max)
func HasNumberLTE ¶
HasNumberLTE tests whether `text` contains a number less than or equal to `max`
@(has_number_lte("the number is 42", 42)) -> {match: 42} @(has_number_lte("the number is 42", 40)) -> @(has_number_lte("the number is not there", 40)) -> @(has_number_lte("the number is not there", "foo")) -> ERROR
@test has_number_lte(text, max)
func HasOnlyPhrase ¶
HasOnlyPhrase tests whether the `text` contains only `phrase`
The phrase must be the only text in the text to match
@(has_only_phrase("The Quick Brown Fox", "quick brown")) -> @(has_only_phrase("Quick Brown", "quick brown")) -> {match: Quick Brown} @(has_only_phrase("the Quick Brown fox", "")) -> @(has_only_phrase("", "")) -> {match: } @(has_only_phrase("The Quick Brown Fox", "red fox")) ->
@test has_only_phrase(text, phrase)
func HasPattern ¶
HasPattern tests whether `text` matches the regex `pattern`
Both text values are trimmed of surrounding whitespace and matching is case-insensitive.
@(has_pattern("Sell cheese please", "buy (\w+)")) -> @(has_pattern("Buy cheese please", "buy (\w+)")) -> {extra: {0: Buy cheese, 1: cheese}, match: Buy cheese}
@test has_pattern(text, pattern)
func HasPhone ¶
HasPhone tests whether `text` contains a phone number. The optional `country_code` argument specifies the country to use for parsing.
@(has_phone("my number is +12067799294")) -> {match: +12067799294} @(has_phone("my number is 2067799294", "US")) -> {match: +12067799294} @(has_phone("my number is 206 779 9294", "US")) -> {match: +12067799294} @(has_phone("my number is none of your business", "US")) ->
@test has_phone(text, country_code)
func HasPhrase ¶
HasPhrase tests whether `phrase` is contained in `text`
The words in the test phrase must appear in the same order with no other words in between.
@(has_phrase("the quick brown fox", "brown fox")) -> {match: brown fox} @(has_phrase("the Quick Brown fox", "quick fox")) -> @(has_phrase("the Quick Brown fox", "")) -> {match: }
@test has_phrase(text, phrase)
func HasState ¶
HasState tests whether a state name is contained in the `text`
@(has_state("Kigali")) -> {match: Rwanda > Kigali City} @(has_state("¡Kigali!")) -> {match: Rwanda > Kigali City} @(has_state("I live in Kigali")) -> {match: Rwanda > Kigali City} @(has_state("Boston")) ->
@test has_state(text)
func HasText ¶
HasText tests whether there the text has any characters in it
@(has_text("quick brown")) -> {match: quick brown} @(has_text("")) -> @(has_text(" \n")) -> @(has_text(123)) -> {match: 123} @(has_text(contact.fields.not_set)) ->
@test has_text(text)
func HasTime ¶
HasTime tests whether `text` contains a time.
@(has_time("the time is 10:30")) -> {match: 10:30:00.000000} @(has_time("the time is 10 PM")) -> {match: 22:00:00.000000} @(has_time("the time is 10:30:45")) -> {match: 10:30:45.000000} @(has_time("there is no time here, just the number 25")) ->
@test has_time(text)
func HasValue ¶
HasValue returns whether `value` is non-nil and not an error
Note that `contact.fields` and `run.results` are considered dynamic, so it is not an error to try to retrieve a value from fields or results which don't exist, rather these return an empty value.
@(has_value(datetime("foo"))) -> @(has_value(not.existing)) -> @(has_value(contact.fields.unset)) -> @(has_value("")) -> @(has_value("hello")) -> {match: hello}
@test has_value(value)
func HasWard ¶
HasWard tests whether a ward name is contained in the `text`
@(has_ward("Gisozi", "Gasabo", "Kigali")) -> {match: Rwanda > Kigali City > Gasabo > Gisozi} @(has_ward("I live in Gisozi", "Gasabo", "Kigali")) -> {match: Rwanda > Kigali City > Gasabo > Gisozi} @(has_ward("Gisozi", "Gasabo", "Brooklyn")) -> @(has_ward("Gisozi", "Brooklyn", "Kigali")) -> @(has_ward("Brooklyn", "Gasabo", "Kigali")) -> @(has_ward("Gasabo")) -> @(has_ward("Gisozi")) -> {match: Rwanda > Kigali City > Gasabo > Gisozi}
@test has_ward(text, district, state)
func IsError ¶
IsError returns whether `value` is an error
Note that `contact.fields` and `run.results` are considered dynamic, so it is not an error to try to retrieve a value from fields or results which don't exist, rather these return an empty value.
@(is_error(datetime("foo"))) -> {match: error calling DATETIME: unable to convert "foo" to a datetime} @(is_error(run.not.existing)) -> {match: dict has no property 'not'} @(is_error(contact.fields.unset)) -> {match: dict has no property 'unset'} @(is_error("hello")) ->
@test is_error(value)
func IsTextEQ ¶
IsTextEQ returns whether two text values are equal (case sensitive). In the case that they are, it will return the text as the match.
@(is_text_eq("foo", "foo")) -> {match: foo} @(is_text_eq("foo", "FOO")) -> @(is_text_eq("foo", "bar")) -> @(is_text_eq("foo", " foo ")) -> @(is_text_eq(run.status, "completed")) -> {match: completed} @(is_text_eq(results.webhook.category, "Success")) -> {match: Success} @(is_text_eq(results.webhook.category, "Failure")) ->
@test is_text_eq(text1, text2)
func NewTrueResult ¶
NewTrueResult creates a new true result with a match
func NewTrueResultWithExtra ¶
NewTrueResultWithExtra creates a new true result with a match and extra
func ParseDecimalFuzzy ¶
ParseDecimalFuzzy parses a decimal from a string
func RegisterXTest ¶
RegisterXTest registers a new router test (and Excellent function)
Types ¶
This section is empty.