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 #34

Open
NVolcz opened this issue Oct 18, 2016 · 1 comment
Open

elementEnd is not parsed when element is empty #34

NVolcz opened this issue Oct 18, 2016 · 1 comment

Comments

@NVolcz
Copy link
Contributor

NVolcz commented Oct 18, 2016

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);
}
@wilzbach
Copy link

This issue was moved to dlang-community/experimental.xml#11

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

2 participants