<commit_before>import ceylon.test {
    test
}

shared test
void voidFunctionTest() {
    compileAndCompare {
         """void simpleFunction() { return; }
         """;

         """import "dart:core" as $dart$core;
            import "package:ceylon/language/language.dart" as $ceylon$language;

            void simpleFunction() {
                return;
            }
         """;
    };
}

shared test
void anonymousFunctionTest() {
    compileAndCompare {
         """void simpleFunction() {
                String() anon = () => "result";
                print(anon());
            }
         """;

        // FIXME this is what we get now....
        //       which is sort of correct, since the anonymous function
        //       needs to be boxed
         """import "dart:core" as $dart$core;
            import "package:ceylon/language/language.dart" as $ceylon$language;

            void simpleFunction() {
                $dart$core.Function anon = () => "result";
                print(anon());
            }
         """;
    };
}

shared test
void functionReturnBoxingTest() {
    // FIXME bad code; need to box the function to box the result
    compileAndCompare {
         """void simpleFunction() {
                Anything() anon = () => "result";
                print(anon());
            }
         """;

         """import "dart:core" as $dart$core;
            import "package:ceylon/language/language.dart" as $ceylon$language;

            void simpleFunction() {
                $dart$core.Function anon = () => "result";
                print(anon());
            }
         """;
    };
}

shared test
void nestedFunctionTest() {
    compileAndCompare {
         """void simpleFunction() {
                String nested1() => "result1";
                Object nested2() { return "result2"; }
                print(nested1());
                print(nested2());
            }
         """;

         """import "dart:core" as $dart$core;
            import "package:ceylon/language/language.dart" as $ceylon$language;

            void simpleFunction() {
                $dart$core.String nested1() => "result1";

                $dart$core.Object nested2() {
                    return $ceylon$language.dart$nativeToCeylonString("result2");
                }

                print($ceylon$language.dart$nativeToCeylonString(nested1()));
                print(nested2());
            }
         """;
    };
}

shared test
void functionReferenceTest() {
    // TODO this works, but pretty much by accident
    compileAndCompare {
         """void simpleFunction() {
                String nested1() => "result1";
                value nested1Ref = nested1;
                print(nested1());
            }
         """;

         """import "dart:core" as $dart$core;
            import "package:ceylon/language/language.dart" as $ceylon$language;

            void simpleFunction() {
                $dart$core.String nested1() => "result1";

                $dart$core.Function nested1Ref = nested1;
                print($ceylon$language.dart$nativeToCeylonString(nested1()));
            }
         """;
    };
}<commit_msg>add test for defaulted parameters<commit_after>import ceylon.test {
    test
}

shared test
void voidFunctionTest() {
    compileAndCompare {
         """void simpleFunction() { return; }
         """;

         """import "dart:core" as $dart$core;
            import "package:ceylon/language/language.dart" as $ceylon$language;

            void simpleFunction() {
                return;
            }
         """;
    };
}

shared test
void anonymousFunctionTest() {
    compileAndCompare {
         """void simpleFunction() {
                String() anon = () => "result";
                print(anon());
            }
         """;

        // FIXME this is what we get now....
        //       which is sort of correct, since the anonymous function
        //       needs to be boxed
         """import "dart:core" as $dart$core;
            import "package:ceylon/language/language.dart" as $ceylon$language;

            void simpleFunction() {
                $dart$core.Function anon = () => "result";
                print(anon());
            }
         """;
    };
}

shared test
void functionReturnBoxingTest() {
    // FIXME bad code; need to box the function to box the result
    compileAndCompare {
         """void simpleFunction() {
                Anything() anon = () => "result";
                print(anon());
            }
         """;

         """import "dart:core" as $dart$core;
            import "package:ceylon/language/language.dart" as $ceylon$language;

            void simpleFunction() {
                $dart$core.Function anon = () => "result";
                print(anon());
            }
         """;
    };
}

shared test
void nestedFunctionTest() {
    compileAndCompare {
         """void simpleFunction() {
                String nested1() => "result1";
                Object nested2() { return "result2"; }
                print(nested1());
                print(nested2());
            }
         """;

         """import "dart:core" as $dart$core;
            import "package:ceylon/language/language.dart" as $ceylon$language;

            void simpleFunction() {
                $dart$core.String nested1() => "result1";

                $dart$core.Object nested2() {
                    return $ceylon$language.dart$nativeToCeylonString("result2");
                }

                print($ceylon$language.dart$nativeToCeylonString(nested1()));
                print(nested2());
            }
         """;
    };
}

shared test
void functionReferenceTest() {
    // TODO this works, but pretty much by accident
    compileAndCompare {
         """void simpleFunction() {
                String nested1() => "result1";
                value nested1Ref = nested1;
                print(nested1());
            }
         """;

         """import "dart:core" as $dart$core;
            import "package:ceylon/language/language.dart" as $ceylon$language;

            void simpleFunction() {
                $dart$core.String nested1() => "result1";

                $dart$core.Function nested1Ref = nested1;
                print($ceylon$language.dart$nativeToCeylonString(nested1()));
            }
         """;
    };
}

shared test
void functionDefaultedParameters() {
    compileAndCompare {
         """shared Integer withDefaults(Integer x = 1, Integer y = 2) {
                return y;
            }

            shared void run() {
                withDefaults(3);
                withDefaults(4, 5);
            }
         """;

         """import "dart:core" as $dart$core;
            import "package:ceylon/language/language.dart" as $ceylon$language;

            $dart$core.int withDefaults([$dart$core.int x = $ceylon$language.dart$defaulted, $dart$core.int y = $ceylon$language.dart$defaulted]) {
                if ($dart$core.identical(x, $ceylon$language.dart$defaulted)) {
                    x = 1;
                }
                if ($dart$core.identical(y, $ceylon$language.dart$defaulted)) {
                    y = 2;
                }
                return y;
            }

            void run() {
                withDefaults(3);
                withDefaults(4, 5);
            }""";
     };
}
{'fraction_non_alphanumeric': 0.1296170096769797, 'fraction_numerical': 0.007359956385443642, 'mean_word_length': 1.569327731092437, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4153105', 'n_tokens_mistral': 2052, 'n_tokens_neox': 1942, 'n_words': 413}