This repository has been archived by the owner on Feb 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
145 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Feature: jsonrpc module | ||
jsonrpc is a module of language-server. | ||
|
||
Scenario: Test ReadWriter | ||
Given the string | ||
When I write it to ReadWriter | ||
Then it should read from ReadWriter | ||
|
||
Scenario: Test ReadWriter | ||
Given the string | ||
When I write it to ReadWriter | ||
Then it should readline from ReadWriter | ||
|
||
Scenario: Test TCPReadWriter | ||
Given the string | ||
When I write it to TCPReadWriter | ||
Then it should read from TCPReadWriter | ||
|
||
Scenario: Test TCPReadWriter | ||
Given the string | ||
When I write it to TCPReadWriter | ||
Then it should readline from TCPReadWriter | ||
|
||
Scenario: Test send_notification and read_message | ||
Given the JSONRPC2Connection instance | ||
When I write a notification to the JSONRPC2Connection | ||
Then it should return the notification from JSONRPC2Connection | ||
|
||
Scenario: Test write_response | ||
Given the JSONRPC2Connection instance | ||
When I write a response to the JSONRPC2Connection | ||
Then it should return the response from JSONRPC2Connection | ||
|
||
# TODO: block until we have generantee the unique request. | ||
# Scenario: Test send_request | ||
# Given the JSONRPC2Connection instance | ||
# When I write a request to the JSONRPC2Connection with id | ||
# Then it should return the request from JSONRPC2Connection with id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# -*- coding: UTF-8 -*- | ||
|
||
# @mark.steps | ||
# ---------------------------------------------------------------------------- | ||
# STEPS: | ||
# ---------------------------------------------------------------------------- | ||
import tempfile | ||
import json | ||
from behave import given, when, then | ||
from coala_langserver.jsonrpc import ReadWriter, TCPReadWriter, JSONRPC2Connection | ||
|
||
|
||
@given('the string') | ||
def step_impl(context): | ||
context.str = 'test-cases' | ||
|
||
|
||
@when('I write it to ReadWriter') | ||
def step_impl(context): | ||
context.f = tempfile.TemporaryFile(mode='w+') | ||
context.readWriter = ReadWriter(context.f, context.f) | ||
context.readWriter.write(context.str) | ||
|
||
|
||
@then('it should read from ReadWriter') | ||
def step_impl(context): | ||
context.f.seek(0) | ||
assert context.readWriter.read(len(context.str)) is not '' | ||
context.f.close() | ||
|
||
|
||
@then('it should readline from ReadWriter') | ||
def step_impl(context): | ||
context.f.seek(0) | ||
assert context.readWriter.readline() is not '' | ||
context.f.close() | ||
|
||
|
||
@when('I write it to TCPReadWriter') | ||
def step_impl(context): | ||
context.f = tempfile.TemporaryFile() | ||
context.readWriter = TCPReadWriter(context.f, context.f) | ||
context.readWriter.write(context.str) | ||
|
||
|
||
@then('it should read from TCPReadWriter') | ||
def step_impl(context): | ||
context.f.seek(0) | ||
assert context.readWriter.read(len(context.str)) is not '' | ||
context.f.close() | ||
|
||
|
||
@then('it should readline from TCPReadWriter') | ||
def step_impl(context): | ||
context.f.seek(0) | ||
assert context.readWriter.readline() is not '' | ||
context.f.close() | ||
|
||
|
||
@given('the JSONRPC2Connection instance') | ||
def step_impl(context): | ||
context.f = tempfile.TemporaryFile() | ||
context.jsonConn = JSONRPC2Connection(conn=TCPReadWriter(context.f, context.f)) | ||
|
||
|
||
@when('I write a request to the JSONRPC2Connection with id') | ||
def step_impl(context): | ||
context.jsonConn.send_request('mockMethod', { | ||
'mock': 'mock' | ||
}) | ||
|
||
|
||
@then('it should return the request from JSONRPC2Connection with id') | ||
def step_impl(context): | ||
context.f.seek(0) | ||
assert context.jsonConn.read_message() is not None | ||
context.f.close() | ||
|
||
|
||
@when('I write a notification to the JSONRPC2Connection') | ||
def step_impl(context): | ||
context.jsonConn.send_notification('mockMethod', { | ||
'mock': 'mock' | ||
}) | ||
|
||
|
||
@then('it should return the notification from JSONRPC2Connection') | ||
def step_impl(context): | ||
context.f.seek(0) | ||
assert context.jsonConn.read_message() is not None | ||
context.f.close() | ||
|
||
|
||
@when('I write a response to the JSONRPC2Connection') | ||
def step_impl(context): | ||
context.ID = 1 | ||
context.jsonConn.write_response(context.ID, { | ||
'mock': 'mock' | ||
}) | ||
|
||
|
||
@then('it should return the response from JSONRPC2Connection') | ||
def step_impl(context): | ||
context.f.seek(0) | ||
assert context.jsonConn.read_message(context.ID) is not None | ||
context.f.close() |