Files
gcc/libphobos/testsuite/libphobos.phobos/std_encoding.d
Iain Buclaw c2ece13931 libphobos: Generate test files for phobos testsuite
Extracts all public unittests from libphobos/src and emits them as
standalone tests in the testsuite using the tests_extractor script.

Compiling every module in the Phobos library with unittests included is
computationally expensive, and these tests are now only ran when
GCC_TEST_RUN_EXPENSIVE is not empty.

When instead just compiling the unittests and linking in the module
under test, this has been observed to reduce the time spent running the
testsuite by more than half.

libphobos/ChangeLog:

	* testsuite/libphobos.phobos/shared/phobos-shared.exp: Require
	is-effective-target run_expensive_tests.
	* testsuite/libphobos.phobos/static/phobos-static.exp: Likewise.
	* testsuite/libphobos.phobos/phobos.exp: New test.
	* testsuite/libphobos.phobos/std_algorithm_comparison.d: New test.
	* testsuite/libphobos.phobos/std_algorithm_iteration.d: New test.
	* testsuite/libphobos.phobos/std_algorithm_mutation.d: New test.
	* testsuite/libphobos.phobos/std_algorithm_searching.d: New test.
	* testsuite/libphobos.phobos/std_algorithm_setops.d: New test.
	* testsuite/libphobos.phobos/std_algorithm_sorting.d: New test.
	* testsuite/libphobos.phobos/std_array.d: New test.
	* testsuite/libphobos.phobos/std_ascii.d: New test.
	* testsuite/libphobos.phobos/std_base64.d: New test.
	* testsuite/libphobos.phobos/std_bigint.d: New test.
	* testsuite/libphobos.phobos/std_bitmanip.d: New test.
	* testsuite/libphobos.phobos/std_checkedint.d: New test.
	* testsuite/libphobos.phobos/std_complex.d: New test.
	* testsuite/libphobos.phobos/std_concurrency.d: New test.
	* testsuite/libphobos.phobos/std_container_array.d: New test.
	* testsuite/libphobos.phobos/std_container_binaryheap.d: New test.
	* testsuite/libphobos.phobos/std_container_dlist.d: New test.
	* testsuite/libphobos.phobos/std_container_rbtree.d: New test.
	* testsuite/libphobos.phobos/std_container_slist.d: New test.
	* testsuite/libphobos.phobos/std_container_util.d: New test.
	* testsuite/libphobos.phobos/std_conv.d: New test.
	* testsuite/libphobos.phobos/std_csv.d: New test.
	* testsuite/libphobos.phobos/std_datetime_date.d: New test.
	* testsuite/libphobos.phobos/std_datetime_interval.d: New test.
	* testsuite/libphobos.phobos/std_datetime_package.d: New test.
	* testsuite/libphobos.phobos/std_datetime_stopwatch.d: New test.
	* testsuite/libphobos.phobos/std_datetime_systime.d: New test.
	* testsuite/libphobos.phobos/std_datetime_timezone.d: New test.
	* testsuite/libphobos.phobos/std_demangle.d: New test.
	* testsuite/libphobos.phobos/std_digest_crc.d: New test.
	* testsuite/libphobos.phobos/std_digest_hmac.d: New test.
	* testsuite/libphobos.phobos/std_digest_md.d: New test.
	* testsuite/libphobos.phobos/std_digest_murmurhash.d: New test.
	* testsuite/libphobos.phobos/std_digest_package.d: New test.
	* testsuite/libphobos.phobos/std_digest_ripemd.d: New test.
	* testsuite/libphobos.phobos/std_digest_sha.d: New test.
	* testsuite/libphobos.phobos/std_encoding.d: New test.
	* testsuite/libphobos.phobos/std_exception.d: New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_affix_allocator.d:
	New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_aligned_block_list.d:
	New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_allocator_list.d:
	New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_ascending_page_allocator.d:
	New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_bitmapped_block.d:
	New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_bucketizer.d:
	New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_fallback_allocator.d:
	New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_free_list.d:
	New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_kernighan_ritchie.d:
	New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_quantizer.d:
	New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_region.d: New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_scoped_allocator.d:
	New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_segregator.d:
	New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_stats_collector.d:
	New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_common.d: New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_gc_allocator.d: New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_mallocator.d: New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_package.d: New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_showcase.d: New test.
	* testsuite/libphobos.phobos/std_experimental_allocator_typed.d: New test.
	* testsuite/libphobos.phobos/std_file.d: New test.
	* testsuite/libphobos.phobos/std_format_package.d: New test.
	* testsuite/libphobos.phobos/std_format_read.d: New test.
	* testsuite/libphobos.phobos/std_format_spec.d: New test.
	* testsuite/libphobos.phobos/std_format_write.d: New test.
	* testsuite/libphobos.phobos/std_functional.d: New test.
	* testsuite/libphobos.phobos/std_getopt.d: New test.
	* testsuite/libphobos.phobos/std_int128.d: New test.
	* testsuite/libphobos.phobos/std_internal_cstring.d: New test.
	* testsuite/libphobos.phobos/std_internal_scopebuffer.d: New test.
	* testsuite/libphobos.phobos/std_json.d: New test.
	* testsuite/libphobos.phobos/std_logger_core.d: New test.
	* testsuite/libphobos.phobos/std_logger_nulllogger.d: New test.
	* testsuite/libphobos.phobos/std_math_algebraic.d: New test.
	* testsuite/libphobos.phobos/std_math_exponential.d: New test.
	* testsuite/libphobos.phobos/std_math_hardware.d: New test.
	* testsuite/libphobos.phobos/std_math_operations.d: New test.
	* testsuite/libphobos.phobos/std_math_remainder.d: New test.
	* testsuite/libphobos.phobos/std_math_rounding.d: New test.
	* testsuite/libphobos.phobos/std_math_traits.d: New test.
	* testsuite/libphobos.phobos/std_math_trigonometry.d: New test.
	* testsuite/libphobos.phobos/std_meta.d: New test.
	* testsuite/libphobos.phobos/std_mmfile.d: New test.
	* testsuite/libphobos.phobos/std_numeric.d: New test.
	* testsuite/libphobos.phobos/std_outbuffer.d: New test.
	* testsuite/libphobos.phobos/std_package.d: New test.
	* testsuite/libphobos.phobos/std_parallelism.d: New test.
	* testsuite/libphobos.phobos/std_path.d: New test.
	* testsuite/libphobos.phobos/std_random.d: New test.
	* testsuite/libphobos.phobos/std_range_interfaces.d: New test.
	* testsuite/libphobos.phobos/std_range_package.d: New test.
	* testsuite/libphobos.phobos/std_range_primitives.d: New test.
	* testsuite/libphobos.phobos/std_regex_package.d: New test.
	* testsuite/libphobos.phobos/std_signals.d: New test.
	* testsuite/libphobos.phobos/std_socket.d: New test.
	* testsuite/libphobos.phobos/std_stdio.d: New test.
	* testsuite/libphobos.phobos/std_string.d: New test.
	* testsuite/libphobos.phobos/std_sumtype.d: New test.
	* testsuite/libphobos.phobos/std_traits.d: New test.
	* testsuite/libphobos.phobos/std_typecons.d: New test.
	* testsuite/libphobos.phobos/std_typetuple.d: New test.
	* testsuite/libphobos.phobos/std_uni_package.d: New test.
	* testsuite/libphobos.phobos/std_uri.d: New test.
	* testsuite/libphobos.phobos/std_utf.d: New test.
	* testsuite/libphobos.phobos/std_uuid.d: New test.
	* testsuite/libphobos.phobos/std_variant.d: New test.
	* testsuite/libphobos.phobos/std_zlib.d: New test.
2025-02-26 00:37:07 +01:00

168 lines
3.9 KiB
D

@safe unittest
{
import std.encoding;
assert(encodingName!(char) == "UTF-8");
assert(encodingName!(wchar) == "UTF-16");
assert(encodingName!(dchar) == "UTF-32");
assert(encodingName!(AsciiChar) == "ASCII");
assert(encodingName!(Latin1Char) == "ISO-8859-1");
assert(encodingName!(Latin2Char) == "ISO-8859-2");
assert(encodingName!(Windows1250Char) == "windows-1250");
assert(encodingName!(Windows1251Char) == "windows-1251");
assert(encodingName!(Windows1252Char) == "windows-1252");
}
@safe pure unittest
{
import std.encoding;
assert( canEncode!(Latin1Char)('A'));
assert( canEncode!(Latin2Char)('A'));
assert(!canEncode!(AsciiChar)('\u00A0'));
assert( canEncode!(Latin1Char)('\u00A0'));
assert( canEncode!(Latin2Char)('\u00A0'));
assert( canEncode!(Windows1250Char)('\u20AC'));
assert(!canEncode!(Windows1250Char)('\u20AD'));
assert(!canEncode!(Windows1250Char)('\uFFFD'));
assert( canEncode!(Windows1251Char)('\u0402'));
assert(!canEncode!(Windows1251Char)('\u20AD'));
assert(!canEncode!(Windows1251Char)('\uFFFD'));
assert( canEncode!(Windows1252Char)('\u20AC'));
assert(!canEncode!(Windows1252Char)('\u20AD'));
assert(!canEncode!(Windows1252Char)('\uFFFD'));
assert(!canEncode!(char)(cast(dchar) 0x110000));
}
@safe pure unittest
{
import std.encoding;
import std.algorithm.searching : find;
import std.utf : byDchar;
assert("The quick brown fox"
.byDchar
.find!(x => !canEncode!AsciiChar(x))
.empty);
}
@system pure unittest
{
import std.encoding;
assert(!isValidCodeUnit(cast(char) 0xC0));
assert(!isValidCodeUnit(cast(char) 0xFF));
assert( isValidCodeUnit(cast(wchar) 0xD800));
assert(!isValidCodeUnit(cast(dchar) 0xD800));
assert(!isValidCodeUnit(cast(AsciiChar) 0xA0));
assert( isValidCodeUnit(cast(Windows1250Char) 0x80));
assert(!isValidCodeUnit(cast(Windows1250Char) 0x81));
assert( isValidCodeUnit(cast(Windows1251Char) 0x80));
assert(!isValidCodeUnit(cast(Windows1251Char) 0x98));
assert( isValidCodeUnit(cast(Windows1252Char) 0x80));
assert(!isValidCodeUnit(cast(Windows1252Char) 0x81));
}
@system pure unittest
{
import std.encoding;
assert( isValid("\u20AC100"));
assert(!isValid(cast(char[3])[167, 133, 175]));
}
@system pure unittest
{
import std.encoding;
assert(sanitize("hello \xF0\x80world") == "hello \xEF\xBF\xBDworld");
}
@system pure unittest
{
import std.encoding;
assert(firstSequence("\u20AC1000") == "\u20AC".length);
assert(firstSequence("hel") == "h".length);
}
@system pure unittest
{
import std.encoding;
assert(lastSequence("1000\u20AC") == "\u20AC".length);
assert(lastSequence("hellö") == "ö".length);
}
@system pure unittest
{
import std.encoding;
assert(index("\u20AC100",1) == 3);
assert(index("hällo",2) == 3);
}
@system unittest
{
import std.encoding;
string s = "hello";
string t;
foreach (c;codePoints(s))
{
t ~= cast(char) c;
}
assert(s == t);
}
@system unittest
{
import std.encoding;
char[] a;
foreach (c;codeUnits!(char)(cast(dchar)'\u20AC'))
{
a ~= c;
}
assert(a.length == 3);
assert(a[0] == 0xE2);
assert(a[1] == 0x82);
assert(a[2] == 0xAC);
}
@system pure unittest
{
import std.encoding;
wstring ws;
// transcode from UTF-8 to UTF-16
transcode("hello world",ws);
assert(ws == "hello world"w);
Latin1String ls;
// transcode from UTF-16 to ISO-8859-1
transcode(ws, ls);
assert(ls == "hello world");
}
@system unittest
{
import std.encoding;
import std.format : format;
auto ts = dchar(0x0000FEFF) ~ "Hello World"d;
auto entry = getBOM(cast(ubyte[]) ts);
version (BigEndian)
{
assert(entry.schema == BOM.utf32be, format("%s", entry.schema));
}
else
{
assert(entry.schema == BOM.utf32le, format("%s", entry.schema));
}
}