forked from jetaggart/light-haskell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_server.rb
57 lines (45 loc) · 1.52 KB
/
test_server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'socket'
require 'json'
server = TCPServer.new 5555
def test_code
<<-CODE
{-# LANGUAGE OverloadedStrings, DeriveGeneric #-}
import Network (connectTo, withSocketsDo, PortID(..))
import Network.Socket (send, socketToHandle)
import System.Environment (getArgs)
import System.IO (hSetBuffering, stdout, hFlush, hPutStr, hGetLine, stderr, hPutStrLn, BufferMode(..), Handle, IOMode(..))
import System.Directory (getCurrentDirectory)
import Control.Concurrent (forkIO)
import Data.Aeson ((.:), (.=), (.:?), object, eitherDecode, encode, FromJSON(..), ToJSON(..), Value(..))
import Control.Exception (throw)
import Control.Applicative ((<$>), (<*>))
import Data.Map (fromList)
import Data.Text (Text)
import qualified Data.ByteString.Lazy.Char8 as BS
CODE
end
loop do
client = server.accept
info = client.gets
puts info
client.puts JSON.generate([456, "haskell.api.reformat", {"data" => test_code}])
info = client.gets
puts "Should succeed: reformatting"
puts info
client.puts JSON.generate([456, "haskell.api.syntax", {"data" => "haskell/LTHaskellClient.hs"}])
info = client.gets
puts "Should succeed: syntax"
puts info
client.puts JSON.generate([456, "haskell.api.eval", {"data" => "1 + 2"}])
info = client.gets
puts "Should succeed: eval"
puts info
client.puts JSON.generate([456, "haskell.api.eval", {"data" => "putStrLn"}])
info = client.gets
puts "Should fail: eval"
puts info
client.puts JSON.generate([456, "client.close", nil])
info = client.gets
puts "Client should quit"
puts info
end