コード例 #1
0
        public void AtDirective_PageDirectiveChildren()
        {
            string[] tests = new string[]
            {
                "@page { @top-left-corner { foo } }",
                "@page { @top-left { foo } }",
                "@page { @top-center { foo } }",
                "@page { @top-right { foo } }",
                "@page { @top-right-corner { foo } }",
                "@page { @bottom-left-corner { foo } }",
                "@page { @bottom-left { foo } }",
                "@page { @bottom-center { foo } }",
                "@page { @bottom-right { foo } }",
                "@page { @bottom-right-corner { foo } }",
                "@page { @left-top { foo } }",
                "@page { @left-middle { foo } }",
                "@page { @left-bottom { foo } }",
                "@page { @right-top { foo } }",
                "@page { @right-middle { foo } }",
                "@page { @right-bottom { foo } }",
                "@page { @RIGHT-bottom { foo } }",
            };

            MarginDirectiveType[] types = new MarginDirectiveType[]
            {
                MarginDirectiveType.TopLeftCorner,
                MarginDirectiveType.TopLeft,
                MarginDirectiveType.TopCenter,
                MarginDirectiveType.TopRight,
                MarginDirectiveType.TopRightCorner,
                MarginDirectiveType.BottomLeftCorner,
                MarginDirectiveType.BottomLeft,
                MarginDirectiveType.BottomCenter,
                MarginDirectiveType.BottomRight,
                MarginDirectiveType.BottomRightCorner,
                MarginDirectiveType.LeftTop,
                MarginDirectiveType.LeftMiddle,
                MarginDirectiveType.LeftBottom,
                MarginDirectiveType.RightTop,
                MarginDirectiveType.RightMiddle,
                MarginDirectiveType.RightBottom,
                MarginDirectiveType.Unknown,
            };

            for (int i = 0; i < tests.Length; i++)
            {
                PageDirective s  = new PageDirective();
                ITextProvider tp = new StringTextProvider(tests[i]);
                Assert.IsTrue(s.Parse(new ItemFactory(tp, null), tp, Helpers.MakeTokenStream(tp)));
                Assert.AreEqual(1, s.PageDirectiveBlock.Margins.Count);
                Assert.AreEqual(types[i], s.PageDirectiveBlock.Margins[0].DirectiveType);
            }
        }
コード例 #2
0
        public void PageDirective_ParseTest()
        {
            string        text = "@page { }";
            ITextProvider tp   = new StringTextProvider(text);
            TokenStream   ts   = Helpers.MakeTokenStream(tp);
            PageDirective pd   = new PageDirective();

            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));

            text = "@page:left { }";
            tp   = new StringTextProvider(text);
            ts   = Helpers.MakeTokenStream(tp);
            pd   = new PageDirective();
            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));
            Assert.IsTrue(tp.CompareTo(pd.Keyword.Start, "page", ignoreCase: false));
            Assert.AreEqual("left", tp.GetText(pd.PseudoPage.Start, pd.PseudoPage.Length));
            Assert.IsNotNull(pd.Block.OpenCurlyBrace);
            Assert.IsNotNull(pd.Block.CloseCurlyBrace);

            text = "@page :right{ }";
            tp   = new StringTextProvider(text);
            ts   = Helpers.MakeTokenStream(tp);
            pd   = new PageDirective();
            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));
            Assert.IsTrue(tp.CompareTo(pd.Keyword.Start, "page", ignoreCase: false));
            Assert.AreEqual("right", tp.GetText(pd.PseudoPage.Start, pd.PseudoPage.Length));
            Assert.IsNotNull(pd.Block.OpenCurlyBrace);
            Assert.IsNotNull(pd.Block.CloseCurlyBrace);

            text = "@page foo:first{ }";
            tp   = new StringTextProvider(text);
            ts   = Helpers.MakeTokenStream(tp);
            pd   = new PageDirective();
            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));
            Assert.IsTrue(tp.CompareTo(pd.Keyword.Start, "page", ignoreCase: false));
            Assert.IsTrue(tp.CompareTo(pd.Identifier.Start, "foo", ignoreCase: false));
            Assert.AreEqual("first", tp.GetText(pd.PseudoPage.Start, pd.PseudoPage.Length));
            Assert.IsNotNull(pd.Block.OpenCurlyBrace);
            Assert.IsNotNull(pd.Block.CloseCurlyBrace);

            text = "@page :foo{ @top-left { } }";
            tp   = new StringTextProvider(text);
            ts   = Helpers.MakeTokenStream(tp);
            pd   = new PageDirective();
            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));
            Assert.AreEqual(1, pd.PageDirectiveBlock.Margins.Count);
            Assert.AreEqual(MarginDirectiveType.TopLeft, pd.PageDirectiveBlock.Margins[0].DirectiveType);
            Assert.IsTrue(tp.CompareTo(pd.PageDirectiveBlock.Margins[0].Keyword.Start, "top-left", ignoreCase: false));

            text = "@page";
            tp   = new StringTextProvider(text);
            ts   = Helpers.MakeTokenStream(tp);
            pd   = new PageDirective();
            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));
            Assert.IsNull(pd.Block);

            text = "@page :right{ @top-left { }";
            tp   = new StringTextProvider(text);
            ts   = Helpers.MakeTokenStream(tp);
            pd   = new PageDirective();
            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));
            Assert.AreEqual(1, pd.PageDirectiveBlock.Margins.Count);
            Assert.IsTrue(tp.CompareTo(pd.PageDirectiveBlock.Margins[0].Keyword.Start, "top-left", ignoreCase: false));
            Assert.IsNotNull(pd.PageDirectiveBlock.Margins[0].RuleBlock.OpenCurlyBrace);
            Assert.IsNotNull(pd.PageDirectiveBlock.Margins[0].RuleBlock.CloseCurlyBrace);
            Assert.IsNotNull(pd.Block.OpenCurlyBrace);
            Assert.IsNull(pd.Block.CloseCurlyBrace);
        }