public void ChooseRendering_RuleApplies_MultiWordTermMatch() { var selectRenderingEndingInBAfterWith = new RenderingSelectionRule(@"Why {0}", @"b$"); Assert.AreEqual("Renderingb", selectRenderingEndingInBAfterWith.ChooseRendering( "Why even - bother - with Mark?", new Word[] { "even", "bother", "with" }, new[] { "Renderinga", "Renderingb" })); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handles the Click event of the btnEdit control. /// </summary> /// ------------------------------------------------------------------------------------ private void btnEdit_Click(object sender, EventArgs e) { RenderingSelectionRule rule = m_listRules.SelectedItem as RenderingSelectionRule; string origName = rule.Name; string origQ = rule.QuestionMatchingPattern; string origR = rule.RenderingMatchingPattern; Func <string, bool> nameIsUnique = n => !m_listRules.Items.Cast <RenderingSelectionRule>().Where(r => r != rule).Any(r => r.Name == n); using (RulesWizardDlg dlg = new RulesWizardDlg(rule, Word.AllWords, m_selectKeyboard, nameIsUnique)) { if (dlg.ShowDialog(this) == DialogResult.OK) { if (!rule.Valid) { m_listRules.SetItemChecked(m_listRules.SelectedIndex, false); } m_listRules.Invalidate(); } else { rule.Name = origName; rule.QuestionMatchingPattern = origQ; rule.RenderingMatchingPattern = origR; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handles the Click event of the btnNew control. /// </summary> /// ------------------------------------------------------------------------------------ private void btnNew_Click(object sender, System.EventArgs e) { int i = 1; string name = string.Format(Properties.Resources.kstidNewSelectionRuleNameTemplate, i); Func <string, bool> nameIsUnique = n => !m_listRules.Items.Cast <RenderingSelectionRule>().Any(r => r.Name == n); while (!nameIsUnique(name)) { name = string.Format(Properties.Resources.kstidNewSelectionRuleNameTemplate, ++i); } RenderingSelectionRule rule = new RenderingSelectionRule(name); using (RulesWizardDlg dlg = new RulesWizardDlg(rule, Word.AllWords, m_selectKeyboard, nameIsUnique)) { if (dlg.ShowDialog(this) == DialogResult.OK) { m_listRules.SelectedIndex = m_listRules.Items.Add(rule); if (rule.Valid) { m_listRules.SetItemChecked(m_listRules.SelectedIndex, true); } } } }
public void ChooseRendering_RuleDoesNotApply_TermNotInQuestion() { var selectRenderingEndingInAAfterXyz = new RenderingSelectionRule(@"\bwith {0}", @"a$"); Assert.IsNull(selectRenderingEndingInAAfterXyz.ChooseRendering( "Why even bother with a dude named Mark?", new Word[] { "Mark" }, new[] { "Renderinga", "Renderingb" })); }
public void ChooseRendering_InvalidRenderingMatchExpr_BadRegex() { var bogusRule = new RenderingSelectionRule(@"about\b {0}", @"a)"); Assert.IsNull(bogusRule.ChooseRendering( "Is this a question about Mark?", new Word[] { "Mark" }, new[] { "Renderinga", "Renderingb" })); }
public void ChooseRendering_RuleApplies_RenderingMatchNotFound() { var selectRenderingEndingInCAfterWith = new RenderingSelectionRule(@"\bwith\b {0}", @"c$"); Assert.IsNull(selectRenderingEndingInCAfterWith.ChooseRendering( "Why even bother with Mark?", new Word[] { "Mark" }, new[] { "Renderinga", "Renderingb" })); }
public void ChooseRendering_InvalidQuestionMatchExpr_NoKeyTermPlaceholder() { var bogusRule = new RenderingSelectionRule(@"\bxyz\b", "a$"); Assert.IsNull(bogusRule.ChooseRendering( "Is this a question about xyz?", new Word[] { "Mark" }, new[] { "Renderinga", "Renderingb" })); }
public void ChooseRendering_RuleApplies_RenderingMatchFound_Suffix() { var selectRenderingEndingInBAfterWith = new RenderingSelectionRule(@"{0}\w*ed\b", "o\u0301$"); Assert.AreEqual("sano\u0301", selectRenderingEndingInBAfterWith.ChooseRendering( "Was the woman healed?", new Word[] { "heal" }, new[] { "sanaba", "sano\u0301", "curaba", "curo\u0301" })); }
public void ChooseRendering_RuleApplies_RenderingMatchFound_PrecedingWord() { var selectRenderingEndingInBAfterWith = new RenderingSelectionRule(@"\bwith {0}", @"b$"); Assert.AreEqual("Renderingb", selectRenderingEndingInBAfterWith.ChooseRendering( "Why even bother with Mark?", new Word[] { "Mark" }, new[] { "Renderinga", "Renderingb" })); }
public void ChooseRendering_RuleApplies_RenderingMatchFound_FollowingWord() { var selectRenderingEndingInBAfterWith = new RenderingSelectionRule(@"{0} for\b", @"b$"); Assert.AreEqual("Renderingb", selectRenderingEndingInBAfterWith.ChooseRendering( "Was Mark for or against discipleship?", new Word[] { "Mark" }, new[] { "bob Renderinga", "Renderingb" })); }
public void ChooseRendering_RuleApplies_RenderingMatchFound_Prefix() { var selectRenderingEndingInBAfterWith = new RenderingSelectionRule(@"\bpre\w*{0}", @"^pre"); Assert.AreEqual("preRendering", selectRenderingEndingInBAfterWith.ChooseRendering( "What is a prebaptism ceremony?", new Word[] { "bapt" }, new[] { "unRendering preacher", "preRendering", "antiRendering" })); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handles the Click event of the btnCopy control. /// </summary> /// ------------------------------------------------------------------------------------ private void btnCopy_Click(object sender, EventArgs e) { int iOrigRule = m_listRules.SelectedIndex; RenderingSelectionRule origRule = m_listRules.SelectedItem as RenderingSelectionRule; RenderingSelectionRule newRule = new RenderingSelectionRule(origRule.QuestionMatchingPattern, origRule.RenderingMatchingPattern); int i = 1; string name = string.Format(Properties.Resources.kstidCopiedSelectionRuleNameTemplate, origRule.Name, string.Empty); Func <string, bool> nameIsUnique = n => !m_listRules.Items.Cast <RenderingSelectionRule>().Any(r => r.Name == n); while (!nameIsUnique(name)) { name = string.Format(Properties.Resources.kstidCopiedSelectionRuleNameTemplate, origRule.Name, "(" + i++ + ")"); } newRule.Name = name; using (RulesWizardDlg dlg = new RulesWizardDlg(newRule, Word.AllWords, m_selectKeyboard, nameIsUnique)) { if (dlg.ShowDialog(this) == DialogResult.OK) { m_listRules.SelectedIndex = m_listRules.Items.Add(newRule); if (newRule.Valid) { m_listRules.SetItemChecked(m_listRules.SelectedIndex, m_listRules.GetItemChecked(iOrigRule)); } } } }
public void GetRenderingMatchType_Custom() { var rule = new RenderingSelectionRule(@"{0} after\b", " "); Assert.AreEqual(RenderingSelectionRule.RenderingMatchType.Custom, rule.RenderingMatchCriteriaType); Assert.IsNull(rule.RenderingMatchSuffix); Assert.IsNull(rule.RenderingMatchPrefix); Assert.AreEqual(" ", rule.RenderingMatchingPattern); }
private void m_listRules_SelectedIndexChanged(object sender, System.EventArgs e) { RenderingSelectionRule rule = m_listRules.SelectedItem as RenderingSelectionRule; btnEdit.Enabled = btnCopy.Enabled = btnDelete.Enabled = (rule != null); if (rule != null) { m_lblDescription.Text = rule.Description; } }
public void GetQuestionMatchType_Custom() { var rule = new RenderingSelectionRule(@"\bbefore {0} after\b", "ation$"); Assert.AreEqual(RenderingSelectionRule.QuestionMatchType.Custom, rule.QuestionMatchCriteriaType); Assert.IsNull(rule.QuestionMatchSuffix); Assert.IsNull(rule.QuestionMatchPrefix); Assert.IsNull(rule.QuestionMatchPrecedingWord); Assert.IsNull(rule.QuestionMatchFollowingWord); Assert.AreEqual(@"\bbefore {0} after\b", rule.QuestionMatchingPattern); }
public void SetQuestionMatchSuffix() { var rule = new RenderingSelectionRule(); Assert.AreEqual(RenderingSelectionRule.QuestionMatchType.Undefined, rule.QuestionMatchCriteriaType); Assert.IsNull(rule.QuestionMatchSuffix); Assert.IsNull(rule.QuestionMatchingPattern); rule.QuestionMatchSuffix = "post"; Assert.AreEqual(RenderingSelectionRule.QuestionMatchType.Suffix, rule.QuestionMatchCriteriaType); Assert.AreEqual("post", rule.QuestionMatchSuffix); Assert.AreEqual(@"{0}\w*post\b", rule.QuestionMatchingPattern); rule.QuestionMatchSuffix = string.Empty; Assert.AreEqual(RenderingSelectionRule.QuestionMatchType.Undefined, rule.QuestionMatchCriteriaType); Assert.IsNull(rule.QuestionMatchSuffix); Assert.IsNull(rule.QuestionMatchingPattern); }
public void SetQuestionMatchPrecedingWord() { var rule = new RenderingSelectionRule(); Assert.AreEqual(RenderingSelectionRule.QuestionMatchType.Undefined, rule.QuestionMatchCriteriaType); Assert.IsNull(rule.QuestionMatchPrecedingWord); Assert.IsNull(rule.QuestionMatchingPattern); rule.QuestionMatchPrecedingWord = "before"; Assert.AreEqual(RenderingSelectionRule.QuestionMatchType.PrecedingWord, rule.QuestionMatchCriteriaType); Assert.AreEqual("before", rule.QuestionMatchPrecedingWord); Assert.AreEqual(@"\bbefore {0}", rule.QuestionMatchingPattern); rule.QuestionMatchPrecedingWord = string.Empty; Assert.AreEqual(RenderingSelectionRule.QuestionMatchType.Undefined, rule.QuestionMatchCriteriaType); Assert.IsNull(rule.QuestionMatchPrecedingWord); Assert.IsNull(rule.QuestionMatchingPattern); }
public void SetQuestionMatchFollowingWord() { var rule = new RenderingSelectionRule(); Assert.AreEqual(RenderingSelectionRule.QuestionMatchType.Undefined, rule.QuestionMatchCriteriaType); Assert.IsNull(rule.QuestionMatchFollowingWord); Assert.IsNull(rule.QuestionMatchingPattern); rule.QuestionMatchFollowingWord = "after"; Assert.AreEqual(RenderingSelectionRule.QuestionMatchType.FollowingWord, rule.QuestionMatchCriteriaType); Assert.AreEqual("after", rule.QuestionMatchFollowingWord); Assert.AreEqual(@"{0} after\b", rule.QuestionMatchingPattern); rule.QuestionMatchFollowingWord = string.Empty; Assert.AreEqual(RenderingSelectionRule.QuestionMatchType.Undefined, rule.QuestionMatchCriteriaType); Assert.IsNull(rule.QuestionMatchFollowingWord); Assert.IsNull(rule.QuestionMatchingPattern); }
public void SetRenderingMatchPrefix() { var rule = new RenderingSelectionRule(); Assert.AreEqual(RenderingSelectionRule.RenderingMatchType.Undefined, rule.RenderingMatchCriteriaType); Assert.IsNull(rule.RenderingMatchPrefix); Assert.IsNull(rule.RenderingMatchingPattern); rule.RenderingMatchPrefix = "pre"; Assert.AreEqual(RenderingSelectionRule.RenderingMatchType.Prefix, rule.RenderingMatchCriteriaType); Assert.AreEqual("pre", rule.RenderingMatchPrefix); Assert.AreEqual("^pre", rule.RenderingMatchingPattern); rule.RenderingMatchPrefix = string.Empty; Assert.AreEqual(RenderingSelectionRule.RenderingMatchType.Undefined, rule.RenderingMatchCriteriaType); Assert.IsNull(rule.RenderingMatchPrefix); Assert.IsNull(rule.RenderingMatchingPattern); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handles the Click event of the btnNew control. /// </summary> /// ------------------------------------------------------------------------------------ private void btnNew_Click(object sender, System.EventArgs e) { int i = 1; string name = string.Format(Properties.Resources.kstidNewSelectionRuleNameTemplate, i); Func<string, bool> nameIsUnique = n => !m_listRules.Items.Cast<RenderingSelectionRule>().Any(r => r.Name == n); while (!nameIsUnique(name)) name = string.Format(Properties.Resources.kstidNewSelectionRuleNameTemplate, ++i); RenderingSelectionRule rule = new RenderingSelectionRule(name); using (RulesWizardDlg dlg = new RulesWizardDlg(rule, Word.AllWords, m_selectKeyboard, nameIsUnique)) { if (dlg.ShowDialog(this) == DialogResult.OK) { m_listRules.SelectedIndex = m_listRules.Items.Add(rule); if (rule.Valid) m_listRules.SetItemChecked(m_listRules.SelectedIndex, true); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:RulesWizardDlg"/> class. /// </summary> /// ------------------------------------------------------------------------------------ public RulesWizardDlg(RenderingSelectionRule rule, IEnumerable <string> allWordsInQuestions, Action <bool> selectKeyboard, Func <string, bool> nameValidator) { InitializeComponent(); m_rdoSuffix.Tag = m_pnlSuffixDetails; m_rdoPrefix.Tag = m_pnlPrefixDetails; m_rdoPreceedingWord.Tag = m_pnlPrecedingWordDetails; m_rdoFollowingWord.Tag = m_pnlFollowingWordDetails; m_rdoUserDefinedQuestionCriteria.Tag = m_pnlUserDefinedRuleDetails; m_rdoRenderingHasSuffix.Tag = m_pnlVernacularSuffix; m_rdoRenderingHasPrefix.Tag = m_pnlVernacularPrefix; m_rdoUserDefinedRenderingCriteria.Tag = m_pnlUserDefinedRenderingMatch; foreach (string word in allWordsInQuestions) { m_cboFollowingWord.Items.Add(word); m_cboPrecedingWord.Items.Add(word); } m_rule = rule; m_selectKeyboard = selectKeyboard; ValidateName = nameValidator; m_txtName.Text = m_rule.Name; switch (m_rule.QuestionMatchCriteriaType) { case RenderingSelectionRule.QuestionMatchType.Undefined: Text = Properties.Resources.kstidEditRuleCaption; m_rdoSuffix.Checked = true; // default; //SetDetails(m_cboSuffix, string.Empty); return; case RenderingSelectionRule.QuestionMatchType.Suffix: m_rdoSuffix.Checked = true; SetDetails(m_cboSuffix, m_rule.QuestionMatchSuffix); break; case RenderingSelectionRule.QuestionMatchType.Prefix: m_rdoPrefix.Checked = true; SetDetails(m_cboPrefix, m_rule.QuestionMatchPrefix); break; case RenderingSelectionRule.QuestionMatchType.PrecedingWord: m_rdoPreceedingWord.Checked = true; SetDetails(m_cboPrecedingWord, m_rule.QuestionMatchPrecedingWord); break; case RenderingSelectionRule.QuestionMatchType.FollowingWord: m_rdoFollowingWord.Checked = true; SetDetails(m_cboFollowingWord, m_rule.QuestionMatchFollowingWord); break; case RenderingSelectionRule.QuestionMatchType.Custom: m_rdoUserDefinedQuestionCriteria.Checked = true; m_txtQuestionMatchRegEx.Text = m_rule.QuestionMatchingPattern; break; } switch (m_rule.RenderingMatchCriteriaType) { case RenderingSelectionRule.RenderingMatchType.Undefined: // default case RenderingSelectionRule.RenderingMatchType.Suffix: m_rdoRenderingHasSuffix.Checked = true; m_txtVernacularSuffix.Text = m_rule.RenderingMatchSuffix; break; case RenderingSelectionRule.RenderingMatchType.Prefix: m_txtVernacularPrefix.Text = m_rule.RenderingMatchPrefix; break; case RenderingSelectionRule.RenderingMatchType.Custom: m_txtRenderingMatchRegEx.Text = m_rule.RenderingMatchingPattern; break; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:RulesWizardDlg"/> class. /// </summary> /// ------------------------------------------------------------------------------------ public RulesWizardDlg(RenderingSelectionRule rule, IEnumerable<string> allWordsInQuestions, Action<bool> selectKeyboard, Func<string, bool> nameValidator) { InitializeComponent(); m_rdoSuffix.Tag = m_pnlSuffixDetails; m_rdoPrefix.Tag = m_pnlPrefixDetails; m_rdoPreceedingWord.Tag = m_pnlPrecedingWordDetails; m_rdoFollowingWord.Tag = m_pnlFollowingWordDetails; m_rdoUserDefinedQuestionCriteria.Tag = m_pnlUserDefinedRuleDetails; m_rdoRenderingHasSuffix.Tag = m_pnlVernacularSuffix; m_rdoRenderingHasPrefix.Tag = m_pnlVernacularPrefix; m_rdoUserDefinedRenderingCriteria.Tag = m_pnlUserDefinedRenderingMatch; foreach (string word in allWordsInQuestions) { m_cboFollowingWord.Items.Add(word); m_cboPrecedingWord.Items.Add(word); } m_rule = rule; m_selectKeyboard = selectKeyboard; ValidateName = nameValidator; m_txtName.Text = m_rule.Name; switch (m_rule.QuestionMatchCriteriaType) { case RenderingSelectionRule.QuestionMatchType.Undefined: Text = Properties.Resources.kstidEditRuleCaption; m_rdoSuffix.Checked = true; // default; //SetDetails(m_cboSuffix, string.Empty); return; case RenderingSelectionRule.QuestionMatchType.Suffix: m_rdoSuffix.Checked = true; SetDetails(m_cboSuffix, m_rule.QuestionMatchSuffix); break; case RenderingSelectionRule.QuestionMatchType.Prefix: m_rdoPrefix.Checked = true; SetDetails(m_cboPrefix, m_rule.QuestionMatchPrefix); break; case RenderingSelectionRule.QuestionMatchType.PrecedingWord: m_rdoPreceedingWord.Checked = true; SetDetails(m_cboPrecedingWord, m_rule.QuestionMatchPrecedingWord); break; case RenderingSelectionRule.QuestionMatchType.FollowingWord: m_rdoFollowingWord.Checked = true; SetDetails(m_cboFollowingWord, m_rule.QuestionMatchFollowingWord); break; case RenderingSelectionRule.QuestionMatchType.Custom: m_rdoUserDefinedQuestionCriteria.Checked = true; m_txtQuestionMatchRegEx.Text = m_rule.QuestionMatchingPattern; break; } switch (m_rule.RenderingMatchCriteriaType) { case RenderingSelectionRule.RenderingMatchType.Undefined: // default case RenderingSelectionRule.RenderingMatchType.Suffix: m_rdoRenderingHasSuffix.Checked = true; m_txtVernacularSuffix.Text = m_rule.RenderingMatchSuffix; break; case RenderingSelectionRule.RenderingMatchType.Prefix: m_txtVernacularPrefix.Text = m_rule.RenderingMatchPrefix; break; case RenderingSelectionRule.RenderingMatchType.Custom: m_txtRenderingMatchRegEx.Text = m_rule.RenderingMatchingPattern; break; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handles the Click event of the btnCopy control. /// </summary> /// ------------------------------------------------------------------------------------ private void btnCopy_Click(object sender, EventArgs e) { int iOrigRule = m_listRules.SelectedIndex; RenderingSelectionRule origRule = m_listRules.SelectedItem as RenderingSelectionRule; RenderingSelectionRule newRule = new RenderingSelectionRule(origRule.QuestionMatchingPattern, origRule.RenderingMatchingPattern); int i = 1; string name = string.Format(Properties.Resources.kstidCopiedSelectionRuleNameTemplate, origRule.Name, string.Empty); Func<string, bool> nameIsUnique = n => !m_listRules.Items.Cast<RenderingSelectionRule>().Any(r => r.Name == n); while (!nameIsUnique(name)) name = string.Format(Properties.Resources.kstidCopiedSelectionRuleNameTemplate, origRule.Name, "(" + i++ + ")"); newRule.Name = name; using (RulesWizardDlg dlg = new RulesWizardDlg(newRule, Word.AllWords, m_selectKeyboard, nameIsUnique)) { if (dlg.ShowDialog(this) == DialogResult.OK) { m_listRules.SelectedIndex = m_listRules.Items.Add(newRule); if (newRule.Valid) m_listRules.SetItemChecked(m_listRules.SelectedIndex, m_listRules.GetItemChecked(iOrigRule)); } } }