@@ -885,6 +885,73 @@ TEST(lang_cfc_default_on_read_fail) {
885885 PASS ();
886886}
887887
888+ /* ── .d: D source vs make/cargo dep-info ───────────────────────── */
889+
890+ /* Write content to a temp .d file and return cbm_disambiguate_d() for it. A
891+ * setup failure returns -1 so neither a D nor a COUNT expectation can pass
892+ * vacuously. */
893+ static int disambiguate_d_content (const char * content ) {
894+ char path [256 ];
895+ snprintf (path , sizeof (path ), "%s/test_lang_dotd.d" , cbm_tmpdir ());
896+ if (!write_probe_file (path , content )) {
897+ return -1 ;
898+ }
899+ CBMLanguage lang = cbm_disambiguate_d (path );
900+ remove (path );
901+ return (int )lang ;
902+ }
903+
904+ TEST (lang_d_dep_info_unsupported ) {
905+ /* cargo (absolute target), gcc -MD continuation, CMake object rule, Windows
906+ * drive letter (not the rule colon), escaped space (one target, not "app"),
907+ * and the GNU make manual's "foo.o foo.d : ..." (two targets, spaced colon). */
908+ ASSERT_EQ (disambiguate_d_content ("/home/u/t/debug/deps/foo-abc123.d: src/lib.rs src/a.rs\n"
909+ "\nsrc/lib.rs:\n" ),
910+ CBM_LANG_COUNT );
911+ ASSERT_EQ (disambiguate_d_content ("foo.o: foo.c /usr/include/stdio.h \\\n"
912+ " /usr/include/features.h\n" ),
913+ CBM_LANG_COUNT );
914+ ASSERT_EQ (disambiguate_d_content ("CMakeFiles/x.dir/a.cpp.o: \\\n /src/a.cpp\n" ),
915+ CBM_LANG_COUNT );
916+ ASSERT_EQ (disambiguate_d_content ("C:/b/foo.o: C:/s/foo.c \\\r\n C:/s/foo.h\r\n" ),
917+ CBM_LANG_COUNT );
918+ ASSERT_EQ (disambiguate_d_content ("out/my\\ app: main.c\n" ), CBM_LANG_COUNT );
919+ ASSERT_EQ (disambiguate_d_content ("foo.o foo.d : foo.c defs.h\n" ), CBM_LANG_COUNT );
920+ PASS ();
921+ }
922+
923+ TEST (lang_d_source_stays_dlang ) {
924+ ASSERT_EQ (disambiguate_d_content ("module a;\n" ), CBM_LANG_DLANG );
925+ ASSERT_EQ (disambiguate_d_content ("import std.stdio : writeln;\n" ), CBM_LANG_DLANG );
926+ ASSERT_EQ (disambiguate_d_content ("@safe:\nvoid f() {}\n" ), CBM_LANG_DLANG );
927+ /* A leading comment is D, even DUB's "/+ dub.sdl:" single-file recipe. */
928+ ASSERT_EQ (disambiguate_d_content ("/+ dub.sdl:\n name \"hello\"\n+/\nvoid main() {}\n" ),
929+ CBM_LANG_DLANG );
930+ ASSERT_EQ (disambiguate_d_content ("enum E : ubyte {\n a,\n}\n" ), CBM_LANG_DLANG );
931+ /* A float UDA ("@ FloatLiteral") has a '.' before its colon, alone or glued
932+ * to a keyword. */
933+ ASSERT_EQ (disambiguate_d_content ("@1.0:\nvoid f() {}\n" ), CBM_LANG_DLANG );
934+ ASSERT_EQ (disambiguate_d_content ("nothrow@1.0:\nvoid f() {}\n" ), CBM_LANG_DLANG );
935+ /* A comment between tokens puts a '/' before the colon. */
936+ ASSERT_EQ (disambiguate_d_content ("public/**/:\nvoid f() {}\n" ), CBM_LANG_DLANG );
937+ ASSERT_EQ (disambiguate_d_content ("public/+ +/:\nvoid f() {}\n" ), CBM_LANG_DLANG );
938+ ASSERT_EQ (disambiguate_d_content ("public//note: x\nvoid f() {}\n" ), CBM_LANG_DLANG );
939+ /* Every D whitespace splits tokens, not only space, tab and CR: form feed,
940+ * vertical tab, U+2028 and U+2029. */
941+ ASSERT_EQ (disambiguate_d_content ("import\fstd.stdio : writeln;\n" ), CBM_LANG_DLANG );
942+ ASSERT_EQ (disambiguate_d_content ("import\vstd.stdio : writeln;\n" ), CBM_LANG_DLANG );
943+ ASSERT_EQ (disambiguate_d_content ("import\xE2\x80\xA8"
944+ "std.stdio : writeln;\n" ),
945+ CBM_LANG_DLANG );
946+ ASSERT_EQ (disambiguate_d_content ("import\xE2\x80\xA9"
947+ "std.stdio : writeln;\n" ),
948+ CBM_LANG_DLANG );
949+ /* Default on doubt: empty or unreadable. */
950+ ASSERT_EQ (disambiguate_d_content ("" ), CBM_LANG_DLANG );
951+ ASSERT_EQ (cbm_disambiguate_d ("/tmp/nonexistent_file_12345.d" ), CBM_LANG_DLANG );
952+ PASS ();
953+ }
954+
888955/* --- New languages (auto-generated) --- */
889956TEST (lang_ext_solidity ) {
890957 ASSERT_EQ (cbm_language_for_extension (".sol" ), CBM_LANG_SOLIDITY );
@@ -1398,6 +1465,7 @@ TEST(lang_probe_bytes_follow_the_name) {
13981465 ASSERT_EQ (cbm_language_probe_bytes ("foo.inc" ), 4096 );
13991466 ASSERT_EQ (cbm_language_probe_bytes ("Form1.frm" ), 4096 );
14001467 ASSERT_EQ (cbm_language_probe_bytes ("App.res" ), 4096 );
1468+ ASSERT_EQ (cbm_language_probe_bytes ("app.d" ), 4096 );
14011469 ASSERT_EQ (cbm_language_probe_bytes ("Widget.cfc" ), 16384 );
14021470 ASSERT_EQ (cbm_language_probe_bytes ("pom.xml" ), 255 );
14031471 /* An unknown name falls back to a shebang probe of the first line. */
@@ -1439,6 +1507,9 @@ TEST(lang_classify_matches_every_content_rule) {
14391507 {"p.frm" , "#procedure foo\nLocal F = a;\n" , CBM_LANG_FORM , cbm_disambiguate_frm },
14401508 {"q.res" , "RSRC\0\0\0\1binary" , CBM_LANG_COUNT , cbm_disambiguate_res },
14411509 {"r.res" , "let x = 1\n" , CBM_LANG_RESCRIPT , cbm_disambiguate_res },
1510+ {"dep.d" , "target/debug/deps/app-0a1b2c.d: src/main.rs src/lib.rs\n" , CBM_LANG_COUNT ,
1511+ cbm_disambiguate_d },
1512+ {"app.d" , "module app;\nimport std.stdio : writeln;\n" , CBM_LANG_DLANG , cbm_disambiguate_d },
14421513 {"s.xml" , "<?xml version=\"1.0\"?>\n<Export generator=\"IRIS\" version=\"26\">\n" ,
14431514 CBM_LANG_OBJECTSCRIPT_EXPORT , NULL },
14441515 {"t.xml" , "<?xml version=\"1.0\"?>\n<project/>\n" , CBM_LANG_XML , NULL },
@@ -1486,6 +1557,7 @@ TEST(lang_classify_unreadable_content_keeps_the_name_default) {
14861557 ASSERT_EQ (cbm_language_classify ("a.cfc" , NULL , 0 , false, false), CBM_LANG_CFSCRIPT );
14871558 ASSERT_EQ (cbm_language_classify ("a.frm" , NULL , 0 , false, false), CBM_LANG_FORM );
14881559 ASSERT_EQ (cbm_language_classify ("a.res" , NULL , 0 , false, false), CBM_LANG_RESCRIPT );
1560+ ASSERT_EQ (cbm_language_classify ("a.d" , NULL , 0 , false, false), CBM_LANG_DLANG );
14891561 ASSERT_EQ (cbm_language_classify ("a.xml" , NULL , 0 , false, false), CBM_LANG_XML );
14901562 ASSERT_EQ (cbm_language_classify ("run-tests" , NULL , 0 , false, false), CBM_LANG_COUNT );
14911563 ASSERT_EQ (cbm_language_classify ("main.go" , NULL , 0 , false, false), CBM_LANG_GO );
@@ -1716,6 +1788,8 @@ SUITE(language) {
17161788 RUN_TEST (lang_frm_form_stays_form );
17171789 RUN_TEST (lang_res_binary_resource_unsupported );
17181790 RUN_TEST (lang_res_rescript_stays_rescript );
1791+ RUN_TEST (lang_d_dep_info_unsupported );
1792+ RUN_TEST (lang_d_source_stays_dlang );
17191793
17201794 /* Go test ports */
17211795 /* New languages */
0 commit comments