コード例 #1
0
ファイル: HTMLParserTests.cs プロジェクト: sassembla/UUebView
    public IEnumerator Revert()
    {
        var        sampleHtml = @"
<body>something</body>
        ";
        ParsedTree parsedRoot = null;

        yield return(GetParsedRoot(sampleHtml, parsedRootSource => { parsedRoot = parsedRootSource; }));

        {
            var bodyContainer = parsedRoot.GetChildren()[0];

            var textChildren = bodyContainer.GetChildren();

            True(textChildren.Count == 1, "not match a. actual:" + textChildren.Count);

            var textChildrenTree = textChildren[0];
            var textPart         = textChildrenTree.keyValueStore[HTMLAttribute._CONTENT] as string;
            var frontHalf        = textPart.Substring(0, 4);
            var backHalf         = textPart.Substring(4);

            textChildrenTree.keyValueStore[HTMLAttribute._CONTENT] = frontHalf;

            var insertionTree = new InsertedTree(textChildrenTree, backHalf, textChildrenTree.tagValue);
            insertionTree.SetParent(bodyContainer);

            // 増えてるはず
            True(bodyContainer.GetChildren().Count == 2, "not match b. actual:" + bodyContainer.GetChildren().Count);
        }

        TagTree.CorrectTrees(parsedRoot);

        {
            var bodyContainer = parsedRoot.GetChildren()[0];

            var textChildren     = bodyContainer.GetChildren();
            var textChildrenTree = textChildren[0];

            True(textChildren.Count == 1, "not match c. actual:" + textChildren.Count);
            True(textChildrenTree.keyValueStore[HTMLAttribute._CONTENT] as string == "something", "actual:" + textChildrenTree.keyValueStore[HTMLAttribute._CONTENT] as string);
        }
    }
コード例 #2
0
    public IEnumerator RevertLayoutHTMLWithSmallImageAndSmallTextAndBr()
    {
        var sample = @"
        <body><img src='https://dummyimage.com/10.png/09f/fff'/>over 100px string should be multi lined text with good separation.
        <br>need some length.</body>";

        ParsedTree parsedRoot = null;
        {
            var cor = parser.ParseRoot(
                sample,
                parsed =>
            {
                parsedRoot = parsed;
            }
                );

            executor.Core.CoroutineExecutor(cor);

            yield return(WaitUntil(
                             () => parsedRoot != null, () => { throw new TimeoutException("too late."); }, 1
                             ));
        }

        {
            var done = false;

            LayoutMachine layoutMachine = null;

            layoutMachine = new LayoutMachine(
                loader,
                new TMProPlugin()
                );

            var cor = layoutMachine.Layout(
                parsedRoot,
                new Vector2(100, 100),
                layoutedTree =>
            {
                done = true;
                True(layoutedTree.viewHeight == 112, "not match. layoutedTree.viewHeight:" + layoutedTree.viewHeight);
            }
                );
            executor.Core.CoroutineExecutor(cor);


            yield return(WaitUntil(
                             () => done, () => { throw new TimeoutException("too late."); }, 5
                             ));

            TagTree.CorrectTrees(parsedRoot);

            /*
             *  revert-layout.
             */
            var done2 = false;

            var cor2 = layoutMachine.Layout(
                parsedRoot,
                new Vector2(100, 100),
                layoutedTree =>
            {
                done2 = true;
                True(layoutedTree.viewHeight == 112, "not match. actual:" + layoutedTree.viewHeight);
            }
                );

            executor.Core.CoroutineExecutor(cor2);


            yield return(WaitUntil(
                             () => done2, () => { throw new TimeoutException("too late."); }, 5
                             ));
        }
    }