Exemplo n.º 1
0
        public void TestItTriesToParseHeadings(string heading, int expectedParsed, bool expectedReturn)
        {
            bool tryParseResult = HeadingParser.TryParse(heading, out int parsedHeadingResult);

            Assert.Equal(expectedReturn, tryParseResult);
            Assert.Equal(expectedParsed, parsedHeadingResult);
        }
        public void Parse()
        {
            DomDocument         document           = new DomDocument();
            IBlockElementParser blockElementParser = new HeadingParser();

            blockElementParser.Parse(null, document,
                                     "h1(class#id){style}=(())). Heading 1\r\n\r\nh2.One more\r\n\r\nh3(class2). And one more\r\n\r\n");

            Assert.AreEqual(2, document.ChildElements.Count);

            Heading heading = document.ChildElements[0] as Heading;

            Assert.IsNotNull(heading);
            Assert.AreEqual(1, heading.Level);
            Assert.AreEqual("class", heading.Attributes.CssClass);
            Assert.AreEqual("id", heading.Attributes.ID);
            Assert.AreEqual("style", heading.Attributes.Style);
            Assert.AreEqual(BlockElementAlignment.Center, heading.Attributes.Alignment);
            Assert.AreEqual(2, heading.Attributes.LeftIndent);
            Assert.AreEqual(3, heading.Attributes.RightIndent);

            heading = document.ChildElements[1] as Heading;

            Assert.IsNotNull(heading);
            Assert.AreEqual(3, heading.Level);
            Assert.AreEqual("class2", heading.Attributes.CssClass);
        }
Exemplo n.º 3
0
        private static RubyParser.TokenVisitor CreateTokenVisitor(FormattedTextBuffer buffer)
        {
            var visitor = new RubyParser.TokenVisitor
            {
                OnNormal = text =>
                {
                    var tokens2 = AnnotationParser.Parse(text);
                    foreach (var token2 in tokens2)
                    {
                        token2.Accept(new AnnotationParser.TokenVisitor
                        {
                            OnBody        = bodyText => buffer.Append(bodyText),
                            OnPlaceholder = () => buffer.Append(AozoraBunko.SpecialCharacters.ExternalCharacterPlaceholder),
                            OnAnnotation  = annotationText =>
                            {
                                //見出し
                                var headingText = HeadingParser.Parse(annotationText);
                                if (headingText != null)
                                {
                                    //TODO: 見出しレベル
                                    buffer.HeadingTitle = headingText;
                                    return;
                                }

                                //圏点
                                var emphasysDottedText = EmphasysDotsParser.Parse(annotationText);
                                if (emphasysDottedText != null)
                                {
                                    buffer.EmphasysDot(buffer.Length - emphasysDottedText.Length, buffer.Length);
                                    return;
                                }

                                //TODO: その他の注記
                            }
                        });
                    }
                    ;
                },
                OnRuby = (baseText, rubyText) =>
                {
                    buffer.Append(baseText);
                    buffer.Ruby(buffer.Length - baseText.Length, buffer.Length, rubyText);
                }
            };

            return(visitor);
        }
        public void cannot_parse_invalid_input(string input, int level)
        {
            var result = HeadingParser.GetParser(level)(new Input(input));

            Assert.False(result.WasSuccessful && result.Remainder.AtEnd);
        }
        public void can_parse_valid_input(string input, int level, string expected)
        {
            var result = HeadingParser.GetParser(level).Parse(input);

            Assert.Equal(expected, result);
        }
 public void SetUp()
 {
     tokensParser = new Mock <ITokensParser>();
     parser       = new HeadingParser(tokensParser.Object);
 }
Exemplo n.º 7
0
 public Parser(ITokensParser tokensParser)
 {
     _headingParser = new HeadingParser(tokensParser);
     _constantsDeclarationParser = new ConstantsDeclarationParser(tokensParser);
     _variablesDeclarationParser = new VariablesDeclarationParser(tokensParser);
 }