                   bytearray.readUTFBytes(6); // one too much
               }));
 
-    // TODO: test that any UTF8 BOM is being skipped
+    // Skip UTF-8 BOM.
+    // This seems fairly ill-defined and ad-hoc since the BOM is skipped but is accounted for in the byte count,
+    // but it's what we do, so test that we continue to do it...
+    bytearray.length = 0;
+    bytearray.position = 0;
+    bytearray.endian = "bigEndian";
+    bytearray.writeByte(0xEF);
+    bytearray.writeByte(0xBB);
+    bytearray.writeByte(0xBF);
+    bytearray.writeUTFBytes("string");
+    bytearray.position = 0;
+    AddTestCase("ByteArray readUTFBytes skips UTF8 BOM but includes it in the length",
+                "str",
+                bytearray.readUTFBytes(6));
+
     // TODO: test invalid UTF - we should still get data, in a predictable way (invalid input turns into individual bytes)
 }
 

                  bytearray.readBytes(bytearray3, 0, bytearray.length+1);
              }));

    // TODO: test more combinations of offset and count
}


    return bytearray;
}

// Utility to test for RangeError
function expectRangeError(tag, thunk)
{
    var exn_ok = "No exn";
    try                   { thunk(); }
    catch (e: RangeError) { exn_ok = "OK"; }
    catch (e)             { exn_ok = "Wrong type"; }
    AddTestCase(tag, "OK", exn_ok);
}

// Utility to test for EOFError
function expectEOF(tag, thunk)
{
