summaryrefslogtreecommitdiff
path: root/serde_v8/tests/de.rs
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-03-31 16:37:38 +0200
committerGitHub <noreply@github.com>2021-03-31 10:37:38 -0400
commitfec1b2a5a4324a7eecdfbb2471931f3b6b0139c5 (patch)
tree8a650553c2d70e047d9d7365f9ac8702ec9861a5 /serde_v8/tests/de.rs
parent6dc3549a818ad49b3907d18c93fd422a9cc743a5 (diff)
refactor: new optimized op-layer using serde_v8 (#9843)
- Improves op performance. - Handle op-metadata (errors, promise IDs) explicitly in the op-layer vs per op-encoding (aka: out-of-payload). - Remove shared queue & custom "asyncHandlers", all async values are returned in batches via js_recv_cb. - The op-layer should be thought of as simple function calls with little indirection or translation besides the conceptually straightforward serde_v8 bijections. - Preserve concepts of json/bin/min as semantic groups of their inputs/outputs instead of their op-encoding strategy, preserving these groups will also facilitate partial transitions over to v8 Fast API for the "min" and "bin" groups
Diffstat (limited to 'serde_v8/tests/de.rs')
-rw-r--r--serde_v8/tests/de.rs57
1 files changed, 55 insertions, 2 deletions
diff --git a/serde_v8/tests/de.rs b/serde_v8/tests/de.rs
index 2df93ae7a..785de6374 100644
--- a/serde_v8/tests/de.rs
+++ b/serde_v8/tests/de.rs
@@ -12,6 +12,22 @@ struct MathOp {
pub operator: Option<String>,
}
+#[derive(Debug, PartialEq, Deserialize)]
+enum EnumUnit {
+ A,
+ B,
+ C,
+}
+
+#[derive(Debug, PartialEq, Deserialize)]
+enum EnumPayloads {
+ UInt(u64),
+ Int(i64),
+ Float(f64),
+ Point { x: i64, y: i64 },
+ Tuple(bool, i64, ()),
+}
+
fn dedo(
code: &str,
f: impl FnOnce(&mut v8::HandleScope, v8::Local<v8::Value>),
@@ -73,6 +89,43 @@ detest!(
}
);
+// Unit enums
+detest!(de_enum_unit_a, EnumUnit, "'A'", EnumUnit::A);
+detest!(de_enum_unit_b, EnumUnit, "'B'", EnumUnit::B);
+detest!(de_enum_unit_c, EnumUnit, "'C'", EnumUnit::C);
+
+// Enums with payloads (tuples & struct)
+detest!(
+ de_enum_payload_int,
+ EnumPayloads,
+ "({ Int: -123 })",
+ EnumPayloads::Int(-123)
+);
+detest!(
+ de_enum_payload_uint,
+ EnumPayloads,
+ "({ UInt: 123 })",
+ EnumPayloads::UInt(123)
+);
+detest!(
+ de_enum_payload_float,
+ EnumPayloads,
+ "({ Float: 1.23 })",
+ EnumPayloads::Float(1.23)
+);
+detest!(
+ de_enum_payload_point,
+ EnumPayloads,
+ "({ Point: { x: 1, y: 2 } })",
+ EnumPayloads::Point { x: 1, y: 2 }
+);
+detest!(
+ de_enum_payload_tuple,
+ EnumPayloads,
+ "({ Tuple: [true, 123, null ] })",
+ EnumPayloads::Tuple(true, 123, ())
+);
+
#[test]
fn de_f64() {
dedo("12345.0", |scope, v| {
@@ -114,7 +167,7 @@ detest!(
de_json_int,
serde_json::Value,
"123",
- serde_json::Value::Number(serde_json::Number::from_f64(123.0).unwrap())
+ serde_json::Value::Number(serde_json::Number::from(123))
);
detest!(
de_json_float,
@@ -156,7 +209,7 @@ detest!(
vec![
(
"a".to_string(),
- serde_json::Value::Number(serde_json::Number::from_f64(1.0).unwrap()),
+ serde_json::Value::Number(serde_json::Number::from(1)),
),
(
"b".to_string(),