<commit_before>use strict;

use lib '..';
use lib '../..';
use lib '../../platform/lib';
use lib '../lib';
use lib '../../lib';

use Test::More;
use Data::Dumper;
use Eldhelm::Util::Factory;
use Eldhelm::Util::FileSystem;
use Eldhelm::Test::Mock::Worker;

my ($index, $sourceContext, $className) = @ARGV;

unless ($className) {
	plan skip_all => 'This test can not run without a class context';
} else {
	plan 'no_plan';
}

my $config = do '../../config.pl' or die 'Can not read config!';
my $worker = Eldhelm::Test::Mock::Worker->new(config => $config);

my $controller = Eldhelm::Util::Factory->instance($className, router => $worker->{router});
my $source     = Eldhelm::Util::FileSystem->getFileContents($sourceContext);
my @allResources;

diag("Verifying models");
my %models = map { +$_ => 1 } $source =~ /getModel\((.*?)\)/g;
foreach (keys %models) {
	my $val = eval("[$_]");
	next unless $val;
	
	my ($name, $args) = @$val;
	push @allResources, $name;
	eval {
		my $model = $controller->getModel($name, $args);
		ok($model, "Model $name ok");
	} or do {
		note($@);
		fail("Model $name is missing!");
	};
}

diag("Verifying views");
%models = map { +$_ => 1 } $source =~ /getView\((.*?)\)/g;
foreach (keys %models) {
	my $val = eval("[$_]");
	next unless $val;
	
	my ($name, $args) = @$val;
	$args ||= {};
	$args->{worker} = $worker;
	push @allResources, $name;
	eval {
		my $model = $controller->getView($name, $args);
		ok($model, "Views $name ok");
		1;
	} or do {
		note($@);
		fail("View $name is missing!");
	};
}

diag("Verifying controllers");
%models = map { +$_ => 1 } $source =~ /getController\((.*?)\)/g;
foreach (keys %models) {
	my $name = eval($_);
	next unless $name;
	
	push @allResources, $name;
	eval {
		my $model = $controller->getController($name);
		ok($model, "Views $name ok");
		1;
	} or do {
		note($@);
		fail("Controller $name is missing!");
	};
}

diag("Verifying scripts");
%models = map { +$_ => 1 } $source =~ /getScript\((.*?)\)/g;
foreach (keys %models) {
	my $name = eval($_);
	next unless $name;
	
	push @allResources, $name;
	eval {
		my $model = $controller->getScript($name);
		ok($model, "Scripts $name ok");
		1;
	} or do {<commit_msg>testing the public and export methods<commit_after>use strict;

use lib '..';
use lib '../..';
use lib '../../platform/lib';
use lib '../lib';
use lib '../../lib';

use Test::More;
use Data::Dumper;
use Eldhelm::Util::Factory;
use Eldhelm::Util::FileSystem;
use Eldhelm::Test::Mock::Worker;

my ($index, $sourceContext, $className) = @ARGV;

unless ($className) {
	plan skip_all => 'This test can not run without a class context';
} else {
	plan 'no_plan';
}

my $config = do '../../config.pl' or die 'Can not read config!';
my $worker = Eldhelm::Test::Mock::Worker->new(config => $config);

diag("Verifying construction");
my $controller = Eldhelm::Util::Factory->instance($className, router => $worker->{router});
my $source = Eldhelm::Util::FileSystem->getFileContents($sourceContext);

my %methods = %{ $controller->{exported} }, %{ $controller->{public} };
foreach (keys %methods) {
	ok($source =~ /sub[\s\t]+$_[\s\t]\{/, "Public or exported method $_");
}
diag(Dumper [keys %methods]);

my @allResources;

diag("Verifying models");
my %models = map { +$_ => 1 } $source =~ /getModel\((.*?)\)/g;
foreach (keys %models) {
	my $val = eval("[$_]");
	next unless $val;

	my ($name, $args) = @$val;
	push @allResources, $name;
	eval {
		my $model = $controller->getModel($name, $args);
		ok($model, "Model $name ok");
	} or do {
		note($@);
		fail("Model $name is missing!");
	};
}

diag("Verifying views");
%models = map { +$_ => 1 } $source =~ /getView\((.*?)\)/g;
foreach (keys %models) {
	my $val = eval("[$_]");
	next unless $val;

	my ($name, $args) = @$val;
	$args ||= {};
	$args->{worker} = $worker;
	push @allResources, $name;
	eval {
		my $model = $controller->getView($name, $args);
		ok($model, "Views $name ok");
		1;
	} or do {
		note($@);
		fail("View $name is missing!");
	};
}

diag("Verifying controllers");
%models = map { +$_ => 1 } $source =~ /getController\((.*?)\)/g;
foreach (keys %models) {
	my $name = eval($_);
	next unless $name;

	push @allResources, $name;
	eval {
		my $model = $controller->getController($name);
		ok($model, "Views $name ok");
		1;
	} or do {
		note($@);
		fail("Controller $name is missing!");
	};
}

diag("Verifying scripts");
%models = map { +$_ => 1 } $source =~ /getScript\((.*?)\)/g;
foreach (keys %models) {
	my $name = eval($_);
	next unless $name;

	push @allResources, $name;
	eval {
		my $model = $controller->getScript($name);
		ok($model, "Scripts $name ok");
		1;
	} or do {
{'fraction_non_alphanumeric': 0.23106880138468194, 'fraction_numerical': 0.003028991778450887, 'mean_word_length': 4.108287292817679, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '3843329', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1672, 'n_words': 459}