Skip to content

Commit 545137c

Browse files
committed
add tests
1 parent bdd77fd commit 545137c

File tree

6 files changed

+124
-59
lines changed

6 files changed

+124
-59
lines changed

.codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
comment: false

.travis.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@ os:
44
- linux
55
- osx
66
julia:
7-
- 0.4
7+
- 0.6
88
- nightly
99
notifications:
1010
email: false
11+
git:
12+
depth: 99999999
1113
# uncomment the following lines to override the default test script
1214
#script:
1315
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
1416
# - julia -e 'Pkg.clone(pwd()); Pkg.build("Merly"); Pkg.test("Merly"; coverage=true)'
17+
after_success:
18+
# push coverage results to Coveralls
19+
- julia -e 'cd(Pkg.dir("Merly")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
20+
# push coverage results to Codecov
21+
- julia -e 'cd(Pkg.dir("Merly")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'

README.md

Lines changed: 72 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,42 @@
11
# Merly.jl
22

3-
*Micro framework for web programming in Julia.*
4-
5-
[![Build Status](https://travis-ci.org/codeneomatrix/Merly.jl.svg?branch=master)](https://travis-ci.org/codeneomatrix/Merly.jl)
6-
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/codeneomatrix/Merly.jl/master/LICENSE.md)
7-
[![Merly](http://pkg.julialang.org/badges/Merly_0.4.svg)](http://pkg.julialang.org/?pkg=Merly)
8-
[![Merly](http://pkg.julialang.org/badges/Merly_0.5.svg)](http://pkg.julialang.org/?pkg=Merly)
9-
[![Merly](http://pkg.julialang.org/badges/Merly_0.6.svg)](http://pkg.julialang.org/?pkg=Merly)
10-
3+
<p align="center">
4+
<strong>Micro framework for web programming in Julia..</strong>
5+
<br><br>
6+
<a href="https://travis-ci.org/codeneomatrix/Merly.jl"><img src="https://travis-ci.org/codeneomatrix/Merly.jl.svg?branch=master"></a>
7+
<a href="https://codecov.io/gh/codeneomatrix/Merly.jl">
8+
<img src="https://codecov.io/gh/codeneomatrix/Merly.jl/branch/master/graph/badge.svg" />
9+
</a>
10+
&nbsp;&nbsp
11+
<a href="https://pkg.julialang.org/detail/Merly"><img src="http://pkg.julialang.org/badges/Merly_0.6.svg"></a>
12+
<a href="https://pkg.julialang.org/detail/Merly"><img src="http://pkg.julialang.org/badges/Merly_0.7.svg"></a>
13+
&nbsp;&nbsp;
14+
<a href="https://raw.githubusercontent.com/codeneomatrix/Merly.jl/master/LICENSE.md"><img src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
15+
16+
## About
1117
Merly is a micro framework for declaring routes and handling requests.
1218
Quickly creating web applications in Julia with minimal effort.
1319

1420
Roadmap
1521
-----
16-
Below are some of the features that are planned to be added in future versions of Faker.jl once version 1.0 of the language is released.
22+
#### Version 0.0.3
23+
- [x] adding the debug option
24+
- [x] optimizing routes
25+
- [x] refactor notfount, cors, body
26+
27+
Below are some of the features that are planned to be added in future versions of Merly.jl once version 1.0 of the language is released.
1728

1829
### All contributions and suggestions are welcome !!!!
1930

2031
#### Version 0.1.0
21-
+ Julia version 1.0 syntax update
22-
23-
#### Version 0.1.1
24-
+ Implementation of verbose
32+
- [ ] Julia version 1.0 syntax update
2533

2634
#### Version 0.1.2
27-
+ Implementation of a websocket module
28-
35+
- [ ] Implementation of a websocket module
36+
2937
#### Version 0.1.3
30-
+ Performance improvement
31-
32-
#### Version 0.1.4
33-
+ Threads implementation
34-
38+
- [ ] Performance improvement
39+
3540

3641
Installing
3742
----------
@@ -45,43 +50,42 @@ Pkg.clone("git://github.com/codeneomatrix/Merly.jl.git") #Development
4550
```julia
4651
using Merly
4752

48-
global u
4953
u="hello"
5054

5155
server = Merly.app()
5256

5357
@page "/" "Hello World!"
54-
@page "/hola/:usr" "<b>Hello {{usr}}!</b>"
58+
@page "/hola/:usr>" "<b>Hello {{usr}}!</b>"
5559

56-
@route GET "/get/:data" begin
60+
@route GET "/get/:data>" begin
5761
"get this back: {{data}}"
5862
end
5963

6064
@route POST "/post" begin
61-
"I did something!"
65+
res.data = "I did something!"
6266
end
6367

6468
@route POST|PUT|DELETE "/" begin
6569
println("params: ",q.params)
6670
println("query: ",q.query)
6771
println("body: ",q.body)
6872

69-
r.headers["Content-Type"]="text/plain"
73+
res.headers["Content-Type"]="text/plain"
7074

7175
"I did something!"
7276
end
7377

74-
Get("/data", (q,r)->(begin
75-
r.headers["Content-Type"]="text/plain"
76-
"$u data"
78+
Get("/data", (q,req,res)->(begin
79+
res.headers["Content-Type"]="text/plain"
80+
u*"data"
7781
end))
7882

7983

80-
Post("/data", (q,r)->(begin
84+
Post("/data", (q,req,res)->(begin
8185
println("params: ",q.params)
8286
println("query: ",q.query)
8387
println("body: ",q.body)
84-
r.headers["Content-Type"]="text/plain"
88+
res.headers["Content-Type"]="text/plain"
8589
global u="bye"
8690
"I did something!"
8791
end))
@@ -95,28 +99,32 @@ Features available in the current release
9599
------------------
96100
### Parameters dictionary
97101
```julia
98-
@route GET "/get/:data" begin
102+
@route GET "/get/:data>" begin
103+
# matches "GET /get/foo" and "GET /get/bar"
104+
# q.params["data"] is 'foo' or 'bar'
99105
"get this back: "*q.params["data"]
100106
end
101107
```
102108
### url query dictionary
109+
103110
```julia
104111
@route POST|PUT|DELETE "/" begin
105-
r.headers["Content-Type"]="text/plain"
106-
107-
"I did something! "*q.query["value1name"]
112+
res.headers["Content-Type"]="text/plain"
113+
# matches "POST /?title=foo&author=bar"
114+
title = q.query["title"]
115+
author = q.query["author"]
116+
"I did something!"
108117
end
109118
```
110119
### Dictionary of body
111120
Payload
112121
```ruby
113-
{"data1":"Hello"}
122+
{"data1":"Hello"}
114123
```
115124
```julia
116125
@route POST|PUT|DELETE "/" begin
117-
r.headers["Content-Type"]="text/plain"
118-
119-
"Payload data "*q.body["data1"]
126+
res.headers["Content-Type"]="text/plain"
127+
res.data = "Payload data "*q.body["data1"]
120128
end
121129
```
122130

@@ -128,8 +136,7 @@ Payload
128136
```
129137
```julia
130138
@route POST|PUT|DELETE "/" begin
131-
r.headers["Content-Type"]="text/plain"
132-
139+
res.headers["Content-Type"]="text/plain"
133140
"Payload data "*q.body["Data"]["Data1"]
134141
end
135142
```
@@ -138,21 +145,21 @@ end
138145

139146
```julia
140147
@route POST|PUT|DELETE "/" begin
141-
r.headers["Content-Type"]="application/json"
142-
r.status = 200 #optional
148+
res.headers["Content-Type"]="application/json"
149+
res.status = 200 #optional
143150
"{\"data1\":2,\"data2\":\"t\"}"
144151
end
145152

146153
```
147154
or
148155
```julia
149156
@route POST|PUT|DELETE "/" begin
150-
r.headers["Content-Type"]="application/json"
157+
res.headers["Content-Type"]="application/json"
151158
info=Dict()
152159
info["data1"]=2
153160
info["data2"]="t"
154-
r.status = 200 #optional
155-
JSON.json(info)
161+
res.status = 200 #optional
162+
res.data = JSON.json(info)
156163
end
157164

158165
```
@@ -161,7 +168,7 @@ end
161168

162169
```julia
163170
@route POST|PUT|DELETE "/" begin
164-
r.headers["Content-Type"]="application/xml"
171+
res.headers["Content-Type"]="application/xml"
165172

166173
"<ListAllMyBucketsResult>
167174
<Buckets>
@@ -176,15 +183,26 @@ end
176183
### Reply File
177184

178185
```julia
179-
server = Merly.app("Path","load") #example: ("D:\\EXAMPLE\\src","*") defauld: (pwd(),"")
180-
@page "/" File("Index.html", r)
186+
@page "/" File("Index.html")
187+
```
181188

189+
### Web server
190+
191+
```julia
192+
# By default, the location where to look for the files that will
193+
# be exposed will be the same where the script is, if the files are
194+
# not found in that site, the location of the files can be established
195+
# with the following instruction.
196+
server.webserverpath("C:\\path") # example in windows
197+
198+
199+
server.webserverfiles("*") #
182200
```
183201
```clojure
184-
Possible values of load
185-
"*" Load all the files located in the path, except what started with "."
202+
Possible values of webserverfiles
203+
204+
"*" Load all the files located in the path, except what started with "."
186205
"jl","clj|jl|py" Extension in files that will not be exposed
187-
"" Any file, Default
188206
```
189207

190208
### Not found message
@@ -200,11 +218,11 @@ server.notfound("notfound.html")
200218
```
201219
### CORS
202220
```julia
203-
server.use("CORS")
221+
server.useCORS(true)
204222
```
205223

206224
### Bonus
207225
If you forgot the MIME type of a file you can use the next instruction
208226
```julia
209-
r.headers["Content-Type"]=mimetypes["file extension"]
210-
```
227+
res.headers["Content-Type"]=mimetypes["file extension"]
228+
```

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
julia 0.4
1+
julia 0.6
22
HttpServer
33
HttpCommon
44
JSON

appveyor.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
3+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
55
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
66
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
77

@@ -18,6 +18,11 @@ notifications:
1818

1919
install:
2020
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
21+
# If there's a newer build queued for the same PR, cancel this one
22+
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
23+
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
24+
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
25+
throw "There are newer queued builds for this pull request, failing early." }
2126
# Download most recent Julia Windows binary
2227
- ps: (new-object net.webclient).DownloadFile(
2328
$env:JULIA_URL,

test/runtests.jl

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,38 @@ using Merly
22
using Base.Test
33

44
# write your own tests here
5-
@test 1 == 1
5+
server = Merly.app()
6+
7+
@test server.useCORS(true) == true
8+
9+
@test server.notfound("<!DOCTYPE html>
10+
<html>
11+
<head><title>Not found</title></head>
12+
<body><h1>404, Not found</h1></body>
13+
</html>") == "<!DOCTYPE html>
14+
<html>
15+
<head><title>Not found</title></head>
16+
<body><h1>404, Not found</h1></body>
17+
</html>"
18+
19+
#=@test @page "/" "Hello World!" == "GET/"
20+
21+
@test @route GET "/get/:data>" begin
22+
println("params: ",q.params["data"])
23+
"get this back: {{data}}"
24+
end =="GET/get/:data>"
25+
26+
@test Post("/data/:nombre>", (q,req,res)->(begin
27+
println("body: ",q.body)
28+
res.headers["Content-Type"]="text/plain"
29+
30+
"I did something!"
31+
end)) =="GET/get/:nombre>"
32+
33+
34+
@test @route POST|PUT|DELETE "/" begin
35+
res.headers["Content-Type"]="text/plain"
36+
"I did something!"
37+
end == "POST/
38+
PUT/
39+
DELETE/"=#

0 commit comments

Comments
 (0)