<commit_before>import ceylon.test { test, assertEquals }
import ceylon.build.task { goal, noop, NoOp }
import ceylon.build.runner { goalDefinition, goalDeclarationsFromIncludes }
import ceylon.collection { HashSet }

class Container() {
    
    shared goal void goalMethod() {
        accumulator.add(`function goalMethod`.name);
    }
    
    shared goal("goal-with-name-specified-method") void goalWithNameSpecifiedMethod() {
        accumulator.add(`function goalWithNameSpecifiedMethod`.name);
    }
    
    // FIXME not possible because of "metamodel reference to local declaration" error
    // TODO when it will be possible, need to be able to access it and to add a test for it
    //goal void internalGoalMethod() {
    //    accumulator.add(`function internalGoalMethod`.name);
    //}

    shared goal Integer goalMethodWithReturnType() {
        accumulator.add(`function goalMethodWithReturnType`.name);
        return 0;
    }
    
    shared goal void invalidGoalMethod(Object parameter) {
        accumulator.add(`function invalidGoalMethod`.name);
    }
    
    shared goal Anything invalidGoalAttribute = noop;
    
    shared goal NoOp noopGoalAttribute = noop;
}

test void shouldBuildGoalDefinitionFromMethod() {
    value container = Container();
    checkGoalDefinition {
        goal = goalDefinition(`function Container.goalMethod`, emptyPhases, container);
        expectedDefinition = ExpectedDefinition("goalMethod");
        expectedAccumulatorContent = ["goalMethod"];
    };
}

// TODO add tests with inheritance (goal name specified in supertype, and another test were refined in subtype)
test void shouldBuildGoalDefinitionFromMethodWithNameSpecified() {
    value container = Container();
    checkGoalDefinition {
        goal = goalDefinition(`function Container.goalWithNameSpecifiedMethod`, emptyPhases, container);
        expectedDefinition = ExpectedDefinition("goal-with-name-specified-method");
        expectedAccumulatorContent = ["goalWithNameSpecifiedMethod"];
    };
}

test void shouldBuildGoalDefinitionFromMethodWithReturnType() {
    value container = Container();
    checkGoalDefinition {
        goal = goalDefinition(`function Container.goalMethodWithReturnType`, emptyPhases, container);
        expectedDefinition = ExpectedDefinition {
            name = "goalMethodWithReturnType";
        };
        expectedAccumulatorContent = ["goalMethodWithReturnType"];
    };
}

test void shouldBuildGoalDefinitionFromNoOpAttribute() {
    value container = Container();
    checkGoalDefinition {
        goal = goalDefinition(`value Container.noopGoalAttribute`, emptyPhases, container);
        expectedDefinition = ExpectedDefinition {
            name = "noopGoalAttribute";
            task = false;
        };
        expectedAccumulatorContent = [];
    };
}

test void shouldFailToBuildInvalidGoalDefinitionMethod() {
    value container = Container();
    checkInvalidGoalDefinition(goalDefinition(`function Container.invalidGoalMethod`, emptyPhases, container));
}

test void shouldFailToBuildInvalidGoalDefinitionAttribute() {
    value container = Container();
    checkInvalidGoalDefinition(goalDefinition(`value Container.invalidGoalAttribute`, emptyPhases, container));
}

Container containerValue = Container();

test void shouldFindIncludedGoals() {
    value definitions = goalDeclarationsFromIncludes([`value containerValue`]);
    assertEquals {
        actual = HashSet { elements = definitions; };
        expected = HashSet {
            `function Container.goalMethod` -> containerValue,
            `function Container.goalWithNameSpecifiedMethod` -> containerValue,
            `function Container.goalMethodWithReturnType` -> containerValue,
            `function Container.invalidGoalMethod` -> containerValue,
            `value Container.invalidGoalAttribute` -> containerValue,
            `value Container.noopGoalAttribute` -> containerValue
        };
    };
}
<commit_msg>Removed value meta model due to bug ceylon/ceylon-compiler#2160<commit_after>import ceylon.test { test, assertEquals }
import ceylon.build.task { goal, noop, NoOp }
import ceylon.build.runner { goalDefinition, goalDeclarationsFromIncludes }
import ceylon.collection { HashSet }

class Container() {
    
    shared goal void goalMethod() {
        accumulator.add(`function goalMethod`.name);
    }
    
    shared goal("goal-with-name-specified-method") void goalWithNameSpecifiedMethod() {
        accumulator.add(`function goalWithNameSpecifiedMethod`.name);
    }
    
    // FIXME not possible because of "metamodel reference to local declaration" error
    // TODO when it will be possible, need to be able to access it and to add a test for it
    //goal void internalGoalMethod() {
    //    accumulator.add(`function internalGoalMethod`.name);
    //}

    shared goal Integer goalMethodWithReturnType() {
        accumulator.add(`function goalMethodWithReturnType`.name);
        return 0;
    }
    
    shared goal void invalidGoalMethod(Object parameter) {
        accumulator.add(`function invalidGoalMethod`.name);
    }
    
    shared goal Anything invalidGoalAttribute = noop;
    
    shared goal NoOp noopGoalAttribute = noop;
}

test void shouldBuildGoalDefinitionFromMethod() {
    value container = Container();
    checkGoalDefinition {
        goal = goalDefinition(`function Container.goalMethod`, emptyPhases, container);
        expectedDefinition = ExpectedDefinition("goalMethod");
        expectedAccumulatorContent = ["goalMethod"];
    };
}

// TODO add tests with inheritance (goal name specified in supertype, and another test were refined in subtype)
test void shouldBuildGoalDefinitionFromMethodWithNameSpecified() {
    value container = Container();
    checkGoalDefinition {
        goal = goalDefinition(`function Container.goalWithNameSpecifiedMethod`, emptyPhases, container);
        expectedDefinition = ExpectedDefinition("goal-with-name-specified-method");
        expectedAccumulatorContent = ["goalWithNameSpecifiedMethod"];
    };
}

test void shouldBuildGoalDefinitionFromMethodWithReturnType() {
    value container = Container();
    checkGoalDefinition {
        goal = goalDefinition(`function Container.goalMethodWithReturnType`, emptyPhases, container);
        expectedDefinition = ExpectedDefinition {
            name = "goalMethodWithReturnType";
        };
        expectedAccumulatorContent = ["goalMethodWithReturnType"];
    };
}

test void shouldBuildGoalDefinitionFromNoOpAttribute() {
    value container = Container();
    checkGoalDefinition {
        goal = goalDefinition(`value Container.noopGoalAttribute`, emptyPhases, container);
        expectedDefinition = ExpectedDefinition {
            name = "noopGoalAttribute";
            task = false;
        };
        expectedAccumulatorContent = [];
    };
}

test void shouldFailToBuildInvalidGoalDefinitionMethod() {
    value container = Container();
    checkInvalidGoalDefinition(goalDefinition(`function Container.invalidGoalMethod`, emptyPhases, container));
}

test void shouldFailToBuildInvalidGoalDefinitionAttribute() {
    value container = Container();
    checkInvalidGoalDefinition(goalDefinition(`value Container.invalidGoalAttribute`, emptyPhases, container));
}

Container containerValue = Container();

test void shouldFindIncludedGoals() {
    value definitions = goalDeclarationsFromIncludes([`value containerValue`]);
    assertEquals {
        actual = HashSet { elements = definitions; };
        expected = HashSet {
            `function Container.goalMethod` -> containerValue,
            `function Container.goalWithNameSpecifiedMethod` -> containerValue,
            `function Container.goalMethodWithReturnType` -> containerValue,
            `function Container.invalidGoalMethod` -> containerValue
            // TODO add again when type inference of `value x` is fixed, bug ceylon/ceylon-compiler#2160
            // `value Container.invalidGoalAttribute` -> containerValue,
            // `value Container.noopGoalAttribute` -> containerValue
        };
    };
}

{'fraction_non_alphanumeric': 0.087569573283859, 'fraction_numerical': 0.0012368583797155227, 'mean_word_length': 3.6821077012159815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1565545', 'n_tokens_mistral': 2047, 'n_tokens_neox': 1972, 'n_words': 484}