Skip to content

Commit eee6751

Browse files
author
SGrondin
committed
Enjoy your tests
1 parent f6cb18e commit eee6751

2 files changed

Lines changed: 60 additions & 2 deletions

File tree

‎src/targets/ocaml/cohttp.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ module.exports = function (options) {
6060
code.push('>>= fun (res, body_stream) ->');
6161
code.push(opts.indent + '(* Do stuff with the result *)');
6262

63-
return code.join(opts.indent !== false ? ' \n' + opts.indent : ' ');
63+
return code.join('\n');
6464
};
6565

6666
module.exports.info = function () {
6767
return {
68-
key: 'ocaml',
68+
family: 'ocaml',
69+
key: 'cohttp',
6970
title: 'OCaml',
7071
link: 'https://github.com/mirage/ocaml-cohttp',
7172
description: 'Cohttp is a very lightweight HTTP server using Lwt or Async for OCaml',

‎test/targets/ocaml/cohttp.js‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
var fixtures = require('../../fixtures');
4+
var HTTPSnippet = require('../../../src');
5+
var should = require('should');
6+
7+
describe('OCaml', function () {
8+
it('should convert full request to an OCaml snippet', function (done) {
9+
var result = new HTTPSnippet(fixtures.full).convert('ocaml', 'cohttp', {
10+
indent: '\t'
11+
});
12+
13+
result.replace(/\n/g, '').should.eql('open Cohttp_lwt_unixopen Lwtlet uri = Uri.of_string "http://httpconsole.com/debug?baz=abc&foo=bar&foo=baz" inlet headers = Header.init ()\t|> fun h -> Header.add h "Accept" "text/plain"\t|> fun h -> Header.add h "Content-Type" "application/json"\t|> fun h -> Header.add h "X-Pretty-Print" "2"\t|> fun h -> Header.add h "Cookie" "foo=bar; bar=baz"inlet body = "{\\"foo\\": \\"bar\\"}" inClient.call ~headers ~body (Code.method_of_string "POST") uri>>= fun (res, body_stream) ->\t(* Do stuff with the result *)');
14+
15+
done();
16+
});
17+
18+
it('should convert query request to an OCaml snippet', function (done) {
19+
var result = new HTTPSnippet(fixtures.query).convert('ocaml', 'cohttp', {
20+
indent: '\t'
21+
});
22+
23+
result.replace(/\n/g, '').should.eql('open Cohttp_lwt_unixopen Lwtlet uri = Uri.of_string "http://httpconsole.com/debug?key=value&baz=abc&foo=bar&foo=baz" inClient.call (Code.method_of_string "POST") uri>>= fun (res, body_stream) ->\t(* Do stuff with the result *)');
24+
25+
done();
26+
});
27+
28+
it('should convert simple request to an OCaml snippet', function (done) {
29+
var result = new HTTPSnippet(fixtures.simple).convert('ocaml', 'cohttp', {
30+
indent: '\t'
31+
});
32+
33+
result.replace(/\n/g, '').should.eql('open Cohttp_lwt_unixopen Lwtlet uri = Uri.of_string "http://httpconsole.com/debug?foo=bar" inlet headers = Header.init ()\t|> fun h -> Header.add h "Content-Type" "application/json"\t|> fun h -> Header.add h "Cookie" "bar=baz"inlet body = "{\\"foo\\": \\"bar\\"}" inClient.call ~headers ~body (Code.method_of_string "POST") uri>>= fun (res, body_stream) ->\t(* Do stuff with the result *)');
34+
35+
done();
36+
});
37+
38+
it('should convert short request to an OCaml snippet', function (done) {
39+
var result = new HTTPSnippet(fixtures.short).convert('ocaml', 'cohttp', {
40+
indent: '\t'
41+
});
42+
43+
result.replace(/\n/g, '').should.eql('open Cohttp_lwt_unixopen Lwtlet uri = Uri.of_string "http://httpconsole.com/echo" inClient.call (Code.method_of_string "GET") uri>>= fun (res, body_stream) ->\t(* Do stuff with the result *)');
44+
45+
done();
46+
});
47+
48+
it('should convert http1 request to an OCaml snippet', function (done) {
49+
var result = new HTTPSnippet(fixtures.http1).convert('ocaml', 'cohttp', {
50+
indent: '\t'
51+
});
52+
53+
result.replace(/\n/g, '').should.eql('open Cohttp_lwt_unixopen Lwtlet uri = Uri.of_string "http://httpconsole.com/debug" inClient.call (Code.method_of_string "GET") uri>>= fun (res, body_stream) ->\t(* Do stuff with the result *)');
54+
55+
done();
56+
});
57+
});

0 commit comments

Comments
 (0)