123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- //! Tests for Unicode support and correct cursor transformation.
- pub mod common;
- use anyhow::Result;
- use common::*;
- use log::info;
- use operational_transform::OperationSeq;
- use rustpad_server::{server, ServerConfig};
- use serde_json::json;
- #[tokio::test]
- async fn test_unicode_length() -> Result<()> {
- pretty_env_logger::try_init().ok();
- let filter = server(ServerConfig::default());
- expect_text(&filter, "unicode", "").await;
- let mut client = connect(&filter, "unicode").await?;
- let msg = client.recv().await?;
- assert_eq!(msg, json!({ "Identity": 0 }));
- let mut operation = OperationSeq::default();
- operation.insert("h🎉e🎉l👨👨👦👦lo");
- let msg = json!({
- "Edit": {
- "revision": 0,
- "operation": operation
- }
- });
- info!("sending ClientMsg {}", msg);
- client.send(&msg).await;
- let msg = client.recv().await?;
- assert_eq!(
- msg,
- json!({
- "History": {
- "start": 0,
- "operations": [
- { "id": 0, "operation": ["h🎉e🎉l👨👨👦👦lo"] }
- ]
- }
- })
- );
- info!("testing that text length is equal to number of Unicode code points...");
- let mut operation = OperationSeq::default();
- operation.delete(14);
- let msg = json!({
- "Edit": {
- "revision": 1,
- "operation": operation
- }
- });
- info!("sending ClientMsg {}", msg);
- client.send(&msg).await;
- let msg = client.recv().await?;
- assert_eq!(
- msg,
- json!({
- "History": {
- "start": 1,
- "operations": [
- { "id": 0, "operation": [-14] }
- ]
- }
- })
- );
- expect_text(&filter, "unicode", "").await;
- Ok(())
- }
- #[tokio::test]
- async fn test_multiple_operations() -> Result<()> {
- pretty_env_logger::try_init().ok();
- let filter = server(ServerConfig::default());
- expect_text(&filter, "unicode", "").await;
- let mut client = connect(&filter, "unicode").await?;
- let msg = client.recv().await?;
- assert_eq!(msg, json!({ "Identity": 0 }));
- let mut operation = OperationSeq::default();
- operation.insert("🎉😍𒀇👨👨👦👦"); // Emoticons and Cuneiform
- let msg = json!({
- "Edit": {
- "revision": 0,
- "operation": operation
- }
- });
- info!("sending ClientMsg {}", msg);
- client.send(&msg).await;
- let msg = client.recv().await?;
- assert_eq!(
- msg,
- json!({
- "History": {
- "start": 0,
- "operations": [
- { "id": 0, "operation": ["🎉😍𒀇👨👨👦👦"] }
- ]
- }
- })
- );
- let mut operation = OperationSeq::default();
- operation.insert("👯♂️");
- operation.retain(3);
- operation.insert("𐅣𐅤𐅥"); // Ancient Greek numbers
- operation.retain(7);
- let msg = json!({
- "Edit": {
- "revision": 1,
- "operation": operation
- }
- });
- info!("sending ClientMsg {}", msg);
- client.send(&msg).await;
- let msg = client.recv().await?;
- assert_eq!(
- msg,
- json!({
- "History": {
- "start": 1,
- "operations": [
- { "id": 0, "operation": ["👯♂️", 3, "𐅣𐅤𐅥", 7] }
- ]
- }
- })
- );
- expect_text(&filter, "unicode", "👯♂️🎉😍𒀇𐅣𐅤𐅥👨👨👦👦").await;
- let mut operation = OperationSeq::default();
- operation.retain(2);
- operation.insert("h̷̙̤̏͊̑̍̆̃̉͝ĕ̶̠̌̓̃̓̽̃̚l̸̥̊̓̓͝͠l̸̨̠̣̟̥͠ỏ̴̳̖̪̟̱̰̥̞̙̏̓́͗̽̀̈́͛͐̚̕͝͝ ̶̡͍͙͚̞͙̣̘͙̯͇̙̠̀w̷̨̨̪͚̤͙͖̝͕̜̭̯̝̋̋̿̿̀̾͛̐̏͘͘̕͝ǒ̴̙͉͈̗̖͍̘̥̤̒̈́̒͠r̶̨̡̢̦͔̙̮̦͖͔̩͈̗̖̂̀l̶̡̢͚̬̤͕̜̀͛̌̈́̈́͑͋̈̍̇͊͝͠ď̵̛̛̯͕̭̩͖̝̙͎̊̏̈́̎͊̐̏͊̕͜͝͠͝"); // Lots of ligatures
- operation.retain(8);
- let msg = json!({
- "Edit": {
- "revision": 1,
- "operation": operation
- }
- });
- info!("sending ClientMsg {}", msg);
- client.send(&msg).await;
- let msg = client.recv().await?;
- assert_eq!(
- msg,
- json!({
- "History": {
- "start": 2,
- "operations": [
- { "id": 0, "operation": [6, "h̷̙̤̏͊̑̍̆̃̉͝ĕ̶̠̌̓̃̓̽̃̚l̸̥̊̓̓͝͠l̸̨̠̣̟̥͠ỏ̴̳̖̪̟̱̰̥̞̙̏̓́͗̽̀̈́͛͐̚̕͝͝ ̶̡͍͙͚̞͙̣̘͙̯͇̙̠̀w̷̨̨̪͚̤͙͖̝͕̜̭̯̝̋̋̿̿̀̾͛̐̏͘͘̕͝ǒ̴̙͉͈̗̖͍̘̥̤̒̈́̒͠r̶̨̡̢̦͔̙̮̦͖͔̩͈̗̖̂̀l̶̡̢͚̬̤͕̜̀͛̌̈́̈́͑͋̈̍̇͊͝͠ď̵̛̛̯͕̭̩͖̝̙͎̊̏̈́̎͊̐̏͊̕͜͝͠͝", 11] }
- ]
- }
- })
- );
- expect_text(&filter, "unicode", "👯♂️🎉😍h̷̙̤̏͊̑̍̆̃̉͝ĕ̶̠̌̓̃̓̽̃̚l̸̥̊̓̓͝͠l̸̨̠̣̟̥͠ỏ̴̳̖̪̟̱̰̥̞̙̏̓́͗̽̀̈́͛͐̚̕͝͝ ̶̡͍͙͚̞͙̣̘͙̯͇̙̠̀w̷̨̨̪͚̤͙͖̝͕̜̭̯̝̋̋̿̿̀̾͛̐̏͘͘̕͝ǒ̴̙͉͈̗̖͍̘̥̤̒̈́̒͠r̶̨̡̢̦͔̙̮̦͖͔̩͈̗̖̂̀l̶̡̢͚̬̤͕̜̀͛̌̈́̈́͑͋̈̍̇͊͝͠ď̵̛̛̯͕̭̩͖̝̙͎̊̏̈́̎͊̐̏͊̕͜͝͠͝𒀇𐅣𐅤𐅥👨👨👦👦").await;
- Ok(())
- }
- #[tokio::test]
- async fn test_unicode_cursors() -> Result<()> {
- pretty_env_logger::try_init().ok();
- let filter = server(ServerConfig::default());
- let mut client = connect(&filter, "unicode").await?;
- assert_eq!(client.recv().await?, json!({ "Identity": 0 }));
- let mut operation = OperationSeq::default();
- operation.insert("🎉🎉🎉");
- let msg = json!({
- "Edit": {
- "revision": 0,
- "operation": operation
- }
- });
- info!("sending ClientMsg {}", msg);
- client.send(&msg).await;
- client.recv().await?;
- let cursors = json!({
- "cursors": [0, 1, 2, 3],
- "selections": [[0, 1], [2, 3]]
- });
- client.send(&json!({ "CursorData": cursors })).await;
- let cursors_resp = json!({
- "UserCursor": {
- "id": 0,
- "data": cursors
- }
- });
- assert_eq!(client.recv().await?, cursors_resp);
- let mut client2 = connect(&filter, "unicode").await?;
- assert_eq!(client2.recv().await?, json!({ "Identity": 1 }));
- client2.recv().await?;
- assert_eq!(client2.recv().await?, cursors_resp);
- let msg = json!({
- "Edit": {
- "revision": 0,
- "operation": ["🎉"]
- }
- });
- client2.send(&msg).await;
- let mut client3 = connect(&filter, "unicode").await?;
- assert_eq!(client3.recv().await?, json!({ "Identity": 2 }));
- client3.recv().await?;
- let transformed_cursors_resp = json!({
- "UserCursor": {
- "id": 0,
- "data": {
- "cursors": [1, 2, 3, 4],
- "selections": [[1, 2], [3, 4]]
- }
- }
- });
- assert_eq!(client3.recv().await?, transformed_cursors_resp);
- Ok(())
- }
|