Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elementEnd is not parsed when element is empty #11

Open
wilzbach opened this issue Jan 28, 2018 · 0 comments
Open

elementEnd is not parsed when element is empty #11

wilzbach opened this issue Jan 28, 2018 · 0 comments

Comments

@wilzbach
Copy link
Member

From @NVolcz on October 18, 2016 21:24

unittest
{
    import std.experimental.xml.lexers;
    import std.experimental.xml.parser;
    import std.string : lineSplitter, strip;
    import std.algorithm : map;
    import std.array : array;

    wstring xml = q{
    <?xml encoding = "utf-8" ?>
    <!DOCTYPE mydoc>
    <aaa>
        <works>
        test
        </works>
        <notWork></notWork>
    </aaa>
    };

    auto cursor = xml.lexer.parser.cursor;

    assert(cursor.atBeginning);

    // <?xml encoding = "utf-8" ?>
    assert(cursor.kind() == XMLKind.document);
    assert(cursor.name() == "xml");
    assert(cursor.prefix() == "");
    assert(cursor.localName() == "xml");
    assert(cursor.attributes().array == [Attribute!wstring("encoding", "utf-8")]);
    assert(cursor.content() == " encoding = \"utf-8\" ");

    assert(cursor.enter());
        assert(!cursor.atBeginning);

        // <!DOCTYPE mydoc
        assert(cursor.kind == XMLKind.dtdEmpty);
        assert(cursor.wholeContent == " mydoc");

        assert(cursor.next);

        // <aaa>
        assert(cursor.kind() == XMLKind.elementStart);
        assert(cursor.name() == "aaa");
        assert(cursor.prefix() == "");
        assert(cursor.localName() == "aaa");

        assert(cursor.enter());
            // <works>
            assert(cursor.kind() == XMLKind.elementStart);
            assert(cursor.name() == "works");

            assert(cursor.enter());
            assert(!cursor.enter());
            assert(!cursor.next());

            //cursor.exit();

            // </works>
            assert(cursor.kind() == XMLKind.elementEnd);
            assert(cursor.name() == "works");

            cursor.exit();

            assert(cursor.next());

             // <notWork>
            assert(cursor.kind() == XMLKind.elementStart);
            assert(cursor.name() == "notWork");

            assert(!cursor.enter());
            assert(!cursor.next());

            // </notWork>
            assert(cursor.kind() == XMLKind.elementEnd);
            assert(cursor.name() == "notWork");

            assert(!cursor.next());
        cursor.exit();

        // </aaa>
        assert(cursor.kind() == XMLKind.elementEnd);
        assert(cursor.name() == "aaa");

        assert(!cursor.next());
    cursor.exit();

    assert(cursor.documentEnd);
    assert(!cursor.atBeginning);
}

Copied from original issue: lodo1995/experimental.xml#34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant