Skip to content

Commit

Permalink
order tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Mar 18, 2024
1 parent c6ec4b1 commit a823b78
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
20 changes: 15 additions & 5 deletions lib/speedy-uuid/tests/async_graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,32 @@ fn cursor_encode_decode() {
let parsed_cursor: Uuid = CursorType::decode_cursor(UUID).unwrap();
assert_eq!(parsed_cursor.as_bytes(), &UUID_BYTES);

let result: Result<Uuid, speedy_uuid::Error> = CursorType::decode_cursor("NOT A UUID");
assert!(result.is_err());

let encoded_cursor = CursorType::encode_cursor(&parsed_cursor);
assert_eq!(encoded_cursor, UUID);
}

#[test]
fn cursor_invalid_input() {
let result: Result<Uuid, speedy_uuid::Error> = CursorType::decode_cursor("NOT A UUID");
assert!(result.is_err());
}

#[test]
fn scalar_encode_decode() {
let parsed_scalar: Uuid = ScalarType::parse(async_graphql::Value::String(UUID.into())).unwrap();
assert_eq!(parsed_scalar.as_bytes(), &UUID_BYTES);

let encoded_scalar = ScalarType::to_value(&parsed_scalar);
assert_eq!(encoded_scalar, async_graphql::Value::String(UUID.into()));
}

#[test]
fn scalar_invalid_input() {
let result: async_graphql::InputValueResult<Uuid> =
ScalarType::parse(async_graphql::Value::Null);
assert!(result.is_err());

let encoded_scalar = ScalarType::to_value(&parsed_scalar);
assert_eq!(encoded_scalar, async_graphql::Value::String(UUID.into()));
let result: async_graphql::InputValueResult<Uuid> =
ScalarType::parse(async_graphql::Value::String("NOT A UUID".into()));
assert!(result.is_err());
}
12 changes: 6 additions & 6 deletions lib/speedy-uuid/tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ const UUID_BYTES: [u8; 16] = [
0x38, 0x05, 0x8d, 0xaf, 0xb2, 0xcd, 0x48, 0x32, 0x90, 0x2a, 0x83, 0x58, 0x3a, 0xc0, 0x7e, 0x28,
];

#[test]
fn deserialize_str() {
let uuid = Uuid::from_str(UUID).unwrap().readable();
serde_test::assert_de_tokens(&uuid, &[Token::Str(UUID)]);
}

#[test]
fn deserialize_bytes() {
let uuid = Uuid::from_slice(&UUID_BYTES).unwrap();
Expand Down Expand Up @@ -55,6 +49,12 @@ fn deserialize_byte_array() {
);
}

#[test]
fn deserialize_str() {
let uuid = Uuid::from_str(UUID).unwrap().readable();
serde_test::assert_de_tokens(&uuid, &[Token::Str(UUID)]);
}

#[test]
fn serialize_uuid() {
let uuid = Uuid::from_slice(&UUID_BYTES).unwrap();
Expand Down

0 comments on commit a823b78

Please sign in to comment.