<commit_before>import ceylon.file {
    parsePath,
    Nil,
    ExistingResource,
    Directory
}
import ceylon.test {
    assertEquals
}

import com.vasileff.ceylon.dart.compiler {
    testCompile,
    testModuleCompile
}

import java.nio.file {
    JFiles=Files
}

void compileAndCompare(String key) {
    value ceylonPathPart = key +  ".tceylon";
    value dartPathPart = key +  ".tdart";

    assert (exists ceylonResource
        =   `module`.resourceByPath(ceylonPathPart));

    assert (nonempty files
        =   splitBetween(ceylonResource.textContent().lines)((first, second)
                =>  second.startsWith("// file:")).sequence());

    value dartUnits
        =   if (files.size == 1) then
                // single file, not a module
                testCompile {
                    verbose = false;
                    "\n".join(files[0])
                }
            else
                // multiple source files separated by comment of the form:
                //      // file:path/filename.ceylon
                testModuleCompile {
                    verbose = false;
                    suppressAllWarnings = true;
                    files.map((lines)
                        =>  lines.first[8...].trimmed
                                -> "\n".join(lines.rest));
                };

    value dartCode
        =   "\n".join(dartUnits.interpose("/".repeat(70)));

    if (outputToTemp) {
        writeNewTempFile(dartPathPart, dartCode);
    }

    value dartText
        =   `module`.resourceByPath(dartPathPart)?.textContent() else "";

    assertEquals {
        actual = dartCode.trimmed;
        expected =  dartText.trimmed;
    };
}

Directory tempDirectory
    =   createTemporaryDirectory("ceylon-dart-test");

Boolean outputToTemp
    =   process.propertyValue("output-to-temp") exists;

void writeNewTempFile(String pathPart, String content) {
    value tempPath = tempDirectory.path;
    value dartPath = tempPath.childPath(pathPart);
    switch (dartFileResource = dartPath.resource)
    case (is Nil) {
        process.writeErrorLine("Outputing file: \
                                '``dartPath.string``'");
        value dartFile = dartFileResource.createFile(true);
        value appender = dartFile.Appender();
        appender.write(content);
        appender.close();<commit_msg>properly trim test output<commit_after>import ceylon.file {
    parsePath,
    Nil,
    ExistingResource,
    Directory
}
import ceylon.test {
    assertEquals
}

import com.vasileff.ceylon.dart.compiler {
    testCompile,
    testModuleCompile
}

import java.nio.file {
    JFiles=Files
}

void compileAndCompare(String key) {
    value ceylonPathPart = key +  ".tceylon";
    value dartPathPart = key +  ".tdart";

    assert (exists ceylonResource
        =   `module`.resourceByPath(ceylonPathPart));

    assert (nonempty files
        =   splitBetween(ceylonResource.textContent().lines)((first, second)
                =>  second.startsWith("// file:")).sequence());

    value dartUnits
        =   if (files.size == 1) then
                // single file, not a module
                testCompile {
                    verbose = false;
                    "\n".join(files[0])
                }
            else
                // multiple source files separated by comment of the form:
                //      // file:path/filename.ceylon
                testModuleCompile {
                    verbose = false;
                    suppressAllWarnings = true;
                    files.map((lines)
                        =>  lines.first[8...].trimmed
                                -> "\n".join(lines.rest));
                };

    value dartCode
        =   "\n".join(dartUnits.interpose("/".repeat(70)));

    if (outputToTemp) {
        writeNewTempFile(dartPathPart, dartCode.trimmed);
    }

    value dartText
        =   `module`.resourceByPath(dartPathPart)?.textContent() else "";

    assertEquals {
        actual = dartCode.trimmed;
        expected =  dartText.trimmed;
    };
}

Directory tempDirectory
    =   createTemporaryDirectory("ceylon-dart-test");

Boolean outputToTemp
    =   process.propertyValue("output-to-temp") exists;

void writeNewTempFile(String pathPart, String content) {
    value tempPath = tempDirectory.path;
    value dartPath = tempPath.childPath(pathPart);
    switch (dartFileResource = dartPath.resource)
    case (is Nil) {
        process.writeErrorLine("Outputing file: \
                                '``dartPath.string``'");
        value dartFile = dartFileResource.createFile(true);
        value appender = dartFile.Appender();
        appender.write(content);
        appender.close();
{'fraction_non_alphanumeric': 0.10909479077711358, 'fraction_numerical': 0.002134927412467976, 'mean_word_length': 1.8973407544836116, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4446490', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1271, 'n_words': 248}