<body onload="test()">
    <p>Test for <i><a href="rdar://problem/6764359">rdar://problem/6764359</a> Thai word selection misbehaves for the last sentence in the document</i>.</p>
    <script>
        function test()
        {
            if (window.testRunner)
                testRunner.dumpAsText();

            var text = "'2!+!2"-+1*7-4!L A%0I2'C+!H--4@-#LD"";
            var container = document.body.appendChild(document.createElement("div"));
            var textNode = container.appendChild(document.createTextNode(text));
            var trailer = container.appendChild(document.createTextNode("."));

            container.contentEditable = "true";
            var selection = getSelection();

            var expectedPositions = [];
            selection.setBaseAndExtent(textNode, 0, textNode, 0);
            while (selection.baseNode === textNode) {
                expectedPositions.push(selection.baseOffset);
                selection.modify("move", "forward", "word");
            }

            container.removeChild(trailer);
            var positions = [];
            selection.setBaseAndExtent(textNode, 0, textNode, 0);
            var success = true;
            for (var i = 0; i < expectedPositions.length; ++i) {
                positions.push(selection.baseOffset);
                if (selection.baseOffset != expectedPositions[i])
                    success = false;
                selection.modify("move", "forward", "word");
            }
            var result = document.getElementById("result");
            if (success)
                result.innerText = "PASS";
            else
                result.innerText = "FAIL: Word boundaries visited: " + positions;
        }
    </script>
    <div id="result">FAIL: Test did not finish</div>
</body>
