diff options
author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-05-06 16:54:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-06 23:54:52 +0000 |
commit | 672216d65a7e737256133615b0bf56092b57b87f (patch) | |
tree | 1ee7458192b2e61344fd7e3e2261be6790f5dcbc /tests/util | |
parent | 8eb1f11112c3ced0ff4a35f3487a4da507db05c2 (diff) |
fix(lsp): Pass diagnostic codes to TSC as numbers (#23720)
Fixes the `Debug Failure` errors described in
https://github.com/denoland/deno/issues/23643#issuecomment-2094552765 .
The issue here was that we were passing diagnostic codes as strings but
TSC expects the codes to be numbers. This resulted in some quick fixes
not working (as illustrated by the test added here which fails before
this PR).
The first commit is the actual fix. The rest are just test related.
Diffstat (limited to 'tests/util')
-rw-r--r-- | tests/util/server/src/assertions.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/util/server/src/assertions.rs b/tests/util/server/src/assertions.rs index f964e56e9..c8b8845f4 100644 --- a/tests/util/server/src/assertions.rs +++ b/tests/util/server/src/assertions.rs @@ -108,3 +108,44 @@ pub fn assert_wildcard_match_with_logger( } } } + +/// Asserts that the actual `serde_json::Value` is equal to the expected `serde_json::Value`, but +/// only for the keys present in the expected value. +/// +/// # Example +/// +/// ``` +/// # use serde_json::json; +/// # use test_server::assertions::assert_json_subset; +/// assert_json_subset(json!({"a": 1, "b": 2}), json!({"a": 1})); +/// +/// // Arrays are compared element by element +/// assert_json_subset(json!([{ "a": 1, "b": 2 }, {}]), json!([{"a": 1}, {}])); +/// ``` +#[track_caller] +pub fn assert_json_subset( + actual: serde_json::Value, + expected: serde_json::Value, +) { + match (actual, expected) { + ( + serde_json::Value::Object(actual), + serde_json::Value::Object(expected), + ) => { + for (k, v) in expected.iter() { + let Some(actual_v) = actual.get(k) else { + panic!("Key {k:?} not found in actual value ({actual:#?})"); + }; + assert_json_subset(actual_v.clone(), v.clone()); + } + } + (serde_json::Value::Array(actual), serde_json::Value::Array(expected)) => { + for (i, v) in expected.iter().enumerate() { + assert_json_subset(actual[i].clone(), v.clone()); + } + } + (actual, expected) => { + assert_eq!(actual, expected); + } + } +} |