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
3 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
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,42 @@ | ||
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 read_message without id | ||
Given the JSONRPC2Connection instance | ||
When I write a message to the JSONRPC2Connection without id | ||
Then it should return it from JSONRPC2Connection | ||
|
||
Scenario: Test read_message with id | ||
Given the JSONRPC2Connection instance | ||
When I write a message to the JSONRPC2Connection with id | ||
Then it should return it from JSONRPC2Connection with id | ||
|
||
Scenario: Test write_response with id | ||
Given the JSONRPC2Connection instance | ||
When I write a message to the JSONRPC2Connection with id | ||
Then it should get it | ||
|
||
Scenario: Test send_notification | ||
Given the JSONRPC2Connection instance | ||
When I write a notification to the JSONRPC2Connection | ||
Then it should get it |
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,85 @@ | ||
# -*- 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): | ||
assert context.readWriter.read(len(context.str)) is not '' | ||
context.f.close() | ||
|
||
|
||
@then('it should readline from ReadWriter') | ||
def step_impl(context): | ||
assert context.readWriter.readline() is not '' | ||
|
||
|
||
@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): | ||
assert context.readWriter.read(len(context.str)) is not '' | ||
context.f.close() | ||
|
||
|
||
@then('it should readline from TCPReadWriter') | ||
def step_impl(context): | ||
assert context.readWriter.readline() is not '' | ||
|
||
|
||
@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 message to the JSONRPC2Connection without id') | ||
def step_impl(context): | ||
context.id = 10 | ||
mockMethod = 'method' | ||
mockParams = { | ||
'mock': 'mock' | ||
} | ||
body = { | ||
'jsonrpc': '2.0', | ||
'id': context.id, | ||
'method': mockMethod, | ||
'params': mockParams, | ||
} | ||
body = json.dumps(body, separators=(',', ':')) | ||
content_length = len(body) | ||
request = ( | ||
'Content-Length: {}\r\n' | ||
'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n\r\n' | ||
'{}'.format(content_length, body)) | ||
context.jsonConn.conn.write(request) | ||
|
||
|
||
@then('it should return it from JSONRPC2Connection') | ||
def step_impl(context): | ||
assert context.jsonConn.read_message(context.id) is not None | ||
context.f.close() |