// This file is part of GAnarchy - decentralized development hub
// Copyright (C) 2021 Soni L.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
//! Unit tests for the effective module.
use std::collections::BTreeSet;
use impl_trait::impl_trait;
use url::Url;
use crate::data::{
DataSource,
DataSourceBase,
Update,
};
use crate::data::kinds::{
InstanceBaseUrl,
InstanceTitle,
ProjectFork,
RepoListUrl,
};
use super::{EffectiveDataSource, EffectiveKind};
/// A helper to test [`EffectiveDataSource`] and [`EffectiveKind`].
struct EffectiveTester;
impl_trait! {
impl EffectiveTester {
/// Always updates with no stats.
impl trait DataSourceBase {
fn update(&mut self) -> Update {
Update::default()
}
fn exists(&self) -> bool {
true
}
}
/// [`InstanceTitle`] effectiveness tester.
impl trait DataSource {
fn get_values(&self) -> Option {
Some(String::new().into())
}
}
/// [`InstanceBaseUrl`] effectiveness tester.
impl trait DataSource {
fn get_values(&self) -> Option {
None
}
}
/// [`RepoListUrl`] effectiveness tester.
impl trait DataSource {
fn get_values(&self) -> Vec {
// TWO for the same url
vec![
RepoListUrl::new_for({
Url::parse("https://example.org").unwrap()
}),
RepoListUrl::new_for({
Url::parse("https://example.org").unwrap()
}),
]
}
}
/// [`ProjectFork`] effectiveness tester.
impl trait DataSource> {
fn get_values(&self) -> BTreeSet> {
vec![
].into_iter().collect()
}
}
impl trait std::fmt::Display {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "tester")
}
}
}
}
/// Tests that the `Option` data sources pass through.
#[test]
fn test_options() {
let eds = EffectiveDataSource(EffectiveTester);
assert_eq!(None, DataSource::::get_values(&eds));
assert_eq!("", DataSource::::get_values(&eds).unwrap().0);
}