예제 #1
0
        public void Transform_GIVEN_globalParseRule_For_StyleClass_WHEN_token_is_for_Bold_And_Is_Starting_Delimeter_With_No_Properties_THEN_Returns_HTML_For_Bold()
        {
            Token t = new Token(TokenType.Delimiter, "#b", 1, 1);
            t.IsStartingDelimeter = true;

            var parseRule = new DelimeterParseRule("Bold", DefaultDelimeterValues.Bold, "b");

            string html = parseRule.TransformToHtml(t, new PropertyParseRule[]{new StyleClassParseRule()});

            html.ShouldEqual("<b>");
        }
예제 #2
0
        public void Transform_GIVEN_globalParseRule_StyleClass_WHEN_token_is_for_Bold_And_Is_Starting_Delimeter_With_Property_For_StyleClass_With_Value_ABC_THEN_Returns_HTML_For_Bold_With_Class_Attribute()
        {
            const string CssClass = "ABC";

            dynamic t = new Token(TokenType.Delimiter, "#b", 1, 1);
            t.StyleClass = CssClass;
            t.IsStartingDelimeter = true;

            var parseRule = new DelimeterParseRule("Bold", DefaultDelimeterValues.Bold, "b");

            string html = parseRule.TransformToHtml(t, new PropertyParseRule[] { new StyleClassParseRule() });

            html.ShouldEqual(String.Format("<b class='{0}'>", CssClass));
        }
예제 #3
0
        public void Transform_GIVEN_globalParseRule_For_StyleClass_Which_Outputs_id_And_localParseRule_For_StyleClass_Which_Outputs_class_WHEN_Token_Is_For_Bold_THEN_Returns_Result_Of_LocalPropertyParseRule_Which_Is_Bold_With_Class_Attribute()
        {
            const string CssClass = "ABC";

            dynamic t = new Token(TokenType.Delimiter, "#b", 1, 1);
            t.StyleClass = CssClass;
            t.IsStartingDelimeter = true;

            var styleClassRule = new StyleClassParseRule();

            var parseRule = new DelimeterParseRule("Bold", DefaultDelimeterValues.Bold, "b");
            parseRule.AddPropertyParseRule(styleClassRule);

            string html = parseRule.TransformToHtml(t, new PropertyParseRule[] { new PropertyParseRule(styleClassRule.PropertyName, "id") });

            html.ShouldEqual(String.Format("<b class='{0}'>", CssClass));
        }
예제 #4
0
        public void Transform_WHEN_token_TokenType_Is_Not_Delimeter_THEN_Throws_InvalidOperationException()
        {
            Token t = new Token(TokenType.Text, "text", 1, 1);

            var parseRule = new DelimeterParseRule("Bold", DefaultDelimeterValues.Bold, "b");
            parseRule.TransformToHtml(t, new List<PropertyParseRule>(0));
        }
예제 #5
0
        public void Transform_WHEN_token_TokenType_Is_Delimeter_AND_Is_For_BOLD_And_Token_Is_For_Opening_Bold_THEN_Returns_HTML_To_Start_Bold()
        {
            Token t = new Token(TokenType.Delimiter, "#b", 1, 1);
            t.IsStartingDelimeter = true;

            var parseRule = new DelimeterParseRule("Bold", DefaultDelimeterValues.Bold, "b");
            string html = parseRule.TransformToHtml(t, new List<PropertyParseRule>(0));

            html.ShouldEqual("<b>");
        }
예제 #6
0
 public void Transform_WHEN_token_Is_Null_THEN_Throws_ArgumentNullException()
 {
     var parseRule = new DelimeterParseRule("Bold", DefaultDelimeterValues.Bold, "b");
     parseRule.TransformToHtml(null, new List<PropertyParseRule>(0));
 }
예제 #7
0
        public void Transform_WHEN_globalPropertyParseRules_Is_Null_THEN_Throws_ArgumentNullException()
        {
            Token t = new Token(TokenType.Delimiter, "#b", 1, 1);

            var parseRule = new DelimeterParseRule("Bold", DefaultDelimeterValues.Bold, "b");
            parseRule.TransformToHtml(t, null);
        }
예제 #8
0
        /// <summary>
        /// Adds a delimeter parse rule for use with this delimeter set
        /// </summary>
        /// <param name="delimeterParseRule">parse rule to use</param>
        public void AddDelimeterParseRule(DelimeterParseRule delimeterParseRule)
        {
            if (delimeterParseRule == null)
                throw new ArgumentNullException("delimeterParseRule");

            string parseRuleName = FormatDelimeterName(delimeterParseRule.Name);

            if (HasDelimeterFor(parseRuleName))
                throw new InvalidOperationException(String.Format("DelimeterParseRule with name '{0}' has already been added", parseRuleName));

            if(HasDelimeterText(delimeterParseRule.Delimeter))
                throw new InvalidOperationException(String.Format("DelimeterParseRule with text '{0}' has already been added", delimeterParseRule.Delimeter));

            _delimeters.Add(parseRuleName, delimeterParseRule.Delimeter);
            _parseRules.Add(delimeterParseRule);
        }