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

support for AMD stocks #104

Merged
merged 8 commits into from
Mar 24, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ jobs:
exit 1
fi
env:
COVERAGE_THRESHOLD: 65
COVERAGE_THRESHOLD: 45
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "etradeTaxReturnHelper"
version = "0.4.6"
version = "0.5.0"
edition = "2021"
description = "Parses etrade financial documents for transaction details (income, tax paid, cost basis) and compute total income and total tax paid according to chosen tax residency (currency)"
license = "BSD-3-Clause"
Expand Down
30 changes: 30 additions & 0 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ impl etradeTaxReturnHelper::Residency for DE {
#[cfg(test)]
mod tests {
use super::*;
use etradeTaxReturnHelper::Residency;

#[test]
fn test_present_result_de() -> Result<(), String> {
let rd: Box<dyn etradeTaxReturnHelper::Residency> = Box::new(DE {});
Expand All @@ -99,4 +101,32 @@ mod tests {

Ok(())
}

#[test]
fn test_get_exchange_rates_eur() -> Result<(), String> {
let mut dates: std::collections::HashMap<
etradeTaxReturnHelper::Exchange,
Option<(String, f32)>,
> = std::collections::HashMap::new();
dates.insert(
etradeTaxReturnHelper::Exchange::USD("07/14/23".to_owned()),
None,
);

let rd: DE = DE {};
rd.get_currency_exchange_rates(&mut dates,"EUR").map_err(|x| "Error: unable to get exchange rates. Please check your internet connection or proxy settings\n\nDetails:".to_string()+x.as_str())?;

let mut expected_result: std::collections::HashMap<
etradeTaxReturnHelper::Exchange,
Option<(String, f32)>,
> = std::collections::HashMap::new();
expected_result.insert(
etradeTaxReturnHelper::Exchange::USD("07/14/23".to_owned()),
Some(("2023-07-13".to_owned(), 0.89077)),
);

assert_eq!(dates, expected_result);

Ok(())
}
}
20 changes: 20 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,26 @@ mod tests {
Ok(())
}

#[test]
fn test_unrecognized_file_taxation() -> Result<(), clap::Error> {
// Get all brokerage with dividends only
let myapp = App::new("E-trade tax helper").setting(AppSettings::ArgRequiredElseHelp);
let rd: Box<dyn etradeTaxReturnHelper::Residency> = Box::new(pl::PL {});
// Check printed values or returned values?
let matches = create_cmd_line_pattern(myapp)
.get_matches_from_safe(vec!["mytest", "unrecognized_file.txt"])?;

let pdfnames = matches
.values_of("financial documents")
.expect_and_log("error getting financial documents names");
let pdfnames: Vec<String> = pdfnames.map(|x| x.to_string()).collect();

match etradeTaxReturnHelper::run_taxation(&rd, pdfnames) {
Ok(_) => panic!("Expected an error from run_taxation, but got Ok"),
Err(_) => Ok(()), // Expected error, test passes
}
}

#[test]
#[ignore]
fn test_dividends_taxation() -> Result<(), clap::Error> {
Expand Down
29 changes: 27 additions & 2 deletions src/pdfparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
fn create_tax_parsing_sequence(sequence: &mut std::collections::VecDeque<Box<dyn Entry>>) {
sequence.push_back(Box::new(StringEntry {
val: String::new(),
patterns: vec!["INTEL CORP".to_owned()],
patterns: vec!["INTEL CORP".to_owned(), "ADVANCED MICRO DEVICES".to_owned()],
}));
sequence.push_back(Box::new(F32Entry { val: 0.0 })); // Tax Entry
}
Expand Down Expand Up @@ -184,7 +184,7 @@
fn create_sold_2_parsing_sequence(sequence: &mut std::collections::VecDeque<Box<dyn Entry>>) {
sequence.push_back(Box::new(StringEntry {
val: String::new(),
patterns: vec!["INTEL CORP".to_owned()],
patterns: vec!["INTEL CORP".to_owned(), "ADVANCED MICRO DEVICES".to_owned()],
}));
sequence.push_back(Box::new(StringEntry {
val: String::new(),
Expand Down Expand Up @@ -379,7 +379,7 @@
sequence: &mut std::collections::VecDeque<Box<dyn Entry>>,
transaction_type: TransactionType,
) -> Result<ParserState, String> {
let mut state = ParserState::ProcessingTransaction(transaction_type.clone());

Check warning on line 382 in src/pdfparser.rs

View workflow job for this annotation

GitHub Actions / coverage

value assigned to `state` is never read
let possible_obj = sequence.pop_front();
match possible_obj {
// Move executed parser objects into Vector
Expand Down Expand Up @@ -1105,6 +1105,31 @@
))
);

assert_eq!(
parse_statement("data/example-sold-amd.pdf"),
Ok((
vec![],
vec![],
vec![
(
"11/10/23".to_owned(),
"11/14/23".to_owned(),
72.0,
118.13,
8505.29
),
(
"11/22/23".to_owned(),
"11/27/23".to_owned(),
162.0,
122.4511,
19836.92
),
],
vec![]
))
);

//TODO(jczaja): Renable reinvest dividends case as soon as you get some PDFs
//assert_eq!(
// parse_statement("data/example3.pdf"),
Expand Down
Loading