11cb0ef41Sopenharmony_ci// META: title=Encoding API: USVString surrogate handling when encoding
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_civar bad = [
41cb0ef41Sopenharmony_ci    {
51cb0ef41Sopenharmony_ci        input: '\uD800',
61cb0ef41Sopenharmony_ci        expected: '\uFFFD',
71cb0ef41Sopenharmony_ci        name: 'lone surrogate lead'
81cb0ef41Sopenharmony_ci    },
91cb0ef41Sopenharmony_ci    {
101cb0ef41Sopenharmony_ci        input: '\uDC00',
111cb0ef41Sopenharmony_ci        expected: '\uFFFD',
121cb0ef41Sopenharmony_ci        name: 'lone surrogate trail'
131cb0ef41Sopenharmony_ci    },
141cb0ef41Sopenharmony_ci    {
151cb0ef41Sopenharmony_ci        input: '\uD800\u0000',
161cb0ef41Sopenharmony_ci        expected: '\uFFFD\u0000',
171cb0ef41Sopenharmony_ci        name: 'unmatched surrogate lead'
181cb0ef41Sopenharmony_ci    },
191cb0ef41Sopenharmony_ci    {
201cb0ef41Sopenharmony_ci        input: '\uDC00\u0000',
211cb0ef41Sopenharmony_ci        expected: '\uFFFD\u0000',
221cb0ef41Sopenharmony_ci        name: 'unmatched surrogate trail'
231cb0ef41Sopenharmony_ci    },
241cb0ef41Sopenharmony_ci    {
251cb0ef41Sopenharmony_ci        input: '\uDC00\uD800',
261cb0ef41Sopenharmony_ci        expected: '\uFFFD\uFFFD',
271cb0ef41Sopenharmony_ci        name: 'swapped surrogate pair'
281cb0ef41Sopenharmony_ci    },
291cb0ef41Sopenharmony_ci    {
301cb0ef41Sopenharmony_ci        input: '\uD834\uDD1E',
311cb0ef41Sopenharmony_ci        expected: '\uD834\uDD1E',
321cb0ef41Sopenharmony_ci        name: 'properly encoded MUSICAL SYMBOL G CLEF (U+1D11E)'
331cb0ef41Sopenharmony_ci    }
341cb0ef41Sopenharmony_ci];
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_cibad.forEach(function(t) {
371cb0ef41Sopenharmony_ci    test(function() {
381cb0ef41Sopenharmony_ci        var encoded = new TextEncoder().encode(t.input);
391cb0ef41Sopenharmony_ci        var decoded = new TextDecoder().decode(encoded);
401cb0ef41Sopenharmony_ci        assert_equals(decoded, t.expected);
411cb0ef41Sopenharmony_ci    }, 'USVString handling: ' + t.name);
421cb0ef41Sopenharmony_ci});
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_citest(function() {
451cb0ef41Sopenharmony_ci    assert_equals(new TextEncoder().encode().length, 0, 'Should default to empty string');
461cb0ef41Sopenharmony_ci}, 'USVString default');
47