Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<title>Canvas test: 2d.text.measure.text-clusters-split.tentative</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
<body class="show_output">
<h1>2d.text.measure.text-clusters-split.tentative</h1>
<p class="desc">Test that getTextClusters() splits the input correctly into the minimal clusters, keeping emojis together.</p>
<p class="output">Actual output:</p>
<canvas id="c" class="output" width="400" height="200"><p class="fallback">FAIL (fallback content)</p></canvas>
<ul id="d"></ul>
<script>
var t = async_test("Test that getTextClusters() splits the input correctly into the minimal clusters, keeping emojis together.");
_addTest(function(canvas, ctx) {
ctx.font = '50px serif';
const text = 'ABC ☺️❤️';
ctx.fillText(text, 20, 100);
const tm = ctx.measureText(text);
const clusters = tm.getTextClusters();
// Should return 6 clusters(A|B|C| |☺️|❤️).
_assertSame(clusters.length, 6, "clusters.length", "6");
// A from position 0 to 1.
_assertSame(clusters[0].begin, 0, "clusters[\""+(0)+"\"].begin", "0");
_assertSame(clusters[0].end, 1, "clusters[\""+(0)+"\"].end", "1");
// B from position 1 to 2.
_assertSame(clusters[1].begin, 1, "clusters[\""+(1)+"\"].begin", "1");
_assertSame(clusters[1].end, 2, "clusters[\""+(1)+"\"].end", "2");
// C from position 2 to 3.
_assertSame(clusters[2].begin, 2, "clusters[\""+(2)+"\"].begin", "2");
_assertSame(clusters[2].end, 3, "clusters[\""+(2)+"\"].end", "3");
// space from position 3 to 4.
_assertSame(clusters[3].begin, 3, "clusters[\""+(3)+"\"].begin", "3");
_assertSame(clusters[3].end, 4, "clusters[\""+(3)+"\"].end", "4");
// ☺️ from position 4 to 6.
_assertSame(clusters[4].begin, 4, "clusters[\""+(4)+"\"].begin", "4");
_assertSame(clusters[4].end, 6, "clusters[\""+(4)+"\"].end", "6");
// ❤️ from position 6 to 8.
_assertSame(clusters[5].begin, 6, "clusters[\""+(5)+"\"].begin", "6");
_assertSame(clusters[5].end, 8, "clusters[\""+(5)+"\"].end", "8");
});
</script>