Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelangrivera committed Nov 6, 2023
1 parent 5d9067f commit 6a82eeb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
14 changes: 14 additions & 0 deletions crates/does-it-throw/src/fixtures/callExpr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,17 @@ connection.onInitialized(() => {
connection.onInitialized2(() => {
throw new Error('hi khue')
})


SomeRandomCall(() => {
throw new Error('hi khue')
})

SomeRandomCall2(() => {
SomeThrow()
SomeThrow2()
})

connection.oneWithASecondArg({}, () => {
throw new Error('hi khue')
})
31 changes: 22 additions & 9 deletions crates/does-it-throw/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ mod integration_tests {
let (result, _cm) = analyze_code(&sample_code, cm);

// general result assertions
assert_eq!(result.functions_with_throws.len(), 3);
assert_eq!(result.calls_to_throws.len(), 3);
assert_eq!(result.functions_with_throws.len(), 5);
assert_eq!(result.calls_to_throws.len(), 7);
assert_eq!(result.imported_identifier_usages.len(), 0);
assert_eq!(result.import_sources.len(), 0);

Expand All @@ -422,9 +422,15 @@ mod integration_tests {
fn function_names_contains(function_names: &Vec<String>, function_name: &str) -> bool {
function_names.iter().any(|f| f == function_name)
}
["onInitialized2", "SomeThrow2", "SomeThrow"]
.iter()
.for_each(|f| assert!(function_names_contains(&function_names, f)));
[
"onInitialized2",
"SomeThrow2",
"SomeThrow",
"SomeRandomCall",
"oneWithASecondArg",
]
.iter()
.for_each(|f| assert!(function_names_contains(&function_names, f)));

// calls to throws
let calls_to_throws: Vec<String> = result
Expand All @@ -436,9 +442,16 @@ mod integration_tests {
fn calls_to_throws_contains(calls_to_throws: &Vec<String>, call_to_throw: &str) -> bool {
calls_to_throws.iter().any(|c| c == call_to_throw)
}

["NOT_SET-onInitialized", "NOT_SET-onInitialized"]
.iter()
.for_each(|f| assert!(calls_to_throws_contains(&calls_to_throws, f)));
[
"NOT_SET-onInitialized",
"NOT_SET-SomeRandomCall2",
"NOT_SET-<anonymous>",
"connection-<anonymous>",
"NOT_SET-onInitialized",
"NOT_SET-SomeRandomCall2",
"connection-<anonymous>",
]
.iter()
.for_each(|f| assert!(calls_to_throws_contains(&calls_to_throws, f)));
}
}

0 comments on commit 6a82eeb

Please sign in to comment.