chromium/third_party/blink/web_tests/svg/text/text-getSubStringLength.html

<!DOCTYPE html>
<title>SVGTextContentElement.getSubStringLength</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div id=log></div>
<div>
  <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
    <text x="10" y="20">W3C &#x0646;&#x0634;&#x0627;&#x0637;</text>
    <text x="10 50" y="40">AB</text>
    <text dx="-1 42 0 1">Text</text>
  </svg>
</div>
<script>
test(function() {
    var text = document.querySelector('text');
    assert_equals(text.getNumberOfChars(), 8);
    var lenFirst4 = text.getSubStringLength(0, 4);
    var lenLast4 = text.getSubStringLength(4, 4);
    var lenAll = text.getSubStringLength(0, 8);
    assert_approx_equals(lenFirst4 + lenLast4, lenAll, 0.01, 'Sum of the parts equal the total.');
}, document.title+', BiDi.');
test(function() {
    var text = document.querySelector('text + text');
    assert_equals(text.getNumberOfChars(), 2);
    var lenFirst = text.getSubStringLength(0, 1);
    var lenLast = text.getSubStringLength(1, 1);
    var lenAll = text.getSubStringLength(0, 2);
    assert_approx_equals(lenFirst + lenLast, lenAll, 0.01, 'Sum of the parts equal the total.');
}, document.title+', multiple text-chunks.');

test(() => {
    let text = document.querySelectorAll('text')[2];
    assert_equals(text.getSubStringLength(1, 0), 0.0);
}, `${document.title}, 0-length`);
</script>