Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move tests into separate files #132

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ component_management:
name: Other
paths:
- src/errors/**
- src/integrations/**
- src/primitives/**
- src/specification/**
- src/*.rs
4 changes: 1 addition & 3 deletions .github/workflows/pr-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
directory: target/coverage
files: target/codecov.json
fail_ci_if_error: true
gcov: true
gcov_ignore: "src/main.rs,src/**/tests.rs,tests/**"
token: ${{ secrets.CODECOV_TOKEN }}
7 changes: 0 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,3 @@ serde_with = "2.0.0"
codegen-units = 1
lto = true
opt-level = 3

[profile.coverage]
inherits = "test"
codegen-units = 1
incremental = false
opt-level = 0
panic = "abort"
22 changes: 1 addition & 21 deletions src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,4 @@ impl fmt::Display for TransmuteError {
impl Error for TransmuteError {}

#[cfg(test)]
mod tests {
use serde::de::Error;

use super::*;

#[test]
fn test_transmute_error() {
let error = TransmuteError::new("Test error message");

assert_eq!(error.details, "Test error message");
assert_eq!(error.to_string(), "TransmuteError: Test error message");
}

#[test]
fn test_transmute_error_from() {
let yaml_error = serde_yaml::Error::custom("YAML parsing error");
let transmute_error: TransmuteError = yaml_error.into();

assert_eq!(transmute_error.details, "YAML parsing error");
}
}
mod tests;
19 changes: 19 additions & 0 deletions src/errors/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use serde::de::Error;

use super::*;

#[test]
fn test_transmute_error() {
let error = TransmuteError::new("Test error message");

assert_eq!(error.details, "Test error message");
assert_eq!(error.to_string(), "TransmuteError: Test error message");
}

#[test]
fn test_transmute_error_from() {
let yaml_error = serde_yaml::Error::custom("YAML parsing error");
let transmute_error: TransmuteError = yaml_error.into();

assert_eq!(transmute_error.details, "YAML parsing error");
}
1 change: 0 additions & 1 deletion src/integrations/iam.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/integrations/mod.rs

This file was deleted.

60 changes: 1 addition & 59 deletions src/ir/conditions.rs → src/ir/conditions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,62 +189,4 @@ impl ConditionValue {
}

#[cfg(test)]
mod tests {
use indexmap::IndexMap;

use crate::ir::conditions::{determine_order, ConditionIr};
use crate::ir::reference::{Origin, PseudoParameter, Reference};
use crate::parser::condition::{ConditionFunction, ConditionValue};

#[test]
fn test_eq_translation() {
let condition_structure = ConditionFunction::Equals(
ConditionValue::String("us-west-2".into()),
ConditionValue::Ref("AWS::Region".into()),
);

let condition_ir = condition_structure.into_ir();
assert_eq!(
ConditionIr::Equals(
Box::new(ConditionIr::Str("us-west-2".into())),
Box::new(ConditionIr::Ref(Reference::new(
"AWS::Region",
Origin::PseudoParameter(PseudoParameter::Region)
)))
),
condition_ir
);
}

#[test]
fn test_sorting() {
let a = ConditionFunction::Equals(
ConditionValue::Ref("Foo".into()),
ConditionValue::Ref("Bar".into()),
);

let b = ConditionFunction::Not(ConditionValue::Condition("A".into()));

let hash = IndexMap::from([("A".into(), a), ("B".into(), b)]);
let ordered = determine_order(&hash);

assert_eq!(ordered, vec!["A", "B"]);
}

#[test]
fn test_condition_translation() {
let condition_structure: ConditionValue = ConditionValue::Condition("other".into());
let condition_ir = condition_structure.into_ir();
assert_eq!(
(ConditionIr::Ref(Reference::new("other", Origin::Condition))),
condition_ir
);
}

fn test_simple() {
assert_eq!(
ConditionIr::Str("hi".into()),
ConditionValue::String("hi".into()).into_ir()
);
}
}
mod tests;
58 changes: 58 additions & 0 deletions src/ir/conditions/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use indexmap::IndexMap;

use crate::ir::conditions::{determine_order, ConditionIr};
use crate::ir::reference::{Origin, PseudoParameter, Reference};
use crate::parser::condition::{ConditionFunction, ConditionValue};

#[test]
fn test_eq_translation() {
let condition_structure = ConditionFunction::Equals(
ConditionValue::String("us-west-2".into()),
ConditionValue::Ref("AWS::Region".into()),
);

let condition_ir = condition_structure.into_ir();
assert_eq!(
ConditionIr::Equals(
Box::new(ConditionIr::Str("us-west-2".into())),
Box::new(ConditionIr::Ref(Reference::new(
"AWS::Region",
Origin::PseudoParameter(PseudoParameter::Region)
)))
),
condition_ir
);
}

#[test]
fn test_sorting() {
let a = ConditionFunction::Equals(
ConditionValue::Ref("Foo".into()),
ConditionValue::Ref("Bar".into()),
);

let b = ConditionFunction::Not(ConditionValue::Condition("A".into()));

let hash = IndexMap::from([("A".into(), a), ("B".into(), b)]);
let ordered = determine_order(&hash);

assert_eq!(ordered, vec!["A", "B"]);
}

#[test]
fn test_condition_translation() {
let condition_structure: ConditionValue = ConditionValue::Condition("other".into());
let condition_ir = condition_structure.into_ir();
assert_eq!(
(ConditionIr::Ref(Reference::new("other", Origin::Condition))),
condition_ir
);
}

#[test]
fn test_simple() {
assert_eq!(
ConditionIr::Str("hi".into()),
ConditionValue::String("hi".into()).into_ir()
);
}
99 changes: 0 additions & 99 deletions src/ir/constructor.rs

This file was deleted.

33 changes: 33 additions & 0 deletions src/ir/constructor/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use crate::parser::parameters::Parameter;
use indexmap::IndexMap;
use voca_rs::case::camel_case;

pub struct Constructor {
pub inputs: Vec<ConstructorParameter>,
}

impl Constructor {
pub(super) fn from<S>(parse_tree: IndexMap<String, Parameter, S>) -> Self {
Self {
inputs: parse_tree
.into_iter()
.map(|(name, param)| ConstructorParameter {
name: camel_case(&name),
description: param.description,
constructor_type: param.parameter_type.to_string(),
default_value: param.default,
})
.collect(),
}
}
}

pub struct ConstructorParameter {
pub name: String,
pub description: Option<String>,
pub constructor_type: String,
pub default_value: Option<String>,
}

#[cfg(test)]
mod tests;
Loading