예제 #1
0
    public IEnumerator AlignSupport()
    {
        var        sampleHtml = @"
<body><p align='center'>aaa</p></body>";
        ParsedTree parsedRoot = null;

        yield return(GetParsedRoot(sampleHtml, parsedRootSource => { parsedRoot = parsedRootSource; }));
    }
예제 #2
0
    public IEnumerator SinglePSupport()
    {
        var        sampleHtml = @"
<body>bbb<p>aaa</body>";
        ParsedTree parsedRoot = null;

        yield return(GetParsedRoot(sampleHtml, parsedRootSource => { parsedRoot = parsedRootSource; }));
    }
예제 #3
0
    public IEnumerator ParseImageAsImgContent()
    {
        var        sampleHtml = @"
<img src='https://github.com/sassembla/Autoya/blob/master/doc/scr.png?raw=true2' />";
        ParsedTree parsedRoot = null;

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

        True(parsedRoot.GetChildren().Count == 1, "not match.");
        True(parsedRoot.GetChildren()[0].tagValue == (int)HTMLTag.img, "not match 1. actual:" + parsedRoot.GetChildren()[0].tagValue);
        True(parsedRoot.GetChildren()[0].treeType == TreeType.Content_Img, "not match.");
    }
예제 #4
0
    public IEnumerator ParseCustomTextAsTextContent()
    {
        var        sampleHtml = @"
<!DOCTYPE uuebview href='resources://Views/ParserTestTextView/UUebTags'>
<mytext>text</mytext>";
        ParsedTree parsedRoot = null;

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

        True(parsedRoot.GetChildren().Count == 1, "not match.");
        True(parsedRoot.GetChildren()[0].treeType == TreeType.Container, "not match. expected:" + TreeType.Container + " actual:" + parsedRoot.GetChildren()[0].treeType);
    }
예제 #5
0
    public IEnumerator ParseCustomImgAsImgContent()
    {
        var        sampleHtml = @"
<!DOCTYPE uuebview href='resources://Views/ParserTestImgView/UUebTags'>
<myimg src='https://github.com/sassembla/Autoya/blob/master/doc/scr.png?raw=true2' />";
        ParsedTree parsedRoot = null;

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

        True(parsedRoot.GetChildren().Count == 1, "not match.");
        True(parsedRoot.GetChildren()[0].treeType == TreeType.Content_Img, "not match. expected:" + TreeType.Content_Img + " actual:" + parsedRoot.GetChildren()[0].treeType);
    }
예제 #6
0
    public IEnumerator LoadDepthAssetListIsDone()
    {
        var        sampleHtml = @"
<!DOCTYPE uuebview href='resources://Views/ParserTest/UUebTags'>
<body>something</body>
        ";
        ParsedTree parsedRoot = null;

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

        True(!loader.IsLoadingUUebTags, "still loading.");
    }
예제 #7
0
    public IEnumerator CustomEmptyLayerCanSingleCloseTag2()
    {
        var        sampleHtml = @"
<!DOCTYPE uuebview href='resources://Views/MyInfoView/UUebTags'>
<body><newbadge/>aaa</body>";
        ParsedTree parsedRoot = null;

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

        True(parsedRoot.errors.Count == 0, "not match.");
        True(parsedRoot.GetChildren().Count == 1, "count:" + parsedRoot.GetChildren().Count);
        True(parsedRoot.GetChildren()[0].GetChildren().Count == 2, "count:" + parsedRoot.GetChildren()[0].GetChildren().Count);
    }
예제 #8
0
    public IEnumerator WithWrongCustomTag()
    {
        var        sampleHtml = @"
<!DOCTYPE uuebview href='resources://Views/WithCustomTag/UUebTags'>
<customtag><typotagpos><customtext>something</customtext></typotagpos></customtag>
<p>else</p>
        ";
        ParsedTree parsedRoot = null;

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

        True(parsedRoot.errors.Any(), "no error.");
    }
예제 #9
0
    public IEnumerator LoadSimpleHTML()
    {
        var        sampleHtml = @"
<body>something</body>
        ";
        ParsedTree parsedRoot = null;

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

        var children = parsedRoot.GetChildren();

        True(children.Count == 1, "not match. children.Count:" + children.Count);
    }
예제 #10
0
    public IEnumerator ParseSimpleHTML()
    {
        var        sampleHtml = @"
<body>something</body>
        ";
        ParsedTree parsedRoot = null;

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

        var children = parsedRoot.GetChildren();

        True(parsedRoot.GetChildren().Count == 1, "not match.");
        True(parsedRoot.GetChildren()[0].tagValue == (int)HTMLTag.body, "not match.");
    }
예제 #11
0
    public IEnumerator ParserTestCustomLayerAndCustomContentCombination()
    {
        var        sampleHtml = @"
<!DOCTYPE uuebview href='resources://Views/ParserTestCombination/UUebTags'>
<customtag><customtagtext><customtext>text</customtext></customtagtext></customtag>
<customtext>text</customtext>";
        ParsedTree parsedRoot = null;

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

        True(parsedRoot.GetChildren().Count == 2, "not match.");
        True(parsedRoot.GetChildren()[0].treeType == TreeType.CustomLayer, "not match. expected:" + TreeType.CustomLayer + " actual:" + parsedRoot.GetChildren()[0].treeType);
        True(parsedRoot.GetChildren()[1].treeType == TreeType.Container, "not match. expected:" + TreeType.Container + " actual:" + parsedRoot.GetChildren()[0].treeType);
    }
예제 #12
0
    public IEnumerator WithCustomTag()
    {
        var        sampleHtml = @"
<!DOCTYPE uuebview href='resources://Views/WithCustomTag/UUebTags'>
<customtag><custompos><customtext>something</customtext></custompos></customtag>
<p>else</p>
        ";
        ParsedTree parsedRoot = null;

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

        var contentsCount = CountContentsRecursive(parsedRoot);

        True(contentsCount == 8, "not match. contentsCount:" + contentsCount);
    }
예제 #13
0
    public IEnumerator ParseCustomTag()
    {
        var        sampleHtml = @"
<!DOCTYPE uuebview href='resources://Views/ParserTest/UUebTags'>
<customtag><customtagpos><customtagtext>something</customtagtext></customtagpos></customtag>
        ";
        ParsedTree parsedRoot = null;

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

        // loader contains 4 additional custom tags.
        var count = loader.GetAdditionalTagCount();

        True(count == 4, "not match. count:" + count);
    }
예제 #14
0
    public IEnumerator Order()
    {
        var        sampleHtml = @"
<body>something1.<img src='https://dummyimage.com/100.png/09f/fff'/></body>";
        ParsedTree parsedRoot = null;

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

        True(
            parsedRoot /*root*/.GetChildren()[0] /*body*/.GetChildren()[0] /*text of body*/.treeType == TreeType.Content_Text, "not match, type:" + parsedRoot /*root*/.GetChildren()[0] /*body*/.GetChildren()[0] /*text of body*/.treeType
            );

        True(
            parsedRoot /*root*/.GetChildren()[0] /*body*/.GetChildren()[1] /*img*/.treeType == TreeType.Content_Img, "not match, type:" + parsedRoot /*root*/.GetChildren()[0] /*body*/.GetChildren()[1] /*img*/.treeType
            );
    }
예제 #15
0
    private IEnumerator CreateLayoutedTree(string sampleHtml, Action <TagTree> onLayouted, float width = 100)
    {
        ParsedTree parsedRoot = null;
        var        cor        = parser.ParseRoot(
            sampleHtml,
            parsed =>
        {
            parsedRoot = parsed;
        }
            );

        view.Core.Internal_CoroutineExecutor(cor);

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

        if (parsedRoot.errors.Any())
        {
            foreach (var error in parsedRoot.errors)
            {
                Debug.LogError("error:" + error.code + " reason:" + error.reason);
            }
            throw new Exception("failed to create layouted tree.");
        }

        TagTree layouted = null;

        var layoutMachine = new LayoutMachine(core.resLoader, new TMProPlugin());

        var cor2 = layoutMachine.Layout(
            parsedRoot,
            new Vector2(width, 100),
            layoutedTree =>
        {
            layouted = layoutedTree;
        }
            );

        view.Core.Internal_CoroutineExecutor(cor2);

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

        onLayouted(layouted);
    }
예제 #16
0
    private IEnumerator CreateTagTree(string sampleHtml, Action <TagTree> onParsed, float width = 100)
    {
        ParsedTree parsedRoot   = null;
        TagTree    layoutedRoot = null;

        var cor = parser.ParseRoot(
            sampleHtml,
            parsed =>
        {
            parsedRoot = parsed;
        }
            );

        executor.Core.CoroutineExecutor(cor);

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

        if (parsedRoot.errors.Any())
        {
            throw new Exception("failed to parse. error:" + parsedRoot.errors[0].reason);
        }


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

        var loaderCor = layoutMachine.Layout(
            parsedRoot,
            new Vector2(width, 100),
            layoutedTree =>
        {
            layoutedRoot = layoutedTree;
        }
            );

        executor.Core.CoroutineExecutor(loaderCor);

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

        onParsed(layoutedRoot);
    }
예제 #17
0
    public IEnumerator PSupport()
    {
        var        sampleHtml = @"
<p>
    p1<a href=''>a</a>p2
</p>";
        ParsedTree parsedRoot = null;

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

        var pChildren = parsedRoot.GetChildren()[0].GetChildren();

        // foreach (var pp in pChildren) {
        //     Debug.LogError("pp:" + pp.tagValue);
        // }
        True(pChildren.Count == 3, "not match, count:" + pChildren.Count);
    }
예제 #18
0
    public IEnumerator CoronWrappedContentSupport()
    {
        var        sampleHtml = @"
<p>
    a'<a href=''>aqua color string</a>'b
</p>";
        ParsedTree parsedRoot = null;

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

        var pChildren = parsedRoot.GetChildren()[0].GetChildren();

        foreach (var pp in pChildren)
        {
            True(pp.keyValueStore[HTMLAttribute._CONTENT] as string == "a'<a href=''>aqua color string</a>'b", "not match, " + pp.keyValueStore[HTMLAttribute._CONTENT]);
        }
        True(pChildren.Count == 1, "not match, pChildren count:" + pChildren.Count);
    }
예제 #19
0
    public IEnumerator BrSupport()
    {
        var        sampleHtml = @"
<p>
    something<br>
    else
</p>";
        ParsedTree parsedRoot = null;

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

        var p = parsedRoot.GetChildren()[0].GetChildren();

        // foreach (var pp in p) {
        //     Debug.LogError("pp:" + pp.tagValue);
        // }
        True(p.Count == 3, "not match, count:" + p.Count);
    }
예제 #20
0
    public IEnumerator WithDeepCustomTag()
    {
        var        sampleHtml = @"
<!DOCTYPE uuebview href='resources://Views/WithDeepCustomTag/UUebTags'>
<customtag><img src='https://github.com/sassembla/Autoya/blob/master/doc/scr.png?raw=true2' /><img src='https://github.com/sassembla/Autoya/blob/master/doc/scr.png?raw=true2' /></customtag>
<p>else</p>
        ";
        ParsedTree parsedRoot = null;

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

        var contentsCount = CountContentsRecursive(parsedRoot);

        // 増えてる階層に関してのチェックを行う。1種のcustomTagがあるので1つ増える。
        True(contentsCount == 7, "not match. contentsCount:" + contentsCount);

        // ShowRecursive(customizedTree, loader);
    }
예제 #21
0
    public IEnumerator CustomEmptyLayerCanSingleCloseTag()
    {
        var        sampleHtml = @"
<!DOCTYPE uuebview href='resources://Views/MyInfoView/UUebTags'>
<newbadge/>";
        ParsedTree parsedRoot = null;

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

        True(parsedRoot.errors.Count == 0, "not match. error:" + ParsedTree.ShowErrors(parsedRoot));
        foreach (var child in parsedRoot.GetChildren())
        {
            if (child.tagValue == 28)
            {
                Debug.LogError("child text:" + child.keyValueStore[HTMLAttribute._CONTENT]);
            }
        }
        True(parsedRoot.GetChildren().Count == 1, "count:" + parsedRoot.GetChildren().Count);
    }
예제 #22
0
    public IEnumerator UnityRichTextSizeSupport()
    {
        var        sampleHtml = @"
<p>
    a<size=50>large string</size>b
</p>";
        ParsedTree parsedRoot = null;

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

        var pChildren = parsedRoot.GetChildren()[0].GetChildren();

        foreach (var pp in pChildren)
        {
            // Debug.LogError("pp:" + pp.tagValue + " text:" + pp.keyValueStore[HTMLAttribute._CONTENT]);
            True(pp.keyValueStore[HTMLAttribute._CONTENT] as string == "a<size=50>large string</size>b", "not match, " + pp.keyValueStore[HTMLAttribute._CONTENT]);
        }
        True(pChildren.Count == 1, "not match, pChildren count:" + pChildren.Count);
    }
예제 #23
0
    public IEnumerator ParseDefaultTag()
    {
        var        sampleHtml = @"
<body>something</body>
        ";
        ParsedTree parsedRoot = null;

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

        // parsedRootを与えて、custimizedRootを返してくる
        // treeの内容が変わらないはず
        var contentsCount = CountContentsRecursive(parsedRoot);

        True(contentsCount == 3 /*root + body + content*/, "not match. contentsCount:" + contentsCount);

        var newContentsCount = CountContentsRecursive(parsedRoot);

        True(newContentsCount == 3, "not match. newContentsCount:" + newContentsCount);
    }
예제 #24
0
    public IEnumerator WithDeepCustomTagBoxHasBoxAttr()
    {
        var        sampleHtml = @"
<!DOCTYPE uuebview href='resources://Views/WithDeepCustomTag/UUebTags'>
<customtag><img src='https://github.com/sassembla/Autoya/blob/master/doc/scr.png?raw=true2' /><img src='https://github.com/sassembla/Autoya/blob/master/doc/scr.png?raw=true2' /></customtag>
<p>else</p>
        ";
        ParsedTree parsedRoot = null;

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

        foreach (var s in parsedRoot.GetChildren()[0].GetChildren())
        {
            True(s.treeType == TreeType.CustomBox, "not match, s.treeType:" + s.treeType);
            True(s.keyValueStore.ContainsKey(HTMLAttribute._BOX), "box does not have pos kv.");
        }

        // ShowRecursive(customizedTree, loader);
    }
예제 #25
0
    private IEnumerator GetParsedRoot(string sampleHtml, Action <ParsedTree> ret)
    {
        ParsedTree parsedRoot = null;
        var        cor        = parser.ParseRoot(
            sampleHtml,
            parsed =>
        {
            parsedRoot = parsed;
        }
            );

        executor.Core.CoroutineExecutor(cor);

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

        ret(parsedRoot);
    }
예제 #26
0
    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);
        }
    }
예제 #27
0
    public IEnumerator ParseErrorAtDirectContentUnderLayer()
    {
        var        sampleHtml = @"
<!DOCTYPE uuebview href='resources://Views/MultipleBoxConstraints/UUebTags'>
<itemlayout>
<topleft>
    <img src='https://dummyimage.com/100.png/09f/fff'/>
</topleft>
<topright>
    <img src='https://dummyimage.com/100.png/08f/fff'/>
</topright>
<content>something! should not be direct.</content>
<bottom>
    <img src='https://dummyimage.com/100.png/07f/fff'/>
</bottom>
</itemlayout>";
        ParsedTree parsedRoot = null;

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

        // parse failed by ErrorAtDirectContentUnderLayer. returns empty tree.
        True(parsedRoot.errors[0].code == (int)ParseErrors.CANNOT_CONTAIN_TEXT_IN_BOX_DIRECTLY, "not match.");
    }
예제 #28
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
                             ));
        }
    }