refactor: DummyClient -> FakeClient

This commit is contained in:
Shunsuke Shibayama 2023-09-08 02:22:34 +09:00
parent dcb42f68b9
commit ac5b0548a3
4 changed files with 20 additions and 20 deletions

View file

@ -27,7 +27,7 @@ use erg_compiler::module::{SharedCompilerResource, SharedModuleGraph, SharedModu
use erg_compiler::ty::HasType; use erg_compiler::ty::HasType;
pub use molc::RedirectableStdout; pub use molc::RedirectableStdout;
use molc::{DummyClient, LangServer}; use molc::{FakeClient, LangServer};
use lsp_types::request::{ use lsp_types::request::{
CallHierarchyIncomingCalls, CallHierarchyOutgoingCalls, CallHierarchyPrepare, CallHierarchyIncomingCalls, CallHierarchyOutgoingCalls, CallHierarchyPrepare,
@ -298,9 +298,9 @@ impl LangServer for Server {
impl Server { impl Server {
#[allow(unused)] #[allow(unused)]
pub fn bind_dummy_client() -> DummyClient<Server> { pub fn bind_fake_client() -> FakeClient<Server> {
let (sender, receiver) = std::sync::mpsc::channel(); let (sender, receiver) = std::sync::mpsc::channel();
DummyClient::new(Server::new(ErgConfig::default(), Some(sender)), receiver) FakeClient::new(Server::new(ErgConfig::default(), Some(sender)), receiver)
} }
} }

View file

@ -13,7 +13,7 @@ use molc::{add_char, oneline_range};
#[test] #[test]
fn test_open() -> Result<(), Box<dyn std::error::Error>> { fn test_open() -> Result<(), Box<dyn std::error::Error>> {
let mut client = Server::bind_dummy_client(); let mut client = Server::bind_fake_client();
client.request_initialize()?; client.request_initialize()?;
client.notify_open(FILE_A)?; client.notify_open(FILE_A)?;
client.wait_messages(3)?; client.wait_messages(3)?;
@ -25,7 +25,7 @@ fn test_open() -> Result<(), Box<dyn std::error::Error>> {
#[test] #[test]
fn test_completion() -> Result<(), Box<dyn std::error::Error>> { fn test_completion() -> Result<(), Box<dyn std::error::Error>> {
let mut client = Server::bind_dummy_client(); let mut client = Server::bind_fake_client();
client.request_initialize()?; client.request_initialize()?;
let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?; let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?;
client.notify_open(FILE_A)?; client.notify_open(FILE_A)?;
@ -43,7 +43,7 @@ fn test_completion() -> Result<(), Box<dyn std::error::Error>> {
#[test] #[test]
fn test_neighbor_completion() -> Result<(), Box<dyn std::error::Error>> { fn test_neighbor_completion() -> Result<(), Box<dyn std::error::Error>> {
let mut client = Server::bind_dummy_client(); let mut client = Server::bind_fake_client();
client.request_initialize()?; client.request_initialize()?;
let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?; let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?;
client.notify_open(FILE_A)?; client.notify_open(FILE_A)?;
@ -62,7 +62,7 @@ fn test_neighbor_completion() -> Result<(), Box<dyn std::error::Error>> {
#[test] #[test]
fn test_rename() -> Result<(), Box<dyn std::error::Error>> { fn test_rename() -> Result<(), Box<dyn std::error::Error>> {
let mut client = Server::bind_dummy_client(); let mut client = Server::bind_fake_client();
client.request_initialize()?; client.request_initialize()?;
let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?; let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?;
client.notify_open(FILE_A)?; client.notify_open(FILE_A)?;
@ -77,7 +77,7 @@ fn test_rename() -> Result<(), Box<dyn std::error::Error>> {
#[test] #[test]
fn test_signature_help() -> Result<(), Box<dyn std::error::Error>> { fn test_signature_help() -> Result<(), Box<dyn std::error::Error>> {
let mut client = Server::bind_dummy_client(); let mut client = Server::bind_fake_client();
client.request_initialize()?; client.request_initialize()?;
let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?; let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?;
client.notify_open(FILE_A)?; client.notify_open(FILE_A)?;
@ -95,7 +95,7 @@ fn test_signature_help() -> Result<(), Box<dyn std::error::Error>> {
#[test] #[test]
fn test_hover() -> Result<(), Box<dyn std::error::Error>> { fn test_hover() -> Result<(), Box<dyn std::error::Error>> {
let mut client = Server::bind_dummy_client(); let mut client = Server::bind_fake_client();
client.request_initialize()?; client.request_initialize()?;
let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?; let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?;
client.notify_open(FILE_A)?; client.notify_open(FILE_A)?;
@ -120,7 +120,7 @@ fn test_hover() -> Result<(), Box<dyn std::error::Error>> {
#[test] #[test]
fn test_references() -> Result<(), Box<dyn std::error::Error>> { fn test_references() -> Result<(), Box<dyn std::error::Error>> {
let mut client = Server::bind_dummy_client(); let mut client = Server::bind_fake_client();
client.request_initialize()?; client.request_initialize()?;
let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?; let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?;
client.notify_open(FILE_A)?; client.notify_open(FILE_A)?;
@ -132,7 +132,7 @@ fn test_references() -> Result<(), Box<dyn std::error::Error>> {
#[test] #[test]
fn test_goto_definition() -> Result<(), Box<dyn std::error::Error>> { fn test_goto_definition() -> Result<(), Box<dyn std::error::Error>> {
let mut client = Server::bind_dummy_client(); let mut client = Server::bind_fake_client();
client.request_initialize()?; client.request_initialize()?;
let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?; let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?;
client.notify_open(FILE_A)?; client.notify_open(FILE_A)?;
@ -147,7 +147,7 @@ fn test_goto_definition() -> Result<(), Box<dyn std::error::Error>> {
#[test] #[test]
fn test_folding_range() -> Result<(), Box<dyn std::error::Error>> { fn test_folding_range() -> Result<(), Box<dyn std::error::Error>> {
let mut client = Server::bind_dummy_client(); let mut client = Server::bind_fake_client();
client.request_initialize()?; client.request_initialize()?;
let uri = NormalizedUrl::from_file_path(Path::new(FILE_IMPORTS).canonicalize()?)?; let uri = NormalizedUrl::from_file_path(Path::new(FILE_IMPORTS).canonicalize()?)?;
client.notify_open(FILE_IMPORTS)?; client.notify_open(FILE_IMPORTS)?;
@ -168,7 +168,7 @@ fn test_folding_range() -> Result<(), Box<dyn std::error::Error>> {
#[test] #[test]
fn test_document_symbol() -> Result<(), Box<dyn std::error::Error>> { fn test_document_symbol() -> Result<(), Box<dyn std::error::Error>> {
let mut client = Server::bind_dummy_client(); let mut client = Server::bind_fake_client();
client.request_initialize()?; client.request_initialize()?;
let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?; let uri = NormalizedUrl::from_file_path(Path::new(FILE_A).canonicalize()?)?;
client.notify_open(FILE_A)?; client.notify_open(FILE_A)?;

View file

@ -1,6 +1,6 @@
# `molc` # `molc`
`molc` is a mock language client for testing language servers. `molc` is a mock (fake) language client for testing language servers.
## Usage ## Usage
@ -9,7 +9,7 @@ You can see specific examples of molc use in [ELS](https://github.com/erg-lang/e
```rust ```rust
use lsp_types::{Url, Value}; use lsp_types::{Url, Value};
use molc::{DummyClient, LangServer, RedirectableStdout}; use molc::{FakeClient, LangServer, RedirectableStdout};
use molc::oneline_range; use molc::oneline_range;
pub struct Server { pub struct Server {
@ -30,7 +30,7 @@ impl RedirectableStdout for Server {
} }
impl Server { impl Server {
fn bind_dummy_client() -> DummyClient<Self> { fn bind_fake_client() -> FakeClient<Self> {
// The server should send responses to this channel at least during testing. // The server should send responses to this channel at least during testing.
let (sender, receiver) = std::sync::mpsc::channel(); let (sender, receiver) = std::sync::mpsc::channel();
DummyClient::new( DummyClient::new(
@ -57,7 +57,7 @@ impl Server {
#[test] #[test]
fn test_references() -> Result<(), Box<dyn std::error::Error>> { fn test_references() -> Result<(), Box<dyn std::error::Error>> {
let mut client = Server::bind_dummy_client(); let mut client = Server::bind_fake_client();
client.request_initialize()?; client.request_initialize()?;
let uri = Url::from_file_path(Path::new(FILE_A).canonicalize()?).unwrap(); let uri = Url::from_file_path(Path::new(FILE_A).canonicalize()?).unwrap();
client.notify_open(FILE_A)?; client.notify_open(FILE_A)?;

View file

@ -133,7 +133,7 @@ pub trait LangServer {
fn dispatch(&mut self, msg: impl Into<Value>) -> Result<()>; fn dispatch(&mut self, msg: impl Into<Value>) -> Result<()>;
} }
pub struct DummyClient<LS: LangServer> { pub struct FakeClient<LS: LangServer> {
server: LS, server: LS,
receiver: std::sync::mpsc::Receiver<Value>, receiver: std::sync::mpsc::Receiver<Value>,
server_capas: Option<ServerCapabilities>, server_capas: Option<ServerCapabilities>,
@ -144,10 +144,10 @@ pub struct DummyClient<LS: LangServer> {
req_id: i64, req_id: i64,
} }
impl<LS: LangServer> DummyClient<LS> { impl<LS: LangServer> FakeClient<LS> {
/// The server should send responses to the channel at least during testing. /// The server should send responses to the channel at least during testing.
pub fn new(server: LS, receiver: std::sync::mpsc::Receiver<Value>) -> Self { pub fn new(server: LS, receiver: std::sync::mpsc::Receiver<Value>) -> Self {
DummyClient { FakeClient {
receiver, receiver,
responses: Vec::new(), responses: Vec::new(),
ver: 0, ver: 0,