// Split this out so we can inject a deterministic rand.Rand for testing. func rand_decider(val string, r *rand.Rand) string { f := func(s string) string { if options := splitDelimitedString(s); len(options) > 0 { return strings.TrimSpace(options[r.Intn(len(options))]) } // Previously r.Intn() was called even for errors so this makes // tests pass. I'll remove it in a future commit. r.Intn(4) return "<plugin error>" } return util.ApplyPluginFunction(val, "decide", f) }
func qd_plugin_lookup(qd *quoteDriver, val string, line *base.Line) string { f := func(s string) string { var quote *quotes.Quote if s == "" { quote = qd.GetPseudoRand("") } else if s[0] == '#' { if qid, err := strconv.Atoi(s[1:]); err == nil { quote = qd.GetByQID(qid) } } else { quote = qd.GetPseudoRand(s) } if quote == nil { return "<plugin error>" } return quote.Quote } return util.ApplyPluginFunction(val, "quote", f) }
// Split this out so we can inject a deterministic rand.Rand for testing. func rand_replacer(val string, r *rand.Rand) string { f := func(s string) string { return randomFloatAsString(s, r) } return util.ApplyPluginFunction(val, "rand", f) }